Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dims(self, dims: str):
# Check amount of provided dims against data shape
if len(dims) != len(self.dask_data.shape):
raise exceptions.InvalidDimensionOrderingError(
f"Provided too many dimensions for the associated file. "
f"Received {len(dims)} dimensions [dims: {dims}] "
f"for image with {len(self.data.shape)} dimensions "
f"[shape: {self.data.shape}]."
)
# Set the dims
self._dims = dims
----------
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
if not (all(d in self.dims for d in dims)):
raise exceptions.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])
# Due to the 12 bit values being stored in a uint16 the raw data is a little
# fussy to get the contrast correct.
p_types = {
8: np.uint8,
12: np.dtype("
# Handle single image formats like png, jpeg, etc
if image_length == 1:
return reader.get_data(0)
# Handle many image formats like gif, mp4, etc
elif image_length > 1:
frames = []
for frame in reader.iter_data():
frames.append(frame)
return np.stack(frames)
# Catch all other image types as unsupported
# https://imageio.readthedocs.io/en/stable/userapi.html#imageio.core.format.Reader.get_length
else:
raise exceptions.UnsupportedFileFormatError(self._file)
# Reraise unsupported file format
except exceptions.UnsupportedFileFormatError:
raise exceptions.UnsupportedFileFormatError(self._file)