playnano.io.data_loaders module

Load stacks saved by playNano as NPZ, HDF5 or OME-TIFF files.

Usually these are called through playnano.io.loader.load_afm_stack() or playnano.afm_stack.AFMImageStack.load_data(), which choose the loader from the file extension.

playnano.io.data_loaders.load_h5_bundle(path: Path, channel: str = 'height_trace') → AFMImageStack[source]

Load a stack from an HDF5 bundle.

Reads files written by save_h5_bundle().

Parameters:
  • path (str or pathlib.Path) – The .h5 file.

  • channel (str, optional) – Ignored; the channel saved in the bundle is used. Accepted so all loaders can be called the same way by load_afm_stack().

Returns:

The stack, with processed, masks, frame_metadata, state_backups (if saved) and provenance restored. stack.provenance["bundle"] records the file it was read from (bundle_file) and its type (bundle_type).

Return type:

AFMImageStack

Raises:
  • KeyError – If the /data dataset or the pixel_size_nm or channel attribute is missing.

  • ValueError – If /frame_metadata_json or /provenance_json is missing, or a JSON dataset cannot be decoded.

playnano.io.data_loaders.load_npz_bundle(path: Path, channel: str = 'height_trace') → AFMImageStack[source]

Load a stack from an NPZ bundle.

Reads files written by save_npz_bundle(). The file is read without running any code it contains: bundles from playNano 0.5.4 and later hold only plain arrays, and the text fields of older bundles (stored as pickled object arrays) are read with a restricted unpickler that only rebuilds arrays of text.

Parameters:
  • path (str or pathlib.Path) – The .npz file.

  • channel (str, optional) – Ignored; the channel saved in the bundle is used. Accepted so all loaders can be called the same way by load_afm_stack().

Returns:

The stack, with processed, masks, frame_metadata, state_backups and provenance restored. stack.provenance["bundle"] records the file it was read from (bundle_file) and its type (bundle_type).

Return type:

AFMImageStack

Raises:
  • KeyError – If data, pixel_size_nm or channel is missing.

  • ValueError – If frame_metadata_json or provenance_json is missing, a JSON entry cannot be decoded, or the file contains pickled objects other than text (which could run code).

playnano.io.data_loaders.load_ome_tiff_stack(path: Path, channel: str = 'height_trace') → AFMImageStack[source]

Load a stack from an OME-TIFF file.

Made for files saved by save_ome_tiff_stack(), but other OME-TIFF stacks with axes (T, C, Z, Y, X) or (T, Y, X) also load; only the first channel and Z plane are read.

Parameters:
  • path (str or pathlib.Path) – The .ome.tif file.

  • channel (str, optional) – Channel name to use if the file does not name one. Default is "height_trace".

Returns:

The stack, as float32. Values are taken from the OME metadata where present, with these fallbacks:

  • pixel size from PhysicalSizeX (µm, converted to nm), else 1.0 nm;

  • frame times from each plane’s DeltaT, else the frame index;

  • provenance from TIFF tag 65000, else from a UserDataProvenance entry in the image description, else empty.

frame_metadata holds only timestamp and frame_pixel_size_nm. stack.provenance["bundle"] records the file it was read from (bundle_file) and its type (bundle_type).

Return type:

AFMImageStack

Raises:

ValueError – If the image does not have 3 or 5 dimensions.