Pipeline utilities#
Refactored utilities for use in multiple pipelines.
- dystrack.pipelines.utilities.loading.robustly_load_image_after_write(target_path, await_write=2)#
Load an image from a specified target path using bioio, ensuring (as) (best as possible using simple means) that the image is no longer being actively written out by the microscope.
Works by repeatedly checking the target file size and initiating the load only if the size has not increased for at least 2 seconds. Loading itself is attempted multiple times in case it fails for some reason.
- Currently supported file types:
[“tif”, “tiff”, “czi”, “nd2”]
- Parameters:
target_path (path-like) – Path to the image file that is to be analyzed.
await_write (int, optional, default 2) – Seconds to wait between each check of the target file size to determine if the file is still being written to. Reducing this will shave off latency but increases the risk of race conditions.
- Returns:
raw – Loaded image data.
- Return type:
numpy array
- dystrack.pipelines.utilities.constraints.constrain_z_movement(z_pos, z_size, limit_fract=0.1)#
Constrain the maximum offset in the z-direction to a given fraction of the total number of z-slices. Also emits a warning if the constraint needed to be applied.
- Parameters:
z_pos (float) – The new z-position as detected by the image analysis pipeline. Must be in unit voxels (that is, unit z-slices).
z_size (int) – Number of slices in the input image.
limit_fract (float, optional, default 0.1) – Maximum fraction of z_size that z_pos is allowed to be offset relative to the center.
- Returns:
z_pos – Updated z-position, constrained to the limit if necessary and unchanged otherwise.
- Return type:
float