Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def size_s(self) -> int:
"""
Returns
-------
size: int
The size of the Scene dimension.
"""
return self.size(Dimensions.Scene)[0]
try:
# Get image dims indicies
image_dim_indices = czi.dims_shape()
# Catch inconsistent scene dimension sizes
if len(image_dim_indices) > 1:
# Choose the provided scene
log.info(
f"File contains variable dimensions per scene, "
f"selected scene: {self.specific_s_index} for data retrieval."
)
# Get the specific scene
if self.specific_s_index < len(image_dim_indices):
data, _ = czi.read_image(
**{Dimensions.Scene: self.specific_s_index}
)
else:
raise exceptions.InconsistentShapeError(
f"The CZI image provided has variable dimensions per scene. "
f"Please provide a valid index to the 'S' parameter to create "
f"a dask array for the index provided. "
f"Provided scene index: {self.specific_s_index}. "
f"Scene index range: 0-{len(image_dim_indices)}."
)
else:
# If the list is length one that means that all the scenes in the image
# have the same dimensions
# Read all data in the image
data, _ = czi.read_image()
def size_s(self) -> int:
return self._size_of_dimension(Dimensions.Scene)
def size_s(self) -> int:
"""
Returns
-------
size: int
The size of the Scene dimension.
"""
return self.size(Dimensions.Scene)[0]
f"Replaced with guess: {guessed_dim}"
)
break
# All of our guess dims were already in the dim list,
# append the dim read from meta
if not appended_dim:
best_guess.append(dim_from_meta)
best_guess = "".join(best_guess)
# Add scene dimension only if there are multiple scenes
if len(tiff.series) == 1:
self._dims = best_guess
else:
self._dims = f"{Dimensions.Scene}{best_guess}"
return self._dims
The list of locked dimensions
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])
-------
numpy.ndarray
a stack of images as a numpy.ndarray
List[Tuple[str, int]]
The shape of the data being returned
"""
if read_dims is None:
read_dims = {}
lif = LifFile(im_path)
# Data has already been checked for consistency. The dims are either consistent
# or S is specified selected_ranges get's the ranges for the Dimension for the
# range unless the dim is explicitly specified
selected_ranges = LifReader._read_dims_to_ranges(lif, read_dims)
s_index = read_dims[Dimensions.Scene] if Dimensions.Scene in read_dims else 0
lif_img = lif.get_image(img_n=s_index)
x_size = lif_img.dims[0]
y_size = lif_img.dims[1]
pixel_type = LifReader.get_pixel_type(meta, s_index)
# The ranged dims
ranged_dims = [
(dim, len(selected_ranges[dim]))
for dim in [
Dimensions.Scene,
Dimensions.Time,
Dimensions.Channel,
Dimensions.SpatialZ,
]
]
def size_s(self) -> int:
return self._size_of_dimension(Dimensions.Scene)