ess.masking.save_detector_masks#

ess.masking.save_detector_masks(filename, detectors, *, entry_metadata=None)#

Save detector masks to an HDF5/NeXus file.

The masks will be saved inside an NXentry/NXinstrument group of the file. An NXdetector group will be created for each detector.

Parameters
  • filename (Union[str, Path]) – Name of the file to save to.

  • detectors (Mapping[str, DataArray]) – Dictionary of data arrays whose masks should be saved.

  • entry_metadata (Optional[Mapping[str, Union[str, int]]], default: None) – Optional dictionary of metadata to save in the NXentry group. Typically this should contain ‘experiment_identifier’, ‘start_time’, and ‘end_time’.

Examples

Consider a data group with two detectors, one with a mask and one without, as well as some metadata:

>>> import scipp as sc
>>>
>>> dg = sc.DataGroup()
>>> dg['mantle_detector'] = sc.DataArray(
...     data=sc.ones(dims=['tube', 'pixel'], shape=[3, 100]),
...     masks={'bad_tube': sc.array(dims=['tube'], values=[False, True, False])},
... )
>>> dg['endcap_detector'] = sc.DataArray(
...     data=sc.ones(dims=['x', 'y'], shape=[2, 2]), masks={}
... )
>>> metadata = {'experiment_identifier': 12345}

Save the masks to a file:

>>> from ess.masking import save_detector_masks
>>>
>>> save_detector_masks('masks.h5', dg, entry_metadata=metadata)

Use ScippNexus to load the resulting file:

>>> import scippnexus as snx
>>>
>>> with snx.File('masks.h5') as f:
>>>     masks = f['entry'][()]
Return type

None