Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def metadata(self) -> _Element:
"""
Load and return the metadata from the CZI file
Returns
-------
The lxml Element Tree of the metadata
"""
# We can't serialize lxml element trees so don't save the tree to the object
# state
return CziFile(self._file).meta
The dimensions to read from the file as a dictionary of string to integer.
Default: None (Read all data from the image)
Returns
-------
data: np.ndarray
The data read for the dimensions provided.
read_dimensions: List[Tuple[str, int]]]
The dimension sizes that were returned from the read.
"""
# Catch optional read dim
if read_dims is None:
read_dims = {}
# Init czi
czi = CziFile(img)
# Read image
log.debug(f"Reading dimensions: {read_dims}")
data, dims = czi.read_image(**read_dims)
# Drop dims that shouldn't be provided back
ops = []
real_dims = []
for i, dim_info in enumerate(dims):
# Expand dimension info
dim, size = dim_info
# If the dim was provided in the read dims we know a single plane for that
# dimension was requested so remove it
if dim in read_dims:
ops.append(0)
def _read_immediate(self) -> da.core.Array:
# Init temp czi
czi = CziFile(self._file)
# Safely construct the numpy array or catch any exception
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):
In that case, use this parameter to specify a specific scene to construct a
dask array for.
Default: 0 (select the first scene)
Returns
-------
img: dask.array.core.Array
The constructed dask array where certain dimensions are chunked.
dims: str
The dimension order as a string.
"""
# Resolve image path
img = CziReader._resolve_image_path(img)
# Init temp czi
czi = CziFile(img)
# Safely construct the dask array or catch any exception
try:
return CziReader._daread(img=img, czi=czi, chunk_by_dims=chunk_by_dims, S=S)
except Exception as e:
# A really bad way to close any connection to the CZI object
czi._bytes = None
czi.reader = None
raise e
def dims(self) -> str:
if self._dims is None:
self._dims = CziFile(self._file).dims
return self._dims