nabu.io.reader module¶
- class nabu.io.reader.Reader(sub_region=None)[source]¶
Bases:
object
Abstract class for various file readers.
- Parameters:
sub_region (tuple, optional) – Coordinates in the form (start_x, end_x, start_y, end_y), to read a subset of each frame. It can be used for Regions of Interest (ROI). Indices start at zero !
- class nabu.io.reader.NPReader(sub_region=None, mmap=True)[source]¶
Bases:
Reader
Reader for NPY/NPZ files. Mostly used for internal development. Please refer to the documentation of nabu.io.reader.Reader
- multi_load = True¶
- class nabu.io.reader.EDFReader(sub_region=None)[source]¶
Bases:
Reader
A class for reading series of EDF Files. Multi-frames EDF are not supported.
- multi_load = False¶
- class nabu.io.reader.HDF5Reader(sub_region=None)[source]¶
Bases:
Reader
A class for reading a HDF5 File.
- multi_load = True¶
- class nabu.io.reader.HDF5Loader(fname, data_path, sub_region=None, data_buffer=None, pre_allocate=True, dtype='f')[source]¶
Bases:
object
An alternative class to HDF5Reader where information is first passed at class instantiation
- class nabu.io.reader.VolReaderBase(*args, **kwargs)[source]¶
Bases:
object
Base class with common code for data readers (EDFStackReader, NXTomoReader, etc)
- class nabu.io.reader.NXTomoReader(filename, data_path='{entry}/instrument/detector/data', sub_region=None, image_key=0, output_dtype=<class 'numpy.float32'>, processing_func=None, processing_func_args=None, processing_func_kwargs=None)[source]¶
Bases:
VolReaderBase
Read a HDF5 file in NXTomo layout.
- Parameters:
filename (str) – Path to the file to read.
data_path (str) – Path within the HDF5 file, eg. “entry/instrument/detector/data”. Default is {entry}/data/data where {entry} is a magic keyword for the first entry.
sub_region (slice or tuple, optional) – Region to select within the data, once the “image key” selection has been done. If None, all the data (corresponding to image_key) is selected. If slice(start, stop) is provided, the selection is done along dimension 0. Otherwise, it must be a 3-tuple of slices in the form (slice(start_angle, end_angle, step_angle), slice(start_z, end_z, step_z), slice(start_x, end_x, step_x)) Each of the parameters can be None, in this case the default start and end are taken in each dimension.
output_dtype (numpy.dtype, optional) – Output data type if the data memory is allocated by this class. Default is float32.
image_key (int, or None, optional) – Image type to read (see NXTomo documentation). 0 for projections, 1 for flat-field, 2 for dark field. If set to None, all the data will be read.
processing_func (callable, optional) – Function to be called on each loaded stack of images. If provided, this function first argument must be the source buffer (3D array: stack of raw images), and the second argument must be the destination buffer (3D array, stack of output images). It can be None.
None. (The other parameters are passed to "processing_func" if this parameter is not) –
- image_key_path = 'instrument/detector/image_key_control'¶
- multiple_frames_per_file = True¶
- load_data(output=None, convert_after_reading=True)[source]¶
Read data.
- Parameters:
output (array-like, optional) – Destination 3D array that will hold the data. If provided, use this memory buffer instead of allocating the memory. Its shape must be compatible with the selection of ‘sub_region’ and ‘image_key’.
conver_after_reading (bool, optional) – Whether to do the dtype conversion (if any, eg. uint16 to float32) after data reading. With using h5py’s read_direct(), reading from uint16 to float32 is extremely slow, so data type conversion should be done after reading. The drawback is that it requires more memory.
- class nabu.io.reader.EDFStackReader(filenames, sub_region=None, output_dtype=<class 'numpy.float32'>, n_reading_threads=1, processing_func=None, processing_func_args=None, processing_func_kwargs=None)[source]¶
Bases:
VolReaderBase
- multiple_frames_per_file = False¶
- nabu.io.reader.load_images_stack_from_hdf5(fname, h5_data_path, sub_region=None)[source]¶
Load a 3D dataset from a HDF5 file.
- Parameters:
fname (str) – File path
h5_data_path (str) – Data path within the HDF5 file
sub_region (tuple, optional) – Tuple indicating which sub-volume to load, in the form (xmin, xmax, ymin, ymax, zmin, zmax) where the 3D dataset has the python shape (N_Z, N_Y, N_X). This means that the data will be loaded as data[zmin:zmax, ymin:ymax, xmin:xmax].
- nabu.io.reader.import_h5_to_dict(h5file, h5path, asarray=False)[source]¶
Wrapper on top of silx.io.dictdump.dicttoh5 replacing “None” with None
- Parameters:
h5file (str) – File name
h5path (str) – Path in the HDF5 file
asarray (bool, optional) – Whether to convert each numeric value to an 0D array. Default is False.