Skip to main content

A Python package for visualizing and analyzing Atomic Force Microscopy(AFM) and Piezoelectric Force Microscopy(PFM) experimental data, offering tools to process, visualize, and extract meaningful insights from AFM images and measurements.

Project description

AFM-tools is a Python package for loading, processing, and visualizing Atomic Force Microscopy (AFM) and Piezoelectric Force Microscopy (PFM) data.

Installation

Install from PyPI:

pip install AFM-tools

Most users should use this pip install. It includes all core AFM/PFM features. 3D utilities in afm_tools.drawing_3d require mayavi (VTK/Qt stack), which is recommended via Conda.

Install from source:

git clone https://github.com/yig319/AFM-tools.git
cd AFM-tools
pip install -e .

Clone On A New Desktop (Core Pip Environment)

From a fresh machine, this is the recommended setup for core AFM-tools usage:

git clone https://github.com/yig319/AFM-tools.git
cd AFM-tools
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements-dev.txt
pip install -e .

Optional: 3D environment (Mayavi via Conda)

If you need drawing_3d/Mayavi features:

conda env create -f environment-mayavi.yml
conda activate afm-tools-3d

This Conda environment installs mayavi/vtk/pyqt plus AFM-tools dependencies. Use it when you need 3D visualization.

Quick Start

import numpy as np
from afm_tools.afm_viz import AFMVisualizer

# Example image array (replace with real AFM/PFM image data)
img = np.random.randn(256, 256)

viz = AFMVisualizer()
viz.viz(img=img, scan_size={"image_size": 256, "scale_size": 1, "units": "µm"})

IBW Preview Style

The high-level IBW preview keeps the compact AFM/PFM plotting style as the default: percentile color limits, MAD-based outlier handling, inward colorbar ticks, small colorbar labels, the unit above the colorbar, and a bottom-right scale bar with its label offset from the bar.

from afm_tools.afm_viz import AfmPreviewOptions, load_afm_dataset, render_afm_preview

dataset = load_afm_dataset("tests/ibw_preview/sample.ibw")
rendered = render_afm_preview(
    dataset,
    AfmPreviewOptions(selected_channel_indices=[0], show_metric_overlay=True),
)
rendered.figure.savefig("sample_preview.png", dpi=180, bbox_inches="tight")

You can tune the restored defaults without rewriting the plotting function:

options = AfmPreviewOptions(
    selected_channel_indices=[0],
    colorbar_setting={
        "style": "compact",
        "tick_labelsize": 7,
        "unit_position": "top",
        "scale_image": True,
    },
    scalebar_setting={
        "text_offset": 0.55,
        "text_fontsize": 9,
    },
)

Use colorbar_setting={"style": "matplotlib"} for Matplotlib’s standard side-label colorbar. Use {"scale_image": False, "tick_unit": True} to keep raw meter-valued image data and scale only the colorbar tick labels, matching older AFM visualizer behavior.

To generate preview PNGs from the bundled sample IBW file:

python tests/ibw_preview/ibw_preview.py
python tests/ibw_preview/ibw_preview.py --channels all

The images are written to tests/ibw_preview/outputs by default.

Features

  • Read and parse AFM-related wave/image formats.

  • 2D/3D visualization utilities for AFM/PFM datasets.

  • Domain and morphology analysis helpers.

  • Video and plotting utilities for time/scan series.

Documentation

Sphinx documentation is provided in the docs directory.

Build docs locally:

pip install -r docs/requirements.txt
pip install -e .
sphinx-build -b html docs docs/_build/html

License

This project is licensed under the MIT License. See LICENSE.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afm_tools-2.1.2.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afm_tools-2.1.2-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file afm_tools-2.1.2.tar.gz.

File metadata

  • Download URL: afm_tools-2.1.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for afm_tools-2.1.2.tar.gz
Algorithm Hash digest
SHA256 2921a32fd06e18b7457546b72d0793b81ea365a4d29237e21ebeb10dcc0bd324
MD5 d7e75ec9e6d71ae56d0a909497204337
BLAKE2b-256 78293eee305127bcd962748c61803ea1c6467419d6d0dc816d2e68f01bb60a4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for afm_tools-2.1.2.tar.gz:

Publisher: main.yml on yig319/AFM-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file afm_tools-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: afm_tools-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for afm_tools-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a76f9737e7cecf9856973407c7f1bb74ff06cae3b3cb06931d20a84699f3c62e
MD5 ed14133f4983795b4a49dc86c493806d
BLAKE2b-256 8d2b1b3518d6945f1e3d99879f7d2bd2ba875f685b238a245adae234ac448a7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for afm_tools-2.1.2-py3-none-any.whl:

Publisher: main.yml on yig319/AFM-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page