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 timeis 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:
- Returns:
Loaded stack.
pixel_size_nmis taken from the first frame; per-frame values live inframe_metadata(timestamp,frame_pixel_size_nm,frame_duration_s,start_epoch_ms,scan_direction,line_rate).- Return type:
Notes
The final frame’s
frame_duration_sisNone— there’s no frame N+1 to measure against, and inventing a duration would silently claim information the file doesn’t contain.start_epoch_msis derived fromDate, 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 firstmax_bytesand parses whatever key/value lines it finds.- Parameters:
- Returns:
Mapping of header keys to values as strings (values keep their unit suffixes; use
_first_floatto strip them).- Return type: