virtual_stack (bool, optional): Specifies whether to use virtual stack
virtual_stack (bool, optional): Specifies whether to use virtual stack
when loading TIFF files. Default is False.
when loading files. Default is False.
Attributes:
Attributes:
virtual_stack (bool): Specifies whether virtual stack is enabled.
virtual_stack (bool): Specifies whether virtual stack is enabled.
...
@@ -24,6 +24,7 @@ class DataLoader:
...
@@ -24,6 +24,7 @@ class DataLoader:
load_tiff(path): Load a TIFF file from the specified path.
load_tiff(path): Load a TIFF file from the specified path.
load_h5(path): Load an HDF5 file from the specified path.
load_h5(path): Load an HDF5 file from the specified path.
load_tiff_stack(path): Load a stack of TIFF files from the specified path.
load_tiff_stack(path): Load a stack of TIFF files from the specified path.
load_txrm(path): Load a TXRM/TXM/XRM file from the specified path
load(path): Load a file or directory based on the given path.
load(path): Load a file or directory based on the given path.
Raises:
Raises:
...
@@ -40,7 +41,7 @@ class DataLoader:
...
@@ -40,7 +41,7 @@ class DataLoader:
Args:
Args:
path (str): The path to the file or directory.
path (str): The path to the file or directory.
virtual_stack (bool, optional): Specifies whether to use virtual
virtual_stack (bool, optional): Specifies whether to use virtual
stack when loading TIFF and HDF5 files. Default is False.
stack when loading files. Default is False.
dataset_name (str, optional): Specifies the name of the dataset to be loaded
dataset_name (str, optional): Specifies the name of the dataset to be loaded
in case multiple dataset exist within the same file. Default is None (only for HDF5 files)
in case multiple dataset exist within the same file. Default is None (only for HDF5 files)
return_metadata (bool, optional): Specifies whether to return metadata or not. Default is False (only for HDF5 files)
return_metadata (bool, optional): Specifies whether to return metadata or not. Default is False (only for HDF5 files)
...
@@ -87,11 +88,11 @@ class DataLoader:
...
@@ -87,11 +88,11 @@ class DataLoader:
ValueError: If the specified dataset_name is not found or is invalid.
ValueError: If the specified dataset_name is not found or is invalid.
ValueError: If the dataset_name is not specified in case of multiple datasets in the HDF5 file
ValueError: If the dataset_name is not specified in case of multiple datasets in the HDF5 file
ValueError: If no datasets are found in the file.
ValueError: If no datasets are found in the file.
"""
"""
# Read file
# Read file
f=h5py.File(path,"r")
f=h5py.File(path,"r")
data_keys=self._get_h5_dataset_keys(f)
data_keys=_get_h5_dataset_keys(f)
datasets=[]
datasets=[]
metadata={}
metadata={}
forkeyindata_keys:
forkeyindata_keys:
...
@@ -169,8 +170,8 @@ class DataLoader:
...
@@ -169,8 +170,8 @@ class DataLoader:
Raises:
Raises:
ValueError: If the 'contains' argument is not specified.
ValueError: If the 'contains' argument is not specified.
ValueError: If the 'contains' argument matches multiple TIFF stacks in the directory
ValueError: If the 'contains' argument matches multiple TIFF stacks in the directory
"""
"""
ifnotself.contains:
ifnotself.contains:
raiseValueError(
raiseValueError(
"Please specify a part of the name that is common for the TIFF file stack with the argument 'contains'"
"Please specify a part of the name that is common for the TIFF file stack with the argument 'contains'"
...
@@ -191,7 +192,7 @@ class DataLoader:
...
@@ -191,7 +192,7 @@ class DataLoader:
raiseValueError(f"The provided part of the filename for the TIFF stack matches multiple TIFF stacks: {unique_names}.\nPlease provide a string that is unique for the TIFF stack that is intended to be loaded")
raiseValueError(f"The provided part of the filename for the TIFF stack matches multiple TIFF stacks: {unique_names}.\nPlease provide a string that is unique for the TIFF stack that is intended to be loaded")
"""Load a TXRM/XRM/TXM file from the specified path.
Args:
path (str): The path to the HDF5 file.
Returns:
numpy.ndarray or tuple: The loaded volume as a NumPy array.
If 'return_metadata' is True, returns a tuple (volume, metadata).
Raises:
ValueError: If the dxchange library is not installed
"""
try:
importdxchange
exceptImportError:
raiseValueError('The library dxchange is required to load TXRM files. Please find installation instructions at https://dxchange.readthedocs.io/en/latest/source/install.html')
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)
log.info("Using %s of memory",sizeof(sys.getsizeof(vol)))
ifself.virtual_stack:
raiseNotImplementedError("Using virtual stack for TXRM files is not implemented yet")