playnano.io.export_data module¶
Save AFM image stacks as OME-TIFF, NPZ or HDF5 files.
OME-TIFF (
save_ome_tiff_stack()): one image stack with pixel size, frame times and provenance, readable by other microscopy software (for example Fiji/Bio-Formats).NPZ (
save_npz_bundle()) and HDF5 (save_h5_bundle()): bundles with the data, every processed layer and mask, the frame metadata and the provenance, which playNano can load again withplaynano.io.data_loaders.
export_bundles() writes any of the three at once, as playnano process
--export does. All formats store heights as float32.
- playnano.io.export_data.check_path_is_path(path: str | Path) Path[source]¶
Return
pathas apathlib.Path.- Parameters:
path (str or pathlib.Path) – The path to convert.
- Returns:
pathas a Path.- Return type:
- Raises:
TypeError – If
pathis neither a str nor a Path.
- playnano.io.export_data.export_bundles(afm_stack: AFMImageStack, output_folder: Path, base_name: str, formats: list[str], raw: bool = False) None[source]¶
Save a stack in one or more of the formats OME-TIFF, NPZ and HDF5.
Files are named
<name>.ome.tif,<name>.npzand<name>.h5._filteredis added to the name when processed data is saved, that is whenrawis False and the stack has processed layers other than"raw".- Parameters:
afm_stack (AFMImageStack) – The stack to save.
output_folder (str or pathlib.Path or None) – Folder for the files; created if missing. If None,
./output.base_name (str or None) – File name without extension. Any folder part and known extension are removed. If empty or None, the name of the file the stack was loaded from is used.
raw (bool, optional) – If True, save the unprocessed snapshot
stack.processed["raw"]. Seesave_npz_bundle(). Default is False.
- Raises:
ValueError – If a format is not recognised, or an output file would overwrite the file the stack was loaded from. Nothing is written in either case.
- playnano.io.export_data.save_h5_bundle(path: Path, stack: AFMImageStack, raw: bool = False) None[source]¶
Save a stack, with its layers, masks and metadata, as an HDF5 bundle.
The file contains these datasets, compressed with gzip where they are arrays:
/data: float32, shape (n_frames, height, width)./processed/<name>: float32, one per entry instack.processed, including/processed/raw./masks/<name>: bool, one per entry instack.masks./timestamps: float64, frame times in seconds./frame_metadata_json,/provenance_json: JSON text./state_backups_json: JSON text, only ifstack.state_backupsis not empty.
and the file attributes
pixel_size_nmandchannel.- Parameters:
path (str or pathlib.Path) – Output file. Its extension is replaced by
.h5, and missing folders are created.stack (AFMImageStack) – The stack to save.
raw (bool, optional) – If True, save the unprocessed snapshot
stack.processed["raw"]instead ofstack.data, without masks or processed layers. If the stack has no"raw"snapshot,stack.datais saved. Default is False. The timestamps and frame metadata are then those from before any frames were removed.
See also
playnano.io.data_loaders.load_h5_bundleLoad the bundle again.
- playnano.io.export_data.save_npz_bundle(path: Path, stack: AFMImageStack, raw: bool = False) None[source]¶
Save a stack, with its layers, masks and metadata, as a NumPy
.npzbundle.The archive is compressed and contains these arrays:
data: float32, shape (n_frames, height, width).processed__<name>: float32, one per entry instack.processed, includingprocessed__raw.masks__<name>: bool, one per entry instack.masks.timestamps: float64, frame times in seconds.frame_metadata_json,provenance_json,state_backups_json: JSON text.pixel_size_nm: float32 scalar.channel: the channel name.
Text is stored as NumPy unicode arrays, so no array is pickled and the file can be opened with
np.load(path, allow_pickle=False). Bundles written before playNano 0.5.4 stored text as object arrays, which need pickle.- Parameters:
path (pathlib.Path) – Output file. Its extension is replaced by
.npz(out/stackbecomesout/stack.npz), and missing folders are created.stack (AFMImageStack) – The stack to save.
raw (bool, optional) – If True, save the unprocessed snapshot
stack.processed["raw"]instead ofstack.data, without masks or processed layers. If the stack has no"raw"snapshot,stack.datais saved. Default is False. The timestamps are then those from before any frames were removed.
See also
playnano.io.data_loaders.load_npz_bundleLoad the bundle again.
Examples
>>> from pathlib import Path >>> from playnano.io.export_data import save_npz_bundle >>> save_npz_bundle(Path("output/stack"), stack)
- playnano.io.export_data.save_ome_tiff_stack(path: Path, afm_stack: AFMImageStack, raw: bool = False) None[source]¶
Save a stack as an OME-TIFF file.
The data is written as float32 with axes (T, C, Z, Y, X) and one channel and Z plane. The OME metadata records the pixel size (in µm), each frame’s time (
DeltaT, in s), the interval between the first two frames (TimeIncrement) and the channel name. Two private TIFF tags hold JSON:65000: the provenance (
stack.provenance).65001: the names of the processed layers. The layers themselves and the masks are not saved; use NPZ or HDF5 for those.
- Parameters:
path (pathlib.Path) – Output file, for example
Path("out/stack.ome.tif"). Used as given; its folder must exist.afm_stack (AFMImageStack) – The stack to save.
raw (bool, optional) – If True, save the unprocessed snapshot
stack.processed["raw"]instead ofstack.data, without masks or processed layers. If the stack has no"raw"snapshot,stack.datais saved. Default is False.
- Raises:
ValueError – If the frames do not all have the same pixel size.
See also
playnano.io.data_loaders.load_ome_tiff_stackLoad the file again.
Examples
>>> from pathlib import Path >>> from playnano.io.export_data import save_ome_tiff_stack >>> save_ome_tiff_stack(Path("output/stack.ome.tif"), stack)