CXIStore#
- class pyrost.CXIStore(names, mode='r', protocol=CXIProtocol(datatypes={'basis_vectors': 'float', 'data': 'uint', 'defocus_x': 'float', 'defocus_y': 'float', 'distance': 'float', 'mask': 'bool', 'phase': 'float', 'pixel_aberrations': 'float', 'pixel_translations': 'float', 'reference_image': 'float', 'scale_map': 'float', 'translations': 'float', 'wavelength': 'float', 'whitefield': 'float', 'whitefields': 'float', 'x_pixel_size': 'float', 'y_pixel_size': 'float'}, load_paths={'basis_vectors': ['/speckle_tracking/basis_vectors', '/entry_1/instrument_1/detector_1/basis_vectors', '/entry/instrument/detector/basis_vectors'], 'data': ['/entry/data/data', '/entry/instrument/detector/data', '/entry_1/instrument_1/detector_1/data', '/entry_1/data_1/data'], 'defocus_x': ['/speckle_tracking/defocus_x', '/speckle_tracking/defocus_fs', '/speckle_tracking/defocus'], 'defocus_y': ['/speckle_tracking/defocus_y', '/speckle_tracking/defocus_ss'], 'distance': ['/entry/instrument/detector/distance', '/entry_1/instrument_1/detector_1/distance'], 'mask': ['/speckle_tracking/mask', '/mask_maker/mask', '/entry_1/instrument_1/detector_1/mask', '/entry/instrument/detector/mask'], 'phase': ['/speckle_tracking/phase'], 'pixel_aberrations': ['/speckle_tracking/pixel_aberrations'], 'pixel_translations': ['/speckle_tracking/pixel_translations'], 'reference_image': ['/speckle_tracking/reference_image'], 'scale_map': ['/speckle_tracking/scale_map'], 'translations': ['/speckle_tracking/translations', '/entry_1/sample_1/geometry/translations', '/entry/sample/geometry/translations', '/entry_1/sample_1/geometry/translation', '/pos_refine/translation', '/entry_1/sample_3/geometry/translation'], 'wavelength': ['/entry/instrument/source/wavelength', '/entry_1/instrument_1/source_1/wavelength', 'entry/instrument/beam/incident_wavelength'], 'whitefield': ['/speckle_tracking/whitefield', '/process_1/whitefield', '/make_whitefield/whitefield', '/process_2/whitefield', '/process_3/whitefield'], 'whitefields': ['/speckle_tracking/whitefields', '/speckle_tracking/flatfields'], 'x_pixel_size': ['/entry/instrument/detector/x_pixel_size', '/entry_1/instrument_1/detector_1/x_pixel_size'], 'y_pixel_size': ['/entry/instrument/detector/y_pixel_size', '/entry_1/instrument_1/detector_1/y_pixel_size']}, kinds={'basis_vectors': 'sequence', 'data': 'stack', 'defocus_x': 'scalar', 'defocus_y': 'scalar', 'distance': 'scalar', 'mask': 'stack', 'phase': 'frame', 'pixel_aberrations': 'frame', 'pixel_translations': 'sequence', 'reference_image': 'scalar', 'scale_map': 'frame', 'translations': 'sequence', 'wavelength': 'scalar', 'whitefield': 'frame', 'whitefields': 'stack', 'x_pixel_size': 'scalar', 'y_pixel_size': 'scalar'}))#
File handler class for HDF5 and CXI files. Provides an interface to save and load data attributes to a file. Support multiple files. The handler saves data to the first file.
- Parameters
- file_dict#
Dictionary of paths to the files and their file objects.
- protocol#
pyrost.CXIProtocol
protocol object.
- mode#
File mode. Valid modes are:
‘r’ : Readonly, file must exist (default).
‘r+’ : Read/write, file must exist.
‘w’ : Create file, truncate if exists.
‘w-’ or ‘x’ : Create file, fail if exists.
‘a’ : Read/write if exists, create otherwise.
- filenames()#
Return a list of paths to the files.
- files()#
Return a list of file objects of the files.
- Return type
List
[File
]- Returns
List of file objects of the files.
- find_dataset(attr)#
Return the path to the attribute from the first file. Return the default path if the attribute is not found inside the first file.
- indices()#
Return a list of frame indices of the data contained in the files.
- Return type
- Returns
A list of frame indices of the data in the files.
- items()#
Return a set of
(name, index)
pairs.name
is the attribute’s name contained in the files, andindex
it’s corresponding set of indices.- Return type
- Returns
A set of
(name, index)
pairs of the data attributes in the files.
- keys()#
Return a set of the attribute’s names contained in the files.
- Return type
- Returns
A set of the attribute’s names in the files.
- load_attribute(attr, idxs=None, processes=1, ss_idxs=slice(None, None, None), fs_idxs=slice(None, None, None), verbose=True)#
Load a data attribute from the files.
- Parameters
attr (
str
) – Attribute’s name to load.idxs (
Union
[int
,slice
,ndarray
,List
[int
],Tuple
[int
],None
]) – A list of frames’ indices to load.processes (
int
) – Number of parallel workers used during the loading.ss_idxs (
Union
[int
,slice
,ndarray
,List
[int
],Tuple
[int
]]) – Slow (vertical) axis indices used to load the data attributes of frame and stack types.fs_idxs (
Union
[int
,slice
,ndarray
,List
[int
],Tuple
[int
]]) – Fast (horizontal) axis indices used to lead the data attributes of frame and stack types.verbose (
bool
) – Set the verbosity of the loading process.
- Raises
ValueError – If the attribute’s kind is invalid.
RuntimeError – If the files are not opened.
- Return type
- Returns
Attribute’s data array.
- read_shape()#
Read the input files and return a shape of the frame type data attribute.
- Raises
RuntimeError – If the files are not opened.
- Return type
- Returns
The shape of the 2D frame-like data attribute.
- save_attribute(attr, data, mode='overwrite', idxs=None)#
Save a data array pertained to the data attribute into the first file.
- Parameters
attr (
str
) – Attribute’s name.data (
ndarray
) – Data array.mode (
str
) –Writing mode:
append : Append the data array to already existing dataset.
insert : Insert the data under the given indices
idxs
.overwrite : Overwrite the existing dataset.
idxs (
Union
[int
,slice
,ndarray
,List
[int
],Tuple
[int
],None
]) – Indices where the data is saved. Used only ifmode
is set to ‘insert’.
- Raises
ValueError – If the attribute’s kind is invalid.
ValueError – If the file is opened in read-only mode.
RuntimeError – If the file is not opened.
- Return type
- update_indices()#
Read the files for the data attributes contained in the protocol.
- Return type
- values()#
Return a set of the attribute’s indices in the files.
- Return type
- Returns
A set of the attribute’s indices in the files.