How to use the aicsimageio.constants.Dimensions.SpatialZ function in aicsimageio

To help you get started, we’ve selected a few aicsimageio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
{'S': (0, 3), 'T': (0,7), 'X': (0, 475), 'Y': (0, 325), 'Z': (0, 4)}
            ].
            The result for a similarly shaped file but with different number of time
            points per scene would yield
            [
             {'S': (0, 1), 'T': (0,8), 'X': (0, 475), 'Y': (0, 325), 'Z': (0, 4)},
             {'S': (1, 2), 'T': (0,6), 'X': (0, 475), 'Y': (0, 325), 'Z': (0, 4)},
             {'S': (2, 3), 'T': (0,7), 'X': (0, 475), 'Y': (0, 325), 'Z': (0, 4)}
            ]

        """
        shape_list = [
            {
                Dimensions.Time: (0, img.nt),
                Dimensions.Channel: (0, img.channels),
                Dimensions.SpatialZ: (0, img.nz),
                Dimensions.SpatialY: (0, img.dims[1]),
                Dimensions.SpatialX: (0, img.dims[0]),
            }
            for idx, img in enumerate(lif.get_iter_image())
        ]
        consistent = all(elem == shape_list[0] for elem in shape_list)
        if consistent:
            shape_list[0][Dimensions.Scene] = (0, len(shape_list))
            shape_list = [shape_list[0]]
        else:
            for idx, lst in enumerate(shape_list):
                lst[Dimensions.Scene] = (idx, idx + 1)
        return shape_list
github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
def __init__(
        self,
        data: types.FileLike,
        chunk_by_dims: List[str] = [
            Dimensions.SpatialZ,
            Dimensions.SpatialY,
            Dimensions.SpatialX,
        ],
        S: int = 0,
        **kwargs,
    ):
        # Run super init to check filepath provided
        super().__init__(data, **kwargs)

        # Store parameters needed for _daread
        self.chunk_by_dims = chunk_by_dims
        self.specific_s_index = S
        lif = LifFile(filename=self._file)
        #  _chunk_offsets is a list of ndarrays
        # (only way I could deal with inconsistent scene shape)
        self._chunk_offsets, self._chunk_lengths = LifReader._compute_offsets(lif=lif)
github AllenCellModeling / aicsimageio / aicsimageio / readers / czi_reader.py View on Github external
def __init__(
        self,
        data: types.FileLike,
        chunk_by_dims: List[str] = [
            Dimensions.SpatialZ,
            Dimensions.SpatialY,
            Dimensions.SpatialX,
        ],
        S: int = 0,
        **kwargs,
    ):
        # Run super init to check filepath provided
        super().__init__(data, **kwargs)

        # Store parameters needed for _daread
        self.chunk_by_dims = chunk_by_dims
        self.specific_s_index = S
github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
def size_z(self) -> int:
        return self._size_of_dimension(Dimensions.SpatialZ)
github AllenCellModeling / aicsimageio / aicsimageio / readers / czi_reader.py View on Github external
def _daread_safe(
        img: Union[str, Path],
        chunk_by_dims: List[str] = [
            Dimensions.SpatialZ,
            Dimensions.SpatialY,
            Dimensions.SpatialX,
        ],
        S: int = 0,
    ) -> Tuple[da.core.Array, str]:
        """
        Safely read a CZI image file as a delayed dask array where certain dimensions
        act as the chunk size.

        Parameters
        ----------
        img: Union[str, Path]
            The filepath to read.
        chunk_by_dims: List[str]
            The dimensions to use as the for mapping the chunks / blocks.
            Default: [Dimensions.SpatialZ, Dimensions.SpatialY, Dimensions.SpatialX]
github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
# If S is in read_dims then use the specified value and the specified dims for
        # that scene
        if Dimensions.Scene in read_dims:
            s_range = range(
                read_dims[Dimensions.Scene], read_dims[Dimensions.Scene] + 1
            )
            s_dict = data_shape[s_range[0]]
        else:
            s_range = range(*data_shape[0][Dimensions.Scene])
            s_dict = data_shape[0]

        # Map the dims over to ranges and if the dim is in read_dims make the range
        # over the single dim
        integrated_dims = {Dimensions.Scene: s_range}
        for dim in [Dimensions.Time, Dimensions.Channel, Dimensions.SpatialZ]:
            if dim in read_dims:
                integrated_dims[dim] = range(read_dims[dim], read_dims[dim] + 1)
            else:
                integrated_dims[dim] = range(*s_dict[dim])

        return integrated_dims
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
title = f"napari: {self.reader._file.name}"

            # Handle RGB entirely differently
            if rgb:
                # Swap channel to last dimension
                new_dims = f"{dims.replace(Dimensions.Channel, '')}{Dimensions.Channel}"
                data = transforms.transpose_to_dims(
                    data=data, given_dims=dims, return_dims=new_dims
                )

                # Run napari
                with napari.gui_qt():
                    napari.view_image(
                        data,
                        is_pyramid=False,
                        ndisplay=3 if Dimensions.SpatialZ in dims else 2,
                        title=title,
                        axis_labels=dims.replace(Dimensions.Channel, ""),
                        rgb=rgb,
                        **kwargs,
                    )

            # Handle all other images besides RGB not requested
            else:
                # Channel axis
                c_axis = (
                    dims.index(Dimensions.Channel)
                    if Dimensions.Channel in dims
                    else None
                )

                # Set visible based on number of channels
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
def size_z(self) -> int:
        """
        Returns
        -------
        size: int
            The size of the Spatial Z dimension.
        """
        return self.size(Dimensions.SpatialZ)[0]
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
else:
                    visible = True

                # Drop channel from dims string
                dims = (
                    dims.replace(Dimensions.Channel, "")
                    if Dimensions.Channel in dims
                    else dims
                )

                # Run napari
                with napari.gui_qt():
                    napari.view_image(
                        data,
                        is_pyramid=False,
                        ndisplay=3 if Dimensions.SpatialZ in dims else 2,
                        channel_axis=c_axis,
                        axis_labels=dims,
                        title=title,
                        visible=visible,
                        **kwargs,
                    )

        except ModuleNotFoundError:
            raise ModuleNotFoundError(
                f"'napari' has not been installed. To use this function install napari "
                f"with either: pip install napari' or "
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
def size_z(self) -> int:
        """
        Returns
        -------
        size: int
            The size of the Spatial Z dimension.
        """
        return self.size(Dimensions.SpatialZ)[0]