# afm-spm/afmreader architecture

> Architecture diagram of the GitHub repository afm-spm/afmreader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/afm-spm/afmreader
- Repository: https://github.com/afm-spm/afmreader

## Overview

AFMReader is a Python library that decodes AFM files into image arrays with pixel-to-nanometre scaling, and sometimes metadata or frame timestamps. Users can call a format-specific loader directly, or use the suffix-based LoadFile switchboard; that switchboard dispatches to the relevant decoder and returns the image and scaling (or a propagated channel error). Format readers cover the README’s supported formats, while shared binary/HDF5 helpers support several decoders. Relationships are limited to documented usage, shown dispatch calls, and source-index references; unsampled implementation details are not inferred.

Main entry points: [`AFMReader/general_loader.py`](https://github.com/afm-spm/afmreader/blob/main/AFMReader/general_loader.py) (Suffix dispatcher), [`AFMReader/io.py`](https://github.com/afm-spm/afmreader/blob/main/AFMReader/io.py) (Binary and HDF5 I/O), [`AFMReader/asd.py`](https://github.com/afm-spm/afmreader/blob/main/AFMReader/asd.py) (ASD reader), [`AFMReader/gwy.py`](https://github.com/afm-spm/afmreader/blob/main/AFMReader/gwy.py) (GWY reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dispatch["Loading API"]
  node_loader["Suffix dispatcher<br/>[general_loader.py]"]
end

subgraph group_formats["Format Readers"]
  node_asd["ASD reader<br/>[asd.py]"]
  node_gwy["GWY reader<br/>[gwy.py]"]
  node_h5jpk["H5-JPK reader<br/>[h5_jpk.py]"]
  node_ibw["IBW reader<br/>[ibw.py]"]
  node_jpk["JPK reader<br/>[jpk.py]"]
  node_spm["SPM reader<br/>[spm.py]"]
  node_stp["STP reader<br/>[stp.py]"]
  node_top["TOP reader<br/>[top.py]"]
  node_topostats["TopoStats reader<br/>[topostats.py]"]
end

subgraph group_shared["Shared Utilities"]
  node_io["Binary and HDF5 I/O<br/>[io.py]"]
  node_logging["Logging setup<br/>[logging.py]"]
end

node_python_user(("Python caller"))

node_python_user -.->|"loads by suffix"| node_loader
node_loader -->|"dispatches to"| node_asd
node_loader -->|"dispatches to"| node_gwy
node_loader -->|"dispatches to"| node_h5jpk
node_loader -->|"dispatches to"| node_ibw
node_loader -->|"dispatches to"| node_jpk
node_loader -->|"dispatches to"| node_spm
node_loader -->|"dispatches to"| node_stp
node_loader -->|"dispatches to"| node_top
node_loader -->|"dispatches to"| node_topostats
node_asd -->|"reads with"| node_io
node_gwy -->|"reads with"| node_io
node_jpk -->|"reads with"| node_io
node_stp -->|"reads with"| node_io
node_top -->|"reads with"| node_io
node_topostats -->|"unpacks with"| node_io

click node_loader "https://github.com/afm-spm/afmreader/blob/main/AFMReader/general_loader.py"
click node_asd "https://github.com/afm-spm/afmreader/blob/main/AFMReader/asd.py"
click node_gwy "https://github.com/afm-spm/afmreader/blob/main/AFMReader/gwy.py"
click node_h5jpk "https://github.com/afm-spm/afmreader/blob/main/AFMReader/h5_jpk.py"
click node_ibw "https://github.com/afm-spm/afmreader/blob/main/AFMReader/ibw.py"
click node_jpk "https://github.com/afm-spm/afmreader/blob/main/AFMReader/jpk.py"
click node_spm "https://github.com/afm-spm/afmreader/blob/main/AFMReader/spm.py"
click node_stp "https://github.com/afm-spm/afmreader/blob/main/AFMReader/stp.py"
click node_top "https://github.com/afm-spm/afmreader/blob/main/AFMReader/top.py"
click node_topostats "https://github.com/afm-spm/afmreader/blob/main/AFMReader/topostats.py"
click node_io "https://github.com/afm-spm/afmreader/blob/main/AFMReader/io.py"
click node_logging "https://github.com/afm-spm/afmreader/blob/main/AFMReader/logging.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader toneBlue
class node_asd,node_gwy,node_h5jpk,node_ibw,node_jpk,node_spm,node_stp,node_top,node_topostats toneAmber
class node_io,node_logging toneMint
class node_python_user toneIndigo
```

## Components

### Loading API

- [Suffix dispatcher](https://github.com/afm-spm/afmreader/blob/main/AFMReader/general_loader.py): `AFMReader/general_loader.py`

### Format Readers

- [ASD reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/asd.py): `AFMReader/asd.py`
- [GWY reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/gwy.py): `AFMReader/gwy.py`
- [H5-JPK reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/h5_jpk.py): `AFMReader/h5_jpk.py`
- [IBW reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/ibw.py): `AFMReader/ibw.py`
- [JPK reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/jpk.py): `AFMReader/jpk.py`
- [SPM reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/spm.py): `AFMReader/spm.py`
- [STP reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/stp.py): `AFMReader/stp.py`
- [TOP reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/top.py): `AFMReader/top.py`
- [TopoStats reader](https://github.com/afm-spm/afmreader/blob/main/AFMReader/topostats.py): `AFMReader/topostats.py`

### Shared Utilities

- [Binary and HDF5 I/O](https://github.com/afm-spm/afmreader/blob/main/AFMReader/io.py): `AFMReader/io.py`
- [Logging setup](https://github.com/afm-spm/afmreader/blob/main/AFMReader/logging.py): `AFMReader/logging.py`

### Other components

- **Python caller**

## Connections

- Python caller → Suffix dispatcher: loads by suffix
- Suffix dispatcher → ASD reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → GWY reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → H5-JPK reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → IBW reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → JPK reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → SPM reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → STP reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → TOP reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- Suffix dispatcher → TopoStats reader: dispatches to (evidence: `AFMReader/general_loader.py`)
- ASD reader → Binary and HDF5 I/O: reads with (evidence: `AFMReader/asd.py`)
- GWY reader → Binary and HDF5 I/O: reads with (evidence: `AFMReader/gwy.py`)
- JPK reader → Binary and HDF5 I/O: reads with (evidence: `AFMReader/jpk.py`)
- STP reader → Binary and HDF5 I/O: reads with (evidence: `AFMReader/stp.py`)
- TOP reader → Binary and HDF5 I/O: reads with (evidence: `AFMReader/top.py`)
- TopoStats reader → Binary and HDF5 I/O: unpacks with (evidence: `AFMReader/topostats.py`)
