Skip to main content

AFMReader

PyPI version PyPI - Python Version Code style: Ruff Code style: black Code style: flake8

pre-commit.ci status fair-software.eu

Downloads Downloads Downloads

A library for loading various Atomic Force Microscopy (AFM) file formats into Python. This library is primarily intended for use with TopoStats.

Supported file formats

File format Description
.asd High-speed AFM
.gwy Gwydion
.h5-jpk Bruker
.ibw WaveMetrics
.jpk-qi-image Bruker
.jpk Bruker
.jpk-qi-data Bruker
.spm Bruker's Format
.stp WSXM AFM software files
.top .stp variant
.topostats TopoStats
.bin Unspecificied binary file format

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 AFMReader these are denoted in bold below.

File format Description Status
.nhf Nanosurf To Be Implemented.
.aris Imaris Oxford Instruments To Be Implemented.
.tiff Park Systems To Be Implemented.

Usage

If you wish to process AFM images supported by AFMReader it is recommend you use TopoStats to do so, however the library can be used on its own.

.topostats

You can open .topostats files using the load_topostats function. Just pass in the path to the file.

from AFMReader.topostats import load_topostats

image, pixel_to_nanometre_scaling_factor, metadata = load_topostats(file_path="./my_topostats_file.topostats")

.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").

from AFMReader.spm import load_spm

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

.gwy

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

from AFMReader.gwy import load_gwy

image, pixel_to_nanometre_scaling_factor = load_gwy(file_path="./my_gwy_file.gwy", 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 want to use. (If in doubt use the "TP" topography channel).

Note: For .asd files, there seem to only ever be two channels in one file. "TP" (topography) is the main one you will want to use unless you know you specifically want something else.

Other channels: "ER" - Error, "PH" - Phase

from AFMReader.asd import load_asd

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

.ibw

You can open .ibw files using the load_ibw function. Just pass in the path to the file and the channel name that you want to use. (If in doubt, use HeightTracee (yes, with the extra 'e'), ZSensorTrace, or ZSensor).

from AFMReader.ibw import load_ibw

image, pixel_to_nanometre_scaling_factor = load_ibw(file_path="./my_ibw_file.ibw", channel="HeightTracee")

.jpk and .jpk-qi-image

You can open .jpk and .jpk-qi-image 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).

from AFMReader.jpk import load_jpk

image, pixel_to_nanometre_scaling_factor = load_jpk(file_path="./my_jpk_file.jpk", channel="height_trace")

.jpk-qi-data

You can open .jpk-qi-data files using the jpk_qi_loader class. Just pass in the path to the file and the channel name you want to use. Then call the my_jpk_qi_loader.load() method. If in doubt, use height_trace or measuredHeight_trace.

from AFMReader.jpk_qi import jpk_qi_loader

my_jpk_qi_loader = jpk_qi_loader(file_path="./my_jpk_qi_data_file.jpk-qi-data", channel="height_trace")
image, pixel_to_nanometre_scaling_factor, force_curves = my_jpk_qi_loader.load()

.h5-jpk

You can open .h5-jpk files using the load_h5jpk 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).

Note: Since .h5-jpk stores timeseries AFM data a dictionary of timestamps for each frame is also returned.

from AFMReader.h5_jpk import load_h5jpk

frames, pixel_to_nanometre_scaling_factor, timestamp_dict = load_h5jpk(
    file_path="./my_jpk_file.h5-jpk", channel="height_trace"
)

If your .h5-jpk file was created from a .jpk-qi-data file, then the curve data can be read like so. Note that reading force curves like this will keep the file open as the force curves are lazy loaded from your hard drive.

from AFMReader.h5_jpk import load_h5jpk

frames, pixel_to_nanometre_scaling_factor, timestamp_dict, force_curves = load_h5jpk(
    file_path="./my_jpk_file.h5-jpk", channel="height_trace"
)

.stp

You can open .stp files using the load_stp function. Just pass in the path to the file you want to use.

from AFMReader.stp import load_stp

image, pixel_to_nanometre_scaling_factor = load_stp(file_path="./my_stp_file.stp")

.top

You can open .top files using the load_top function. Just pass in the path to the file you want to use.

from AFMReader.top import load_top

image, pixel_to_nanometre_scaling_factor = load_top(file_path="./my_top_file.top")

.bin

You can open unspecified binary files using the load_bin function. You must supply the path to the file, the data type, the byte offset where the image data begins, and the physical dimensions of the scan. Supported data_type values include "IEEE double", "IEEE single", "float64", "float32", "I32", "U32", "I16", "U16", "I8", and "U8".

from AFMReader.bin import load_bin

image, pixel_to_nanometre_scaling_factor = load_bin(
    filepath="./my_binary_file.bin",
    data_type="IEEE double",
    offset_bytes=0,
    size_x=1000.0,  # physical width in nm
    size_y=1000.0,  # physical height in nm
    shape_x=512,  # pixels along x
    shape_y=512,  # pixels along y
    z_scaling=1.0,  # optional z-axis scaling factor
)

Contributing

Bug reports and feature requests are welcome. Please search for existing issues, if none relating to your bug/feature are found then feel free to create a new issue detailing what went wrong or the feature you would like to see implemented.

Pull requests are also welcome, please note that we have a Code of Conduct.

Setup

We use pre-commit to apply linting via ruff and pylint pre-commit hooks and use the Black and Flake8 code styles. To set yourself up for contributing after cloning the package and creating a Python virtual environment you should install the development dependencies and pre-commit as shown below.

# Activate your virtual environment, this will depend on which system you use e.g. conda or virtualenvwrapper
# Clone the repository
git clone git@github.com:AFM-SPM/AFMReader.git
# Change directories into the newly cloned directory
cd AFMReader
# Install the package along with the optional development (dev) dependencies
pip install -e .[dev]
# Install pre-commit
pre-commit install

This will ensure that any commits and pull requests you make will pass the Pre-commit Continuous Integration. Where possible ruff will correct the changes it can, but it may require you to address some issues manually, before adding any changes and attempting to commit again.

Citing

If you use or depend on AFMReader in your software please consider citing it in any derivative work that is published. Citation details can be found in the CITATION.cff file in this repository.

Also, please let us know if you use AFMReader in your software. You can either make a Pull Request to add it to the list below or you can email us at topostats@sheffield.ac.uk with details of your package.

Used By

AFMReader is a dependency of the following packages.

Metadata

Release files for AFMReader 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AFMReader 0.0.8
File Size Uploaded Provenance Actions
afmreader-0.0.8.tar.gz 65.0 MB With provenance Details for afmreader-0.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for AFMReader 0.0.8
File Interpreter ABI Platform Actions
afmreader-0.0.8-py3-none-any.whl Python 3 none any Details for afmreader-0.0.8-py3-none-any.whl

Total release size: 65.1 MB

Release files / afmreader-0.0.8.tar.gz

Download URL afmreader-0.0.8.tar.gz
Size 65.0 MB
Tags Source
SHA-256 checksum
How to use checksums
03071bdca6ed1bd271b2d69e0268b971776f87ae78678af0e45c32c6e576c2dd
BLAKE2b-256 checksum
How to use checksums
6272037c8924a08c1396ebbb398fbbdeab6fea5432926afb48bca79725b2a1e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / afmreader-0.0.8-py3-none-any.whl

Download URL afmreader-0.0.8-py3-none-any.whl
Size 80.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2a44ffce76b393f4727a32fae837e9ab5ee2bcb0e18a2dd358406db0d41a09e
BLAKE2b-256 checksum
How to use checksums
9c6fb35ed5e78824dd7f416c515baf88d932f6ad5b9504de3c30bc84622c6269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for AFMReader 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for afmreader-0.0.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page