playnano.io.data_loaders module¶
Load stacks saved by playNano as NPZ, HDF5 or OME-TIFF files.
load_npz_bundle()andload_h5_bundle()restore everythingplaynano.io.export_datasaved: data, processed layers, masks, frame metadata, provenance and the saved metadata from before frame removal.load_ome_tiff_stack()restores the data, pixel size, frame times, channel name and provenance. OME-TIFF files do not hold processed layers or masks.
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
.h5file.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) andprovenancerestored.stack.provenance["bundle"]records the file it was read from (bundle_file) and its type (bundle_type).- Return type:
- Raises:
KeyError – If the
/datadataset or thepixel_size_nmorchannelattribute is missing.ValueError – If
/frame_metadata_jsonor/provenance_jsonis 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
.npzfile.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_backupsandprovenancerestored.stack.provenance["bundle"]records the file it was read from (bundle_file) and its type (bundle_type).- Return type:
- Raises:
KeyError – If
data,pixel_size_nmorchannelis missing.ValueError – If
frame_metadata_jsonorprovenance_jsonis 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.tiffile.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
UserDataProvenanceentry in the image description, else empty.
frame_metadataholds onlytimestampandframe_pixel_size_nm.stack.provenance["bundle"]records the file it was read from (bundle_file) and its type (bundle_type).- Return type:
- Raises:
ValueError – If the image does not have 3 or 5 dimensions.