Skip to content

Commit

Permalink
Merge pull request #33 from AFM-SPM/SylviaWhittle/file-type-spm
Browse files Browse the repository at this point in the history
Add file type: SPM
  • Loading branch information
SylviaWhittle authored May 1, 2024
2 parents 7a98e3d + f589f6b commit 6502c56
Show file tree
Hide file tree
Showing 7 changed files with 140,900 additions and 12 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ for use with [TopoStats](https://github.com/AFM-SPM/TopoStats).

Supported file formats

| File format | Description |
|-------------|----------------|
| `.asd` | High-speed AFM |
| File format | Description |
|-------------|------------------|
| `.asd` | High-speed AFM |
| `.spm` | [Bruker's Format](https://www.bruker.com/) |
| `.jpk` | [Bruker](https://www.bruker.com/) |

Support for the following additional formats is planned. Some of these are already supported in TopoStats and are
awaiting refactoring to move their functionality into topofileformats these are denoted in bold below.

| File format | Description | Status |
|-------------|---------------------------------------------------------|--------------------------------------------|
| `.spm` | [Bruker](https://www.bruker.com/) | TopoStats supported, to be migrated (#16). |
| `.ibw` | [WaveMetrics](https://www.wavemetrics.com/) | TopoStats supported, to be migrated (#17). |
| `.gwy` | [Gwyddion](http://gwyddion.net/) | TopoStats supported, to be migrated (#1). |
| `.nhf` | [Nanosurf](https://www.nanosurf.com/en/) | To Be Implemented. |
Expand All @@ -41,6 +41,18 @@ awaiting refactoring to move their functionality into topofileformats these are
If you wish to process AFM images supported by `topofileformats` it is recommend you use
[TopoStats](https://github.com/AFM-SPM/TopoStats) to do so, however the library can be used on its own.

### .spm

You can open `.spm` files using the `load_spm` function. Just pass in the path to the file and the
channel name that you want to use. (If in doubt use one of the following: "Height", "ZSensor",
"Height Sensor").

```python
from topofileformats.spm import load_spm

image, pixel_to_nanometre_scaling_factor = load_spm(file_path="./my_spm_file.spm", channel="Height")
```

### .asd

You can open `.asd` files using the `load_asd` function. Just pass in the path to the file and the channel name that you
Expand All @@ -52,9 +64,9 @@ will want to use unless you know you specifically want something else.
Other channels: `"ER"` - Error, `"PH"` - Phase

```python
from topofileformats import load_asd
from topofileformats.asd import load_asd

frames, pixel_to_nanometre_scaling_factor, metadata = load_asd(file_path="./my_asd_file.asd")
frames, pixel_to_nanometre_scaling_factor, metadata = load_asd(file_path="./my_asd_file.asd", channel="TP")
```

### .jpk
Expand Down
77 changes: 74 additions & 3 deletions examples/example_01.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SPM Files"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -8,6 +15,52 @@
"source": [
"from pathlib import Path\n",
"\n",
"# Import the load_spm from topofileformats\n",
"from topofileformats.spm import load_spm\n",
"from topofileformats.logging import logger\n",
"\n",
"logger.enable(__package__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load the SPM file as an image and pixel to nm scaling factor\n",
"FILE = \"../tests/resources/sample_0.spm\"\n",
"image, pixel_to_nm_scaling = load_spm(FILE, channel=\"Height\")\n",
"logger.info(f\"Loaded a {image.shape} image with a pixel to nm scaling factor of {pixel_to_nm_scaling} nm/pixel.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot the image\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.imshow(image, cmap=\"afmhot\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ASD Files"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import the load_asd from topofileformats\n",
"from topofileformats.asd import load_asd, create_animation"
]
},
Expand All @@ -17,8 +70,25 @@
"metadata": {},
"outputs": [],
"source": [
"FILE = Path(\"../tests/resources/sample_0.asd\")\n",
"frames, pixel_to_nm_scaling, metadata = load_asd(file_path=FILE, channel=\"TP\")"
"# Load the ASD file as a list of frames, the pixel to nm scaling factor and the metadata\n",
"FILE = \"../tests/resources/sample_0.asd\"\n",
"frames, pixel_to_nm_scaling, metadata = load_asd(file_path=FILE, channel=\"TP\")\n",
"logger.info(f\"Loaded {len(frames)} frames from {FILE}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot a frame\n",
"import matplotlib.pyplot as plt\n",
"\n",
"frame_number = 55\n",
"plt.imshow(frames[frame_number], cmap=\"afmhot\")\n",
"plt.title(f\"Frame {frame_number}\")\n",
"plt.show()"
]
},
{
Expand All @@ -27,7 +97,8 @@
"metadata": {},
"outputs": [],
"source": [
"create_animation(file_name=\"sample_0\", frames=frames)"
"# Create a gif of the frames using the create_animation function. This is slow for large files.\n",
"create_animation(file_name=\"sample_0\", frames=frames, file_format=\".gif\")"
]
},
{
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

keywords = [
Expand All @@ -31,6 +32,8 @@ keywords = [
dependencies = [
"matplotlib",
"tifffile",
"pySPM",
"pySPM",
"loguru",
]

Expand Down
Loading

0 comments on commit 6502c56

Please sign in to comment.