"""Utility class for loading data from different file formats.
...
...
@@ -222,11 +226,12 @@ class DataLoader:
"""Load a TXRM/XRM/TXM file from the specified path.
Args:
path (str): The path to the TXRM/XRM/TXM file.
path (str): The path to the TXRM/TXM file.
Returns:
numpy.ndarray or tuple: The loaded volume.
If 'self.return_metadata' is True, returns a tuple (volume, metadata).
numpy.ndarray, dask.array.core.Array or tuple: The loaded volume.
If 'virtual_stack' is True, returns a dask.array.core.Array object.
If 'return_metadata' is True, returns a tuple (volume, metadata).
Raises:
ValueError: If the dxchange library is not installed
...
...
@@ -239,18 +244,41 @@ class DataLoader:
"The library dxchange is required to load TXRM files. Please find installation instructions at https://dxchange.readthedocs.io/en/latest/source/install.html"
)
ifself.virtual_stack:
ifnotpath.endswith('.txm'):
log.warning("Virtual stack is only thoroughly tested for reconstructed volumes in TXM format and is thus not guaranteed to load TXRM and XRM files correctly")
# Get metadata
ole=olefile.OleFileIO(path)
metadata=dxchange.reader.read_ole_metadata(ole)
# Compute data offsets in bytes for each slice
offsets=_get_ole_offsets(ole)
iflen(offsets)!=metadata['number_of_images']:
raiseValueError(f'Metadata is erroneous: number of images {metadata["number_of_images"]} is different from number of data offsets {len(offsets)}')
log.warning('Virtual stack volume will be returned as a dask array. To load certain slices into memory, use normal indexing followed by the compute() method, e.g. vol[:,0,:].compute()')
else:
vol,metadata=dxchange.read_txrm(path)
vol=(
vol.squeeze()
)# In case of an XRM file, the third redundant dimension is removed
log.info("Loaded shape: %s",vol.shape)
ifself.virtual_stack:
raiseNotImplementedError(
"Using virtual stack for TXRM files is not implemented yet"