Skip to content

API

mesospim_fractal_tasks.tasks.mesospim_to_omezarr.mesospim_to_omezarr(*, zarr_dir, pattern='', extension='h5', zarr_name=None, image_name=None, metadata_file=None, channel_color_settings='default', num_levels=None, chunksize=DimTuple(z=64, y=1024, x=1024), overwrite=False)

Convert mesoSPIM data (TIFFs or H5) to an OME-Zarr.

Parameters:

Name Type Description Default
zarr_dir str

Path of the directory where the new OME-ZARR will be created. (standard argument for Fractal tasks, managed by Fractal server).

required
pattern str

Common pattern to identify which files in the dataset directory are to be converted (for example: if the files are image_name1.tiff, image_name2.tiff, ... then pattern = image_name). Default: "".

''
extension str

File extension of the files to convert (currently support TIFF, raw and H5 format). Default: "h5".

'h5'
zarr_name Optional[str]

Name of the OME-Zarr to create/open. If not provided, the name of the dataset directory will be used. If the OME-Zarr already exists, the new image will be appended. The overwrite argument handles the overwriting or not of the image if it exists. Default: None.

None
image_name Optional[str]

Name of the new image to be created. Default: 'raw_image'.

None
metadata_file Optional[str]

Name of the metadata file. It is expected to be in the same folder as the acquisition files. Note: if not provided, a _meta.txt will be searched using the provided pattern. Default: None.

None
channel_color_settings str

Keyword identifying the channel color settings among all saved settings. Default: "default".

'default'
num_levels int

Number of pyramid levels (including the full resolution level, so with no extra pyramid, the number of levels is 1). For a 1Tb dataset, it is recommended to have at least 6 levels. If not provided, the code will estimate the optimal pyramid depth based on the size of the image. Default: None.

None
chunksize DimTuple

Chunk size to use for the OME-Zarr image. Smaller chunksizes improve visualisation smoothness but impairs processing efficiency. Default: (64, 1024, 1024).

DimTuple(z=64, y=1024, x=1024)
overwrite bool

Whether to overwrite OME-Zarr image if it already exists. It will not overwrite the OME-Zarr folder if it already exists. Default: False.

False

mesospim_fractal_tasks.tasks.init_correct_flatfield.init_correct_flatfield(*, zarr_urls, zarr_dir, FOV_list=None, z_levels=None, resolution_level=None, save_models=False, erase_source_image=False)

Initialized BaSiCPy illumination correction task

This task prepares a parallelization list of all zarr_urls that need to be used to perform illumination correction with BaSiCPy.

Parameters:

Name Type Description Default
zarr_urls list[str]

List of paths or urls to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server).

required
zarr_dir str

path of the directory where the new OME-Zarrs will be created. Present for compatibility, not used by this task. (standard argument for Fractal tasks, managed by Fractal server).

required
FOV_list Optional[list[int]]

List of tiles to process. If provided, illumination profiles will be computed from this list of tiles without BaSiCPy. They are expected to contain only empty space. Default: None.

None
z_levels Optional[list[int]]

Two integers indicating the maximum number of z planes to process at the top and bottom of the 3D tile stack. If provided, illumination profiles will be computed using z planes up to the first number of z_levels at the bottom and down to the 2nd number of z_levels at the top of the tiles (expecting empty FOVs) without BaSiCPy. If FOV_list is not empty the subvolumes will be extracted from the tiles in FOV_list, otherwise from the four tiles at the corners. Default: None.

None
resolution_level Optional[int]

Resolution level at which to calculate the illumination correction profiles. If None, the lowest resolution level will be used for BaSiCPy and highest resolution level for empty FOVs. Default: None.

None
save_models bool

If True, illumination profiles will be saved in the parent folder of the currently processed OME-Zarr. Default: False.

False
erase_source_image bool

Whether to erase the source image after correction.

False

mesospim_fractal_tasks.tasks.correct_flatfield.correct_flatfield(*, zarr_url, init_args, models_folder=None, n_zplanes=200, basicpy_model_params=None)

Perform flatfield (and darkfield) correction using either BaSiCPy or empty FOVs for each channel label or wavelength.

Parameters:

Name Type Description Default
zarr_url str

Path or url to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server).

required
init_args Dict[str, Any]

Intialization arguments provided by init_correct_flatfield.

required
models_folder Optional[str]

Folder name where illumination profiles are stored and can be used to perform flatfield correction. If provided, fitting models is skipped and only the correction step is performed. Default: None.

None
n_zplanes int

Number of z planes to use to calculate the illumination profile model. Greater number requires more memory. If using BaSiCPy, at least 150 is recommended for a good fit. If using empty FOVs, at least 50 is recommended. If the result is not satisfactory try to increase this number. If memory overflows, try to decrease this number. Default: 200.

200
basicpy_model_params Optional[BaSiCPyModelParams]

Parameters for the BaSiC model. See documentation for more information. Default: None.

None

mesospim_fractal_tasks.tasks.init_correct_illumination.init_correct_illumination(*, zarr_urls, zarr_dir, erase_source_image=False)

Initializes illumination correction task.

Parameters:

Name Type Description Default
zarr_urls list[str]

List of paths or urls to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server).

required
zarr_dir str

path of the directory where the new OME-Zarrs will be created. Not used by this task. (standard argument for Fractal tasks, managed by Fractal server).

required
erase_source_image bool

Whether to erase the source image after correction.

False

mesospim_fractal_tasks.tasks.correct_illumination.correct_illumination(*, zarr_url, init_args, z_correction=False)

Perform a global illumination correction on a multi-channel OME-Zarr image.

The task estimates correction coefficients per tile to normalize the global illumination across all tiles. Additionally, it can perform a z-correction to compensate for Z band artifacts.

Parameters:

Name Type Description Default
zarr_url str

Path or url to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server).

required
init_args dict

The initialization arguments for the task.

required
z_correction bool

Whether to correct for Z band artifacts.

False

mesospim_fractal_tasks.tasks.init_crop_regions_of_interest.init_crop_regions_of_interest(*, zarr_urls, zarr_dir, crop_or_roi='roi', roi_table_name=None, num_levels=None, chunksize=None, overwrite=False, erase_source_image=False)

Initialise the parallelisation list for Crop Regions of Interest Task.

This task prepares a parallelization list of all rois that are to be cropped from a given Zarr image.

Parameters:

Name Type Description Default
zarr_urls list[str]

List of paths or urls to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server). Expected to be a list of length 1 for this task.

required
zarr_dir str

path to the directory where the OME-Zarr image is located and where the ROI coordinates table can be found. (standard argument for Fractal tasks, managed by Fractal server).

required
crop_or_roi str

Whether the coordinates are for a crop or a ROI. If crop, the coordinates correspond to a crop of the full resolution image to remove empty space for example. A cropped image will be output with adapted FOV_ROI_table. If roi, one or more small ROIs are to be extracted. Default: roi.

'roi'
roi_table_name Optional[str]

Name/identifier of the ROI coordinates table to identify it in the target image of the zarr_dir (e.g. if cropping zarr_dir/raw_image, the table must be in the raw_image folder). If not provided, the default roi_coords is used.

None
num_levels Optional[int]

Number of pyramid levels to generate for the ROI image (including the full resolution image). If not provided, the same multi-resolution pyramid size as the original image will be used. Default: None.

None
chunksize Optional[DimTuple]

Chunk size to use for the new ROI image(s). If None, the chunksize of the original image will be used. Default: None.

None
overwrite bool

Whether to overwrite existing ROI images if they already exist in the OME-Zarr folder. Default: False.

False
erase_source_image bool

If True, the source image will be erased after cropping. It only works if crop_or_roi is set to crop. Default: False.

False

mesospim_fractal_tasks.tasks.crop_regions_of_interest.crop_regions_of_interest(*, zarr_url, init_args)

Crop regions of interest from a multi-channel OME-Zarr image. It loads the full resolution image, crops the ROI, and saves it in the same well.

Parameters:

Name Type Description Default
zarr_url str

Path to the individual OME-Zarr image to be processed. (standard argument for Fractal tasks, managed by Fractal server).

required
init_args Dict[str, Any]

Intialization arguments provided by init_crop_regions_of_interest.

required

mesospim_fractal_tasks.tasks.stitch_with_multiview_stitcher.stitch_with_multiview_stitcher(*, zarr_url, channel, registration_resolution_level=None, registration_on_z_proj=False, registration_function='phase_correlation', overlap_tolerance=None, transform_type='translation', pre_registration_pruning_method='keep_axis_aligned', max_workers=4, fusion_chunksize=None, erase_source_image=False)

Stitches FOVs from an OME-Zarr image.

Performs registration and fusion of FOVs indicated in the FOV_ROI_table of the OME-Zarr image. Writes the fused image back to a "fused" group in the same Zarr array.

Parameters:

Name Type Description Default
zarr_url str

Absolute path to the OME-Zarr image.

required
channel StitchingChannelInputModel

Channel for registration; requires either wavelength_id (e.g. 488) or label (e.g. PGP9.5), but not both.

required
registration_resolution_level Optional[int]

Resolution level to use for registration. Recommended to set the lowest level possible, e.g. 5 (highest is 0). If None, the lowest resolution level available will be used for registration. Default: None.

None
registration_on_z_proj bool

Whether to perform registration on a maximum projection along z in case of 3D data. Recommended when memory is limited but results are generally less good. Default: False.

False
registration_function str

Type of transformation to use for registration. Available functions: - 'phase_correlation' - 'antspy': see ANTsPy documentation for more information. Default: 'phase_correlation'.

'phase_correlation'
overlap_tolerance Optional[DimTuple]

Extend overlap regions considered for pairwise registration. Currently, the overlap between tiles as referenced in the metadata is used. To go beyond this, the following options are available: - if 0, the overlap region is the intersection of the tiles. - if > 0, the overlap region is the intersection of the tiles extended by this value in the given spatial dimensions. Default: 0 for all dimensions.

None
transform_type str

Type of transformation to use for registration. Available types: - 'translation': translation - 'rigid': rigid body transformation - 'similarity': similarity transformation - 'affine': affine transformation Default: 'translation'.

'translation'
pre_registration_pruning_method str

Method to use for selecting a subset of all overlapping tiles for pairwise registration. By default, only lower, upper, right and left neighbors are considered. Set this parameter to no_pruning if pairs of tiles which deviate from this pattern need to be registered. Available methods: - None: No pruning, useful when no regular arrangement is present. - 'alternating_pattern': Prune to edges between squares of differering colors in checkerboard pattern. Useful for regular 2D tile arrangements (of both 2D or 3D data). - 'shortest_paths_overlap_weighted': Prune to shortest paths in overlap graph (weighted by overlap). Useful to minimize the number of pairwise registrations. - 'otsu_threshold_on_overlap': Prune to edges with overlap above Otsu threshold. This is useful for regular 2D or 3D grid arrangements, as diagonal edges will be pruned. - 'keep_axis_aligned': Keep only edges that align with tile axes. This is useful for regular grid arrangements and to explicitely prune diagonals, e.g. when other methods fail.

'keep_axis_aligned'
max_workers int

Maximum number of workers to process blocks in parallel. Should not be more than number of available workers. If set to one, it falls back to sequential processing. Default: 4.

4
fusion_chunksize Optional[DimTuple]

Chunksize for the dimension (Z, Y, X) to use when performing the fusion. It impacts the memory usage and the time to fuse the tiles. It also corresponds to the chunksize of the output zarr. Setting smaller chunks can reduce memory usage but increase the time to fuse the tiles. If None, the chunksize of the raw image is used. Default: None.

None
erase_source_image bool

If True, the source image will be erased after stitching. Default: False.

False