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 .spm files as one stack.

Parameters:
  • folder_path (str or pathlib.Path) – Folder of frame files: .spm or 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_nm is the first frame’s; each frame_metadata entry holds timestamp (s from the first frame), frame_pixel_size_nm, line_rate, frame_duration_s, start_epoch_ms and scan_direction. The last frame’s frame_duration_s is None when real frame times are used, because there is no next frame to measure to.

Return type:

AFMImageStack

Raises:
  • ValueError – If folder_path is not a folder, the first file has no Scan Rate, or the frames differ in shape.

  • FileNotFoundError – If the folder has no .spm or numbered files.

Notes

Date is local time with one-second precision, but it is stored as if it were UTC, so start_epoch_ms can 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 .spm file into a dict.

The header is a list of key: value lines, each starting with a backslash, at the start of the file before the binary image data.

Parameters:
  • file_path (str or pathlib.Path) – The .spm file.

  • 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:

dict