Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def guess_dim_order(shape: Tuple[int]) -> str:
return Dimensions.DefaultOrder[len(Dimensions.DefaultOrder) - len(shape) :]
def save(self, data, dims=constants.Dimensions.DefaultOrder, **kwargs) -> None:
"""Write to open file"""
pass
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
),
shape=sample_chunk_shape,
dtype=sample.dtype,
)
# Convert the numpy array of lazy readers into a dask array and fill the inner
# most empty dimensions with chunks
merged = da.block(lazy_arrays.tolist())
# Because we have set certain dimensions to be chunked and others not
# we will need to transpose back to original dimension ordering
# Example being, if the original dimension ordering was "SZYX" and we want to
# chunk by "S", "Y", and "X" we created an array with dimensions ordering "ZSYX"
transpose_indices = []
transpose_required = False
for i, d in enumerate(Dimensions.DefaultOrder):
new_index = blocked_dimension_order.index(d)
if new_index != i:
transpose_required = True
transpose_indices.append(new_index)
else:
transpose_indices.append(i)
# Only run if the transpose is actually required
# The default case is "Z", "Y", "X", which _usually_ doesn't need to be
# transposed because that is _usually_
# The normal dimension order of the LIF file anyway
if transpose_required:
merged = da.transpose(merged, tuple(transpose_indices))
# Because dimensions outside of Y and X can be in any order and present or not
# we also return the dimension order string.
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
if not (all(d in Dimensions.DefaultOrder for d in dims)):
raise InvalidDimensionOrderingError(f"Invalid dimensions requested: {dims}")
# Check that the dims requested are in the image dims
if not (all(d in self.dims for d in dims)):
raise InvalidDimensionOrderingError(f"Invalid dimensions requested: {dims}")
# Return the shape of the data for the dimensions requested
return tuple([self.dask_data.shape[self.dims.index(dim)] for dim in dims])
# the length of the sample chunk. When dask.block happens it fills the
# dimensions from inner-most to outer-most with the chunks as long as the
# dimension is size 1. Basically, we are adding empty dimensions to the
# operating shape that will be filled by the chunks from dask
operating_shape = tuple(operating_shape) + (1,) * len(sample_chunk_shape)
# Create empty numpy array with the operating shape so that we can iter through
# and use the multi_index to create the readers.
lazy_arrays = np.ndarray(operating_shape, dtype=object)
# We can enumerate over the multi-indexed array and construct read_dims
# dictionaries by simply zipping together the ordered dims list and the current
# multi-index plus the begin index for that plane. We then set the value of the
# array at the same multi-index to the delayed reader using the constructed
# read_dims dictionary.
dims = [d for d in Dimensions.DefaultOrder]
begin_indicies = tuple(image_dim_indices[d][0] for d in dims)
for i, _ in np.ndenumerate(lazy_arrays):
# Add the czi file begin index for each dimension to the array dimension
# index
this_chunk_read_indicies = (
current_dim_begin_index + curr_dim_index
for current_dim_begin_index, curr_dim_index in zip(begin_indicies, i)
)
# Zip the dims with the read indices
this_chunk_read_dims = dict(
zip(blocked_dimension_order, this_chunk_read_indicies)
)
# Remove the dimensions that we want to chunk by from the read dims
for d in chunk_by_dims:
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 the dims requested are in the image dims
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
if not (all(d in Dimensions.DefaultOrder for d in dims)):
raise InvalidDimensionOrderingError(f"Invalid dimensions requested: {dims}")
# Check that the dims requested are in the image dims
if not (all(d in self.dims for d in dims)):
raise InvalidDimensionOrderingError(f"Invalid dimensions requested: {dims}")
# Return the shape of the data for the dimensions requested
return tuple([self.dask_data.shape[self.dims.index(dim)] for dim in dims])
"""
# Check known dims
if known_dims is not None:
if not all([d in Dimensions.DefaultOrder for d in known_dims]):
raise InvalidDimensionOrderingError(
f"The provided dimension string to the 'known_dims' argument "
f"includes dimensions that AICSImage does not support. "
f"Received: '{known_dims}'. "
f"Supported dimensions: {Dimensions.DefaultOrderList}."
)
# Hold onto known dims until data is requested
self._known_dims = known_dims
# Dims should nearly always be default dim order unless explictly overridden
self.dims = Dimensions.DefaultOrder
# Determine reader class and create dask delayed array
reader_class = self.determine_reader(data=data)
self._reader = reader_class(data, **kwargs)
# Lazy load data from reader and reformat to standard dimensions
self._dask_data = None
self._data = None
# Store dask client and cluster setup
self._dask_kwargs = dask_kwargs
self._client = None
self._cluster = None