CXIStore#

class cbclib.CXIStore(names, mode='r', protocol=CXIProtocol(datatypes={'background': 'float', 'cor_data': 'float', 'data': 'uint', 'frames': 'uint', 'mask': 'bool', 'streak_data': 'float', 'tilts': 'float', 'translations': 'float', 'wavelength': 'float', 'whitefield': 'float', 'x_pixel_size': 'float', 'y_pixel_size': 'float'}, load_paths={'background': ['/entry/crystallography/background'], 'cor_data': ['/entry/data/cor_data'], 'data': ['/entry/data/data', '/entry_1/data/data', '/entry_1/data_1/data', '/data/data', '/entry_1/instrument_1/detector_1/data'], 'frames': ['/entry/crystallography/frames', '/frame_selector/frames', '/process_3/frames'], 'mask': ['/entry/instrument/detector/mask', '/entry_1/instrument_1/detector_1/mask', '/entry_1/instrument/detector/mask'], 'tilts': ['/entry/crystallography/tilts'], 'translations': ['/entry/crystallography/translations'], 'streak_data': ['/entry/crystallography/streak_data'], 'wavelength': ['/entry/instrument/beam/wavelength', '/entry/instrument/beam/incident_wavelength', '/entry_1/instrument_1/beam/wavelength'], 'whitefield': ['/entry/crystallography/whitefield'], 'x_pixel_size': ['/entry/instrument/detector/x_pixel_size'], 'y_pixel_size': ['/entry/instrument/detector/y_pixel_size']}, kinds={'background': 'stack', 'cor_data': 'stack', 'data': 'stack', 'frames': 'sequence', 'mask': 'stack', 'streak_data': 'stack', 'tilts': 'sequence', 'translations': 'sequence', 'wavelength': 'scalar', 'whitefield': 'frame', 'x_pixel_size': 'scalar', 'y_pixel_size': 'scalar'}))[source]#

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#

cbclib.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()[source]#

Close the files.

Return type

None

filenames()[source]#

Return a list of paths to the files.

Return type

List[str]

Returns

List of paths to the files.

files()[source]#

Return a list of file objects of the files.

Return type

List[File]

Returns

List of file objects of the files.

find_dataset(attr)[source]#

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()[source]#

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()[source]#

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()[source]#

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)[source]#

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.

  • verbose (bool) – Set the verbosity of the loading process.

Raises
Return type

ndarray

Returns

Attribute’s data array.

open()[source]#

Open the files.

Return type

None

read_shape()[source]#

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)[source]#

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()[source]#

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

Return type

None

values()[source]#

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.