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
  • names (Union[str, List[str]]) – Paths to the files.

  • mode (str) – Mode in which to open file; one of (‘w’, ‘r’, ‘r+’, ‘a’, ‘w-‘).

  • protocol (CXIProtocol) – CXI protocol. Uses the default protocol if not provided.

file_dict#

Dictionary of paths to the files and their file objects.

file#

h5py.File object of the first file.

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.

close()#

Close the files.

Return type

None

filenames()#

Return a list of paths to the files.

Return type

List[str]

Returns

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.

Parameters

attr (str) – Attribute’s name.

Return type

str

Returns

Path to the attribute inside the first file.

indices()#

Return a list of frame indices of the data contained in the files.

Return type

ndarray

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, and index it’s corresponding set of indices.

Return type

ItemsView

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

KeysView

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
Raises
Return type

ndarray

Returns

Attribute’s data array.

open()#

Open the files.

Return type

None

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

Tuple[int, int]

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 if mode is set to ‘insert’.

Raises
Return type

None

update_indices()#

Read the files for the data attributes contained in the protocol.

Return type

None

values()#

Return a set of the attribute’s indices in the files.

Return type

ValuesView

Returns

A set of the attribute’s indices in the files.