diffractem.nexus module

diffractem.nexus.copy_h5(fn_from, fn_to, exclude=('%/detector/data', '/%/data/%', '/%/results/%'), mode='w-', print_skipped=False, h5_folder=None, h5_suffix='.h5')[source]

Copies datasets h5/nxs files or lists of them to new ones, with exclusion of datasets. :param fn_from: single h5/nxs file or list file :param fn_to: new file name, or new list file. If the latter, specify with h5_folder and h5_suffix how the new names

are supposed to be constructed

Parameters
  • exclude – patterns for data sets to be excluded. All regular expressions are allowed, % is mapped to .* (i.e., any string of any length), for compatibility with CrystFEL

  • mode – mode in which new files are opened. By default w-, i.e., files are created, but never overwritten

  • print_skipped – print the skipped data sets, for debugging

  • h5_folder – if operating on a list: folder where new h5 files should go

  • h5_suffix – if operating on a list: suffix appended to old files (after stripping their extension)

Returns

diffractem.nexus.get_meta_fields(files, dataset_paths, shorten_labels=True)[source]

Get arbitrary meta data from files. :type files: Union[str, list] :param files: :type dataset_paths: Union[list, str, tuple, dict] :param dataset_paths: list of dataset paths, or dict of structure {dataset: default value} :param shorten_labels: only use final section of labels for columns of returned DataFrame :return: pandas DataFrame of metadata

diffractem.nexus.get_table(files, path='/%/shots', parallel=True)[source]
Return type

DataFrame

diffractem.nexus.meta_to_nxs(filename, meta=None, exclude=('Detector',), meta_grp='/entry/instrument', data_grp='/entry/data', data_field='raw_counts', data_location='/entry/instrument/detector/data')[source]

Merges a dict containing metadata information for a serial data acquisition into an existing detector nxs file. Additionally, it adds a soft link to the actual data for easier retrieval later (typically into /entry/data) :param filename: NeXus file or lists :param meta: can be set to {} -> no meta action performed. Or a JSON file name. If None, a JSON file name will be

derived from nxs_file by replacing .nxs by .json (useful in loops)

Parameters
  • exclude – names of meta groups or fields to exclude

  • meta_grp – location in the NeXus, where the metadata should go to

  • data_grp – location of softlink to the data stack. No softlink action if None.

  • data_field – name of the softlink to the data stack

  • data_location – location of the data stack

Returns

diffractem.nexus.store_table(table, path, parallel=True, format='nexus', file=None, subset=None)[source]

Stores a pandas DataFrame containing ‘file’ and ‘subset’ columns to multiple HDF5 files. Essentially a multi-file, multi-processed wrapper to pd.to_hdf :type table: DataFrame :param table: DataFrame to be stored :type path: str :param path: path in HDF5 files. % will be substituted by the respective subset name :type parallel: bool :param parallel: if True (default), writes files in parallel :type format: str :param format: can be ‘nexus’ to write columns of table in separate arrays, or ‘tables’ to use PyTables to write

a HDF5 table object.

Returns

list of futures (see documentation of concurrent.futures). [None] if parallel=False