magmap.io.np_io module¶
Import/export for Numpy-based archives such as .npy and .npz formats.
- class magmap.io.np_io.Image5d(img=None, path_img=None, path_meta=None, img_io=None)[source]¶
Bases:
objectMain image storage.
- Variables:
img – 5D Numpy array in the format
t,z,y,x,c; defaults to None.path_img – Path from which
imgwas loaded; defaults to None.path_meta – Path from which metadata for
imgwas loaded; defaults to None.img_io – I/O source for image5d array; defaults to None.
subimg_offset – Sub-image offset in
z,y,x; defaults to None.subimg_size – Sub-image size in
z,y,x; defaults to None.meta – Image metadata dictionary; defaults to None.
- magmap.io.np_io.find_scaling(img_path, scaled_shape=None, scale=None, load_size=None)[source]¶
Find scaling between two images.
Scaling can be computed to translate blob coordinates into another space, such as a downsampled image. These compressed coordinates can be used to generate a heat map of blobs.
- Parameters:
img_path (
str) – Base path to image.scaled_shape (
Optional[Sequence[int]], default:None) – Shape of image to calculate scaling factor if this factor cannot be found from a transposed file’s metadata; defaults to None.scale (
Optional[float], default:None) – Scalar scaling factor, used to find a rescaled file; defaults to None. To find a resized file instead, set an atlas profile with the resizing factor.load_size (
Optional[Sequence[int]], default:None) – Size of image to load inx, y, z, typically given by an atlas profile and used to identify the path of the scaled image to load; defaults to None.
- Return type:
- Returns:
Tuple of sequence of scaling factors to a scaled or resized image, or None if not loaded or given, and the resolutions of the full-sized image found based on
img_path.
- magmap.io.np_io.get_num_channels(img, is_3d=False)[source]¶
Get the number of image channels based on expected dimensions.
- magmap.io.np_io.img_to_blobs_path(path)[source]¶
Get the blobs path associated with an image or user-supplied.
The user-supplied blobs path stored in
magmap.io.config.load_datatakes precedence overpath.
- magmap.io.np_io.read_np_archive(archive)[source]¶
Load Numpy archive file into a dictionary, skipping any values that cannot be loaded.
- Parameters:
archive – Loaded Numpy archive.
- Returns:
Dictionary with keys and values corresponding to that of the Numpy archive, skipping any values that could not be loaded such as those that would require pickling when not allowed.
- magmap.io.np_io.read_tif(path, img5d=None)[source]¶
Read TIF files with Tifffile with lazy access through memory mapping.
- magmap.io.np_io.setup_images(path, series=None, offset=None, size=None, proc_type=None, allow_import=True, fallback_main_img=True, bg_atlas=None, labels_ref_path=None)[source]¶
Sets up an image and all associated images and metadata.
Paths for related files such as registered images will generally be constructed from
path. Ifconfig.prefixis set, it will be used in place ofpathfor registered labels.- Parameters:
path (
str) – Path to image from which MagellanMapper-style paths will be generated.series (
Optional[int], default:None) – Image series number; defaults to None.offset (
Optional[Sequence[int]], default:None) – Sub-image offset given in z,y,x; defaults to None.size (
Optional[Sequence[int]], default:None) – Sub-image shape given in z,y,x; defaults to None.proc_type (
Optional[ProcessTypes], default:None) – Processing type.allow_import (
bool, default:True) – True to allow importing the image if it cannot be loaded; defaults to True.fallback_main_img (
bool, default:True) – True to fall back to loading a registered image if possible if the main image could not be loaded; defaults to True.bg_atlas (
Optional[BrainGlobeAtlas], default:None) – BrainGlobe atlas; defaults to None. If provided, the images and labels reference will be extracted from the atlas instead of loaded frompath.labels_ref_path (
Optional[str], default:None) – Path to labels reference file. Defaults to None, in which case :att:`config.load_labels` and any loaded labels metadata will be used.
- magmap.io.np_io.write_raw_file(arr, path)[source]¶
Write an array to a RAW data file.
The array will be output directly to disk through a memmapped object.
- Parameters:
arr (
np.ndarray) – Array to write.path (str) – Output path.