playnano.io.formats.read_spm_folder module¶
Load a folder of Bruker NanoScope .spm files, one per frame, as an AFMImageStack.
Files are read with AFMReader, which returns heights in nm. Frames are taken in file-name order.
Timing: if every file’s header has Relative frame time, those times give
timestamp (s from the first frame) and frame_duration_s (the time to
the next frame), which include any pause between frames. If any file lacks it,
the whole stack uses an even interval of lines / Scan Rate.
scan_direction is stored per frame, because NanoScope time series can
alternate between up and down frames. start_epoch_ms comes from each
file’s Date.
- playnano.io.formats.read_spm_folder.load_spm_folder(folder_path: Path | str, channel: str) AFMImageStack[source]¶
Load a folder of NanoScope
.spmfiles as one stack.- Parameters:
folder_path (str or pathlib.Path) – Folder of frame files:
.spmor numbered.001,.002… files. Files are sorted by name.channel (str) – Channel to load, for example
"Height","ZSensor"or"Height Sensor".
- Returns:
The stack.
pixel_size_nmis the first frame’s; eachframe_metadataentry holdstimestamp(s from the first frame),frame_pixel_size_nm,line_rate,frame_duration_s,start_epoch_msandscan_direction. The last frame’sframe_duration_sis None when real frame times are used, because there is no next frame to measure to.- Return type:
- Raises:
ValueError – If
folder_pathis not a folder, the first file has noScan Rate, or the frames differ in shape.FileNotFoundError – If the folder has no
.spmor numbered files.
Notes
Dateis local time with one-second precision, but it is stored as if it were UTC, sostart_epoch_mscan be off by the time zone offset. Use it for records, not to align recordings to better than a second.
- playnano.io.formats.read_spm_folder.parse_spm_header(file_path, max_bytes=65536)[source]¶
Read the text header of an
.spmfile into a dict.The header is a list of
key: valuelines, each starting with a backslash, at the start of the file before the binary image data.- Parameters:
file_path (str or pathlib.Path) – The
.spmfile.max_bytes (int, optional) – Number of bytes to read from the start of the file. Enough for the fields this reader uses in typical files; very long headers may need more. Default is 65536.
- Returns:
Header keys mapped to their values, both as str. Values keep their units. Malformed lines are skipped.
- Return type: