magmap.cv.chunking module#
Divides a region into smaller chunks and reassembles it.
Bases:
objectShared array storage class.
- Attrbibutes:
arr: Shared ctypes raw array. shape: Shape of the original ndarray array. dtype: Data type of the ndarray.
Bases:
objectContainer class for storing shared arrays for multiprocessing.
Arrays are taken as ndarrays, stored as raw arrays, and accessed back as ndarrays.
- Variables:
shared_arrs – Dictionary of registered names to shared image instances.
Build the initializer and its arguments for multiprocessing Pool.
- Parameters:
arrs (
Dict[Any,ndarray]) – Dictionary of ndarrays to convert to shared arrays.- Return type:
- Returns:
Tuple of
init_shared_labels()as the Pool initializer function and a tuple of the arguments to this initializer, consisting ofSharedArrsContainer.setup_shared_arrs`()and a dictionary of the shared arrays.
Convert labels image as a shared array to a NumPy array.
Set up shared arrays for reconstructing as ndarray.
- magmap.cv.chunking.get_mp_pool(initializer=None, initargs=None)[source]#
Get a multiprocessing
Poolobject, configured based onconfigsettings.- Parameters:
- Return type:
Pool- Returns:
Pool object with number of processes and max tasks per process determined by command-line and the main (first) ROI profile settings.
- magmap.cv.chunking.get_split_stack_total_shape(sub_rois, overlap=None)[source]#
Get the shape of a chunked stack.
Useful for determining the final shape of a stack that has been chunked and potentially scaled before merging the stack into an output array of this shape.
- Variables:
sub_rois – Array of sub regions, in (z, y, x, …) dimensions.
overlap – Overlap size between sub-ROIs. Defaults to None for no overlap.
- Returns:
The shape of the chunked stack after it would be merged.
Provide generic initialization for spawned multiprocessing.
- Parameters:
fn (
Callable) – Function that takesargsfor initializing each process.args – Arguments to
fn.
- magmap.cv.chunking.is_fork()[source]#
Check if the multiprocessing start method is set to “fork”.
- Returns:
True if the start method is “fork”, False if otherwise.
- Return type:
- magmap.cv.chunking.merge_blobs(blob_rois)[source]#
Combine all blobs into a master list so that each overlapping region will contain all blobs from all sub-ROIs that had blobs in those regions, obviating the need to pair sub-ROIs with one another.
- Parameters:
blob_rois (
np.ndarray) – Blob from each sub-region defined bystack_splitter(). Blobs are assumed to be a 2D array in the format[[z, y, x, ...], ...].- Returns:
Merged blobs in 2D format of the format,
[[z, y, x, ..., sub_roi_z, sub_roi_y, sub_roi_x], ...], where sub-ROI coordinates have been added as the final columns.- Return type:
np.ndarray
- magmap.cv.chunking.merge_split_stack(sub_rois, max_pixels, overlap)[source]#
Merges sub regions back into a single stack.
See :func:
merge_split_stack2for a much faster implementation if the final output array size is known beforehand.- Parameters:
- Return type:
- Returns:
The merged stack.
- magmap.cv.chunking.merge_split_stack2(sub_rois, overlap, offset, output)[source]#
Merges sub regions back into a single stack, saving directly to an output variable such as a memmapped array.
- Parameters:
sub_rois – Array of sub regions, in (z, y, x, …) dimensions.
overlap – Overlap size between sub-ROIs given as an int seq in z,y,x. Can be None for no overlap.
offset – Axis offset for output array.
output – Output array, such as a memmapped array to bypass storing the merged array in RAM.
- Returns:
The merged stack.
- magmap.cv.chunking.set_mp_start_method(val=None)[source]#
Set the multiprocessing start method.
If the start method has already been applied, will skip.
- magmap.cv.chunking.stack_splitter(shape, max_pixels, overlap=None)[source]#
Split a stack into multiple sub regions.
- Parameters:
- Return type:
- Returns:
Tuple of
sub_roi_slices, sub_rois_offsets, wheresub_roi_slicesis a Numpy object array where each element contains a tuple of slice objects defining the corresponding sub-region at that position, andsub_rois_offsetsis a Numpy array of corresponding offsets for each sub-ROI in (z, y, x) order coordinates.