playnano.io.formats.read_spm_folder module

Module to load a folder of NanoScope .spm files as an AFMImageStack.

Files contained within the same folder are read together. Files read with the height data in nm.

Timing (per-frame): real Relative frame time values from each file’s header are used to compute both timestamp (seconds from frame 0) and frame_duration_s (gap to the next frame). Real values capture the actual inter-frame jitter and dead time between acquisitions, which the synthesised lines / Scan Rate estimate would miss. If any file is missing that field the reader falls back to the synth interval for the whole stack.

Frame direction (scan_direction) is stored per frame because a NanoScope time series can capture alternating up/down frames. Absolute time (start_epoch_ms) is derived from each file’s Date field.

playnano.io.formats.read_spm_folder.load_spm_folder(folder_path: Path | str, channel: str) → AFMImageStack[source]

Load a NanoScope .spm time-series folder into an AFMImageStack.

Real per-frame timing is used when Relative frame time is present in every file, giving actual inter-frame gaps rather than a uniform synthetic interval. Frame direction is stored per frame so a series with alternating up/down frames is faithfully represented.

Parameters:
  • folder_path (Path | str) – Folder containing the .spm frames. Files with numeric extensions (.001, .002 …) are treated as .spm too.

  • channel (str) – Channel name to extract.

Returns:

Loaded stack. pixel_size_nm is taken from the first frame; per-frame values live in frame_metadata (timestamp, frame_pixel_size_nm, frame_duration_s, start_epoch_ms, scan_direction, line_rate).

Return type:

AFMImageStack

Notes

The final frame’s frame_duration_s is None — there’s no frame N+1 to measure against, and inventing a duration would silently claim information the file doesn’t contain.

start_epoch_ms is derived from Date, which is naive local time with second precision. It is good enough for provenance but should not be used for sub-second alignment across machines.

playnano.io.formats.read_spm_folder.parse_spm_header(file_path, max_bytes=65536)[source]

Extract ASCII header key-value pairs from a .spm file.

NanoScope headers are backslash-prefixed ‘key: value’ lines at the start of the file, followed by the binary image data at Data offset. This reads the first max_bytes and parses whatever key/value lines it finds.

Parameters:
  • file_path (str or Path) – Path to the .spm file.

  • max_bytes (int, optional) – Bytes to read from the start of the file. The default (65 kB) covers the fields this reader needs on typical Dimension/BioScope files, but very large headers may need more.

Returns:

Mapping of header keys to values as strings (values keep their unit suffixes; use _first_float to strip them).

Return type:

dict[str, str]