Skip to content

projection

Task for 3D->2D maximum-intensity projection.

projection(*, zarr_url, method=DaskProjectionMethod.MIP, output_image_name=Field(default='{image_name}_{method}', pattern='^.*\\{image_name\\}.*$'), overwrite=False)

Perform intensity projection along Z axis with a chosen method.

this task will write the output in a new OM-Zarr file

in the same location as the input one, with the same name plus a suffix indicating the projection method used (e.g. "_MIP" for maximum intensity projection).

PARAMETER DESCRIPTION
zarr_url

Path or url to the individual OME-Zarr image to be processed.

TYPE: str

method

Choose which method to use for intensity projection along the Z axis.

TYPE: DaskProjectionMethod DEFAULT: MIP

output_image_name

The template for the output image name. To make sure that the output image is unique it must contain the placeholder {image_name}, and it can optionally contain the placeholder {method}.

TYPE: str DEFAULT: Field(default='{image_name}_{method}', pattern='^.*\\{image_name\\}.*$')

overwrite

If True, previous projected images with the same "output_image_name" will be overwritten.

TYPE: bool DEFAULT: False

Source code in fractal_tasks_core/projection.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
@validate_call
def projection(
    *,
    zarr_url: str,
    method: DaskProjectionMethod = DaskProjectionMethod.MIP,
    output_image_name: str = Field(
        default="{image_name}_{method}",
        pattern=r"^.*\{image_name\}.*$",
    ),
    overwrite: bool = False,
) -> dict[str, Any]:
    """Perform intensity projection along Z axis with a chosen method.

    Note: this task will write the output in a new OM-Zarr file
        in the same location as the input one, with the same name plus
        a suffix indicating the projection method used (e.g. "_MIP" for
        maximum intensity projection).

    Args:
        zarr_url: Path or url to the individual OME-Zarr image to be processed.
        method: Choose which method to use for intensity projection along the
            Z axis.
        output_image_name: The template for the output image name. To make sure
            that the output image is unique it must contain the placeholder
            {image_name}, and it can optionally contain the placeholder {method}.
        overwrite: If True, previous projected images with the same "output_image_name"
            will be overwritten.
    """
    if not zarr_url.endswith(".zarr"):
        raise ValueError(f"The input zarr url must end with .zarr, but got {zarr_url}")

    base, image_name = zarr_url.rsplit("/", 1)
    image_name = image_name.removesuffix(".zarr")
    output_image_name = format_template_name(
        output_image_name, image_name=image_name, method=method.abbreviation
    )
    if not output_image_name.endswith(".zarr"):
        output_image_name = f"{output_image_name}.zarr"
    output_zarr_url = f"{base}/{output_image_name}"
    return projection_core(
        input_zarr_url=zarr_url,
        output_zarr_url=output_zarr_url,
        method=method,
        overwrite=overwrite,
    )