playnano.io.loader module

Load AFM videos from instrument files and from playNano’s own exports.

load_afm_stack() picks a reader from the file extension:

Extensions are matched without regard to case.

playnano.io.loader.get_loader_for_file(file_path: Path, file_loaders: dict, folder_loaders: dict) → callable[source]

Choose the reader for a single file.

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

  • file_loaders (dict) – Maps each extension (lower case, with the dot) to its reader. Combined extensions such as .ome.tif are checked first.

  • folder_loaders (dict) – Extensions of folder formats, used to give a helpful error when a single frame of a folder format is passed.

Returns:

The extension and its reader.

Return type:

tuple of (str, callable)

Raises:

ValueError – If the file has no extension, an unknown one, or one that belongs to a folder format (for example a single .jpk frame).

playnano.io.loader.get_loader_for_folder(folder_path: Path, folder_loaders: dict) → tuple[str, callable][source]

Choose the folder reader for a folder of frame files.

Parameters:
  • folder_path (pathlib.Path) – The folder.

  • folder_loaders (dict) – Maps each extension (lower case, with the dot) to its reader.

Returns:

The extension and its reader. If the folder holds several known types, .jpk is chosen if present, otherwise the most common. Numbered extensions such as .001 count as .spm.

Return type:

tuple of (str, callable)

Raises:

FileNotFoundError – If the folder contains no file of a known type.

playnano.io.loader.load_afm_stack(file_path: Path, channel: str = 'height_trace') → AFMImageStack[source]

Load an AFM video from a file or a folder of frame files.

The reader is chosen from the extension (see the module description). Instrument readers return heights in nm for length channels; see each reader for details.

Parameters:
  • file_path (str or pathlib.Path) – The file, or the folder of frame files.

  • channel (str, optional) – Channel to load, for example "height_trace" for .h5-jpk files. Channel names depend on the format. Ignored for NPZ and HDF5 bundles. Default is "height_trace".

Returns:

The loaded stack.

Return type:

AFMImageStack

Raises:
  • FileNotFoundError – If the path does not exist, or a folder contains no known file type.

  • ValueError – If the file type is not supported.

See also

playnano.afm_stack.AFMImageStack.load_data

The usual way to call this.