Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file type: SPM #33

Merged
merged 42 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b37ee8e
Configuring test coverage
ns-rse Apr 24, 2024
370b663
Add loading of spm files
SylviaWhittle Apr 22, 2024
56eb3c2
Tests for load_spm
SylviaWhittle Apr 22, 2024
9cb649f
Documentation for loading spm
SylviaWhittle Apr 22, 2024
8449c2c
Spm test file
SylviaWhittle Apr 22, 2024
05cd52e
Example loading spm
SylviaWhittle Apr 22, 2024
be2e5c5
Fix tiny bug in asd loading - ensure strings are converted to paths
SylviaWhittle Apr 22, 2024
7d21983
Fix python 3.9 not supporting pipe operator in type hints
SylviaWhittle Apr 22, 2024
c2fe677
Fix parametrization
SylviaWhittle Apr 23, 2024
4f5b611
Switch prints with logging
SylviaWhittle Apr 29, 2024
1938d27
Add loading of jpk files
SylviaWhittle Apr 23, 2024
54193af
Tests for load_jpk
SylviaWhittle Apr 23, 2024
f765a4c
Documentation for loading jpk
SylviaWhittle Apr 23, 2024
9d5768e
jpk test file
SylviaWhittle Apr 23, 2024
344211c
Dependency for tifffile
SylviaWhittle Apr 23, 2024
9d8feb7
Example loading jpk
SylviaWhittle Apr 23, 2024
4db2370
Switch prints with logging
SylviaWhittle Apr 29, 2024
d90db6d
Switch info with error logging statements in exceptions
SylviaWhittle Apr 29, 2024
08a26b9
[pre-commit.ci] pre-commit-autoupdate
pre-commit-ci[bot] Apr 29, 2024
f9b59d6
Merge pull request #37 from AFM-SPM/ns-rse/configure-coverage
ns-rse Apr 30, 2024
4b38178
Merge pull request #38 from AFM-SPM/pre-commit-ci-update-config
ns-rse Apr 30, 2024
48391b2
Fix missing " in readme
SylviaWhittle Apr 30, 2024
64ca069
Revert operation back to how topostats uses spm and update docstring
SylviaWhittle Apr 30, 2024
4deba60
Merge branch 'SylviaWhittle/file-type-spm' of github.com:AFM-SPM/topo…
SylviaWhittle Apr 30, 2024
95a9fcf
Add example to docstring
SylviaWhittle Apr 30, 2024
764effb
docs: doctest format for example in docstring
ns-rse Apr 30, 2024
2a9b4ed
docs: doctest format for example in docstring
ns-rse Apr 30, 2024
7a98e3d
Merge pull request #36 from AFM-SPM/SylviaWhittle/file-type-jpk
SylviaWhittle May 1, 2024
58022ef
Add loading of spm files
SylviaWhittle Apr 22, 2024
b19e108
Tests for load_spm
SylviaWhittle Apr 22, 2024
93bbf8e
Documentation for loading spm
SylviaWhittle Apr 22, 2024
c82e86c
Spm test file
SylviaWhittle Apr 22, 2024
ca6d89f
Example loading spm
SylviaWhittle Apr 22, 2024
9632136
Fix tiny bug in asd loading - ensure strings are converted to paths
SylviaWhittle Apr 22, 2024
f2a11ed
Fix python 3.9 not supporting pipe operator in type hints
SylviaWhittle Apr 22, 2024
43543ff
Fix parametrization
SylviaWhittle Apr 23, 2024
21521d8
Switch prints with logging
SylviaWhittle Apr 29, 2024
50fe578
Switch info with error logging statements in exceptions
SylviaWhittle Apr 29, 2024
5373635
Revert operation back to how topostats uses spm and update docstring
SylviaWhittle Apr 30, 2024
26598d2
Fix missing " in readme
SylviaWhittle Apr 30, 2024
2d8dcf1
docs: doctest format for example in docstring
ns-rse Apr 30, 2024
f589f6b
Resolve merge conflicts
SylviaWhittle May 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.1
rev: v0.4.2
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
types: [python]
Expand Down
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +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 @@ -40,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 @@ -51,9 +64,20 @@ 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", channel="TP")
```

### .jpk

You can open `.jpk` files using the `load_jpk` function. Just pass in the path
to the file and the channel name you want to use. (If in doubt, use `height_trace` or `measuredHeight_trace`).

```python
from topofileformats.jpk import load_jpk

frames, pixel_to_nanometre_scaling_factor, metadata = load_asd(file_path="./my_asd_file.asd")
image, pixel_to_nanometre_scaling_factor = load_jpk(file_path="./my_jpk_file.jpk", channel="height_trace")
```

## Contributing
Expand Down
118 changes: 115 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,10 @@
"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}\")"
]
},
{
Expand All @@ -27,7 +82,64 @@
"metadata": {},
"outputs": [],
"source": [
"create_animation(file_name=\"sample_0\", frames=frames)"
"# 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()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 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\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# JPK Files"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import the load_jpk function from topofileformats\n",
"from topofileformats.jpk import load_jpk"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load the IBW file as an image and pixel to nm scaling factor\n",
"FILE = \"../tests/resources/sample_0.jpk\"\n",
"image, pixel_to_nm_scaling = load_jpk(file_path=FILE, channel=\"height_trac\")"
]
},
{
"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()"
]
}
],
Expand Down
13 changes: 12 additions & 1 deletion 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 @@ -30,7 +31,9 @@ keywords = [

dependencies = [
"matplotlib",
"numpy",
"tifffile",
"pySPM",
"pySPM",
"loguru",
]

Expand Down Expand Up @@ -134,3 +137,11 @@ convention = "numpy"

[tool.ruff.flake8-pytest-style]
fixture-parentheses = true

[tool.coverage.run]
source = ["topofileformats"]
omit = [
"topofileformats/_version.py",
"*tests*",
"**/__init__*",
]
Binary file added tests/resources/sample_0.jpk
Binary file not shown.
Loading
Loading