How to use the aicsimageio.constants.Dimensions 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 / reader.py View on Github external
----------
        scene: int
            The index of the scene for which to return channel names.

        Returns
        -------
        channels_names: Optional[List[str]]
            List of strings representing the channel names.
            If channel dimension not present in file, return None.
        """
        # Check for channels dimension
        if Dimensions.Channel not in self.dims:
            return None

        # Channel dimension in reader data, get default channel names
        channel_index = self.dims.index(Dimensions.Channel)
        channel_dim_size = self.dask_data.shape[channel_index]
        return [str(i) for i in range(channel_dim_size)]
github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
(dim, len(selected_ranges[dim]))
            for dim in [
                Dimensions.Scene,
                Dimensions.Time,
                Dimensions.Channel,
                Dimensions.SpatialZ,
            ]
        ]

        img_stack = []

        # Loop through the dim ranges to return the requested image stack
        with open(str(im_path), "rb") as image:
            for s_index in selected_ranges[Dimensions.Scene]:
                for t_index in selected_ranges[Dimensions.Time]:
                    for c_index in selected_ranges[Dimensions.Channel]:
                        for z_index in selected_ranges[Dimensions.SpatialZ]:
                            # Use the precalculated offset to jump to the begining of
                            # the desired YX plane
                            image.seek(offsets[s_index][t_index, c_index, z_index])
                            # Read the image data as a bytearray
                            byte_array = image.read(read_lengths[s_index])
                            # Convert the bytearray to a the type pixel_type
                            typed_array = np.frombuffer(
                                byte_array, dtype=pixel_type
                            ).reshape(x_size, y_size)
                            # LIF stores YX planes so transpose them to get YX
                            typed_array = typed_array.transpose()
                            # Append the YX plane to the image stack.
                            img_stack.append(typed_array)

        shape = [len(selected_ranges[dim[0]]) for dim in ranged_dims]
github AllenCellModeling / aicsimageio / aicsimageio / aics_image.py View on Github external
    def size(self, dims: str = Dimensions.DefaultOrder) -> Tuple[int]:
        """
        Parameters
        ----------
        dims: str
            A string containing a list of dimensions being requested. The default is to
            return the six standard dims.

        Returns
        -------
        size: Tuple[int]
            A tuple with the requested dimensions filled in.
        """
        # Ensure dims is an uppercase string
        dims = dims.upper()

        # Check that dims requested are all a part of the available dims in the package
github AllenCellModeling / aicsimageio / aicsimageio / readers / lif_reader.py View on Github external
]

        """
        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
Returns
        -------
        Dict[Dimension: range]
            These ranges can then be used to iterate through the specified YX images

        """
        if read_dims is None:
            read_dims = {}

        data_shape = LifReader._dims_shape(lif=lif)

        # 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