From e4f8edd0b901373a76b9a4174fc30f6736a7369e Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Sat, 14 Nov 2026 13:01:35 +0100 Subject: [PATCH 1/3] fix mask order when reading from file --- .../adr/0001-pixel-mask-file-format.md | 7 ++- packages/essreduce/src/ess/reduce/masking.py | 54 ++++++++++++------- packages/essreduce/tests/masking_test.py | 54 ++++++++++++++----- 3 files changed, 78 insertions(+), 37 deletions(-) diff --git a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md index a2ae02ee7..50c80e4c9 100644 --- a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md +++ b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md @@ -46,9 +46,8 @@ with h5py.File(path) as f: - Names of `NXdetector` groups are the names of the groups in the NeXus files of the runs. A name that is not a bank of the instrument is an error, since a misspelled name would otherwise mask nothing. - The name of a dataset in `masks` is the name of the mask in the reduced data. - Datasets with the same name in several banks form one mask. - The data of each bank gets a mask of that name, made from the dataset of that bank. - A bank without a dataset of that name has no pixels masked by it. + Masks are associated with their detector group; a detector without a dataset does + not get that mask. - A pixel is masked if its value is not zero. HDF5 has no boolean type. h5py stores numpy booleans as an enumeration based on `int8`, which other HDF5 libraries may not read as booleans. @@ -65,7 +64,7 @@ with h5py.File(path) as f: `write_pixel_masks` writes all three, and workflows do not read them. Workflows take a list of filenames and use the masks of all files. -Two files with a mask of the same name are an error. +Two files with a mask of the same name for the same detector are an error. A file can hold all masks of an instrument, or masks can be split into files, for example by validity period: one file for broken tubes and one for the beamstop of an experiment. Workflows do not check validity dates. Selecting the files that are valid for a run is left to the caller of the workflow, which sets the list of filenames. diff --git a/packages/essreduce/src/ess/reduce/masking.py b/packages/essreduce/src/ess/reduce/masking.py index 05eb0fcaf..b862aea58 100644 --- a/packages/essreduce/src/ess/reduce/masking.py +++ b/packages/essreduce/src/ess/reduce/masking.py @@ -22,11 +22,12 @@ """Files with pixel masks to apply. Use an empty sequence to apply none.""" PixelMasks = NewType('PixelMasks', dict[str, sc.Variable | sc.DataGroup]) -"""Pixel masks of the whole instrument, by mask name. +"""Pixel masks of the whole instrument. -Each value is either a variable of masked detector IDs, or a data group of boolean masks -by detector. :py:func:`read_pixel_masks` provides them from files, and they can also be -set directly. :py:func:`to_detector_masks` selects the masks for one detector. +Each value is either a variable of masked detector IDs, named by the mask, or a data +group of boolean masks, named by detector and then mask. :py:func:`read_pixel_masks` +provides them from files, and they can also be set directly. +:py:func:`to_detector_masks` selects the masks for one detector. """ _HDF5_SUFFIXES = ('.h5', '.hdf', '.hdf5', '.nxs') @@ -55,10 +56,8 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: beamstop integer array Detector names are the names of the NeXus detector groups, and mask names are - the names of the datasets. Datasets with the same name in several detectors form - one mask. The data of each detector gets a mask of that name, made from the - dataset of that detector. A detector without a dataset of that name has no - pixels masked by it. A pixel is masked if its value is not zero. The dimensions + the names of the datasets. The data of each detector gets the masks in its + ``masks`` collection. A pixel is masked if its value is not zero. The dimensions of a dataset are given by HDF5 dimension labels. They are named after the logical dimensions of the detector, and may be a subset of them, in any order. Other entries of the file, such as the instrument name or a validity date, are @@ -75,15 +74,26 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: Raises ------ ValueError - If a file has an unsupported suffix or content, or two files give the same mask - name. One mask would replace the other otherwise. + If a file has an unsupported suffix or content, or two files define the same + mask for a detector. One mask would replace the other otherwise. """ masks = {} for filename in map(Path, filenames): for name, content in _read_mask_file(filename).items(): - if name in masks: + if name not in masks: + masks[name] = content + elif isinstance(content, sc.DataGroup) and isinstance( + previous := masks[name], sc.DataGroup + ): + duplicates = set(previous) & set(content) + if duplicates: + raise ValueError( + f"Several mask files give detector masks {sorted(duplicates)} " + f"for detector '{name}'." + ) + masks[name] = sc.DataGroup({**dict(previous), **dict(content)}) + else: raise ValueError(f"Several mask files give the mask name '{name}'.") - masks[name] = content return PixelMasks(masks) @@ -126,12 +136,15 @@ def to_detector_masks( if isinstance(content, sc.Variable): masks[name] = _mask_from_ids(content, detector.coords[id_coord], name) continue + if known_banks is not None and name not in known_banks: + raise ValueError(f"Masks have unknown banks: {[name]}.") if bank is None: - raise ValueError(f"Mask '{name}' is given per bank, but no bank is known.") - if known_banks is not None and (unknown := set(content) - set(known_banks)): - raise ValueError(f"Mask '{name}' has unknown banks: {sorted(unknown)}.") - if bank in content: - masks[name] = _align_bank_mask(content[bank], detector.sizes, name) + raise ValueError("Masks are given per bank, but no bank is known.") + if name == bank: + for mask_name, mask in content.items(): + if mask_name in masks: + raise ValueError(f"Several masks have the name '{mask_name}'.") + masks[mask_name] = _align_bank_mask(mask, detector.sizes, mask_name) return masks @@ -248,11 +261,14 @@ def _read_nexus_masks(entry: snx.Group, filename: Path) -> dict[str, sc.DataGrou for detector_name, detector in entry['instrument'][snx.NXdetector].items(): if 'masks' not in detector: continue + detector_masks = {} for name, field in detector['masks'].items(): - masks.setdefault(name, {})[detector_name] = _read_bank_mask(field, filename) + detector_masks[name] = _read_bank_mask(field, filename) + if detector_masks: + masks[detector_name] = sc.DataGroup(detector_masks) if not masks: raise ValueError(f"Mask file '{filename}' has no detector with masks.") - return {name: sc.DataGroup(banks) for name, banks in masks.items()} + return masks def _read_bank_mask(field: snx.Field | snx.Group, filename: Path) -> sc.Variable: diff --git a/packages/essreduce/tests/masking_test.py b/packages/essreduce/tests/masking_test.py index c9bf055b4..aa1dea5b2 100644 --- a/packages/essreduce/tests/masking_test.py +++ b/packages/essreduce/tests/masking_test.py @@ -93,7 +93,7 @@ def test_read_raises_if_hdf5_does_not_hold_integers(tmp_path: Path) -> None: _read(path) -def test_read_bank_masks_names_masks_after_datasets(tmp_path: Path) -> None: +def test_read_bank_masks_by_detector_and_mask_name(tmp_path: Path) -> None: broken = sc.array(dims=['tube'], values=[True, False]) beamstop = sc.array(dims=['straw'], values=[False, True, True]) write_pixel_masks( @@ -102,8 +102,7 @@ def test_read_bank_masks_names_masks_after_datasets(tmp_path: Path) -> None: instrument='TEST', ) masks = _read(tmp_path / 'a.nxs') - assert sc.identical(masks['broken'], sc.DataGroup(bank_0=broken)) - assert sc.identical(masks['beamstop'], sc.DataGroup(bank_0=beamstop)) + assert sc.identical(masks['bank_0'], sc.DataGroup(broken=broken, beamstop=beamstop)) def test_write_uses_detector_name_and_mask_name(tmp_path: Path) -> None: @@ -115,7 +114,7 @@ def test_write_uses_detector_name_and_mask_name(tmp_path: Path) -> None: assert file['entry/instrument/loki_detector_0/masks/bad_tubes'][ () ].tolist() == [1] - assert sc.identical(_read(path)['bad_tubes'], sc.DataGroup(loki_detector_0=mask)) + assert sc.identical(_read(path)['loki_detector_0'], sc.DataGroup(bad_tubes=mask)) def test_read_bank_masks_keeps_dimensions_of_all_banks(tmp_path: Path) -> None: @@ -128,7 +127,9 @@ def test_read_bank_masks_keeps_dimensions_of_all_banks(tmp_path: Path) -> None: {bank: {'m': mask} for bank, mask in banks.items()}, instrument='TEST', ) - assert sc.identical(_read(tmp_path / 'a.nxs')['m'], sc.DataGroup(banks)) + loaded = _read(tmp_path / 'a.nxs') + assert sc.identical(loaded['bank_0'], sc.DataGroup(m=banks['bank_0'])) + assert sc.identical(loaded['bank_1'], sc.DataGroup(m=banks['bank_1'])) def test_read_bank_masks_omits_banks_without_dataset_of_mask(tmp_path: Path) -> None: @@ -139,8 +140,8 @@ def test_read_bank_masks_omits_banks_without_dataset_of_mask(tmp_path: Path) -> instrument='TEST', ) masks = _read(tmp_path / 'a.nxs') - assert list(masks['broken']) == ['bank_0'] - assert list(masks['beamstop']) == ['bank_1'] + assert list(masks['bank_0']) == ['broken'] + assert list(masks['bank_1']) == ['beamstop'] def test_read_ignores_other_entries_of_the_file(tmp_path: Path) -> None: @@ -153,7 +154,7 @@ def test_read_ignores_other_entries_of_the_file(tmp_path: Path) -> None: with snx.File(path, 'r+') as file: file['entry'].create_field('valid_from', '2026-11-01T00:00:00Z') file['entry/instrument/bank_0'].create_field('pixel_mask', np.array([1])) - assert list(_read(path)) == ['m'] + assert list(_read(path)) == ['bank_0'] def test_read_skips_detector_without_masks(tmp_path: Path) -> None: @@ -165,7 +166,7 @@ def test_read_skips_detector_without_masks(tmp_path: Path) -> None: ) with snx.File(path, 'r+') as file: file['entry/instrument'].create_class('bank_1', snx.NXdetector) - assert list(_read(path)['m']) == ['bank_0'] + assert list(_read(path)['bank_0']) == ['m'] def test_read_combines_masks_of_several_files(tmp_path: Path) -> None: @@ -177,21 +178,46 @@ def test_read_combines_masks_of_several_files(tmp_path: Path) -> None: tmp_path / 'b.nxs', {'bank_0': {'beamstop': mask}}, instrument='TEST' ) masks = _read(tmp_path / 'a.nxs', tmp_path / 'b.nxs') - assert list(masks) == ['broken', 'beamstop'] + assert list(masks['bank_0']) == ['broken', 'beamstop'] -def test_read_raises_if_files_have_mask_with_same_name(tmp_path: Path) -> None: +def test_read_raises_if_files_have_mask_for_same_detector_and_name( + tmp_path: Path, +) -> None: mask = sc.array(dims=['tube'], values=[True]) write_pixel_masks( tmp_path / 'a.nxs', {'bank_0': {'broken': mask}}, instrument='TEST' ) write_pixel_masks( - tmp_path / 'b.nxs', {'bank_1': {'broken': mask}}, instrument='TEST' + tmp_path / 'b.nxs', {'bank_0': {'broken': mask}}, instrument='TEST' ) with pytest.raises(ValueError, match='broken'): _read(tmp_path / 'a.nxs', tmp_path / 'b.nxs') +def test_read_round_trips_masks_by_detector(tmp_path: Path) -> None: + masks = { + f'loki_detector_{i}': { + 'bad_tubes': sc.array( + dims=['layer', 'tube'], + values=np.arange(4 * 32).reshape(4, 32) % 9 == i, + ), + 'bad_straws': sc.array( + dims=['layer', 'tube', 'straw'], + values=np.arange(4 * 32 * 7).reshape(4, 32, 7) % 9 == i, + ), + } + for i in range(9) + } + path = tmp_path / 'masks.hdf' + write_pixel_masks(path, masks, instrument='LOKI') + + loaded = _read(path) + assert list(loaded) == list(masks) + for detector, detector_masks in masks.items(): + assert sc.identical(loaded[detector], sc.DataGroup(detector_masks)) + + def test_write_stores_masks_as_uint8(tmp_path: Path) -> None: path = tmp_path / 'a.nxs' write_pixel_masks( @@ -220,7 +246,7 @@ def test_read_masks_pixels_with_nonzero_value(tmp_path: Path, dtype: str) -> Non values = np.array([0, 1, 1], dtype=dtype) if dtype != 'bool': values[2] = 2 - loaded = _read(_write_raw_mask(tmp_path / 'a.nxs', values))['m']['bank_0'] + loaded = _read(_write_raw_mask(tmp_path / 'a.nxs', values))['bank_0']['m'] assert loaded.dims == ('tube',) assert loaded.values.tolist() == [False, True, True] @@ -305,7 +331,7 @@ def bank() -> sc.DataArray: def _per_bank(**banks: sc.Variable) -> PixelMasks: - return PixelMasks({'m': sc.DataGroup(banks)}) + return PixelMasks({bank: sc.DataGroup(m=mask) for bank, mask in banks.items()}) def test_to_detector_masks_selects_bank_and_allows_fewer_dims( From 871d74d2d69c14bf8d153fe9de6f273b820ed548 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Sat, 14 Nov 2026 13:13:21 +0100 Subject: [PATCH 2/3] protect against masks with same names but different shapes in different NXdetectors --- .../adr/0001-pixel-mask-file-format.md | 1 + packages/essreduce/src/ess/reduce/masking.py | 30 ++++++++++++++++++- packages/essreduce/tests/masking_test.py | 19 ++++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md index 50c80e4c9..0ad657d64 100644 --- a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md +++ b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md @@ -55,6 +55,7 @@ with h5py.File(path) as f: Readers accept any integer type, and the boolean enumeration that h5py writes for numpy booleans. - Dimensions of a mask are named with HDF5 dimension labels. They are a subset of the logical dimensions of the bank, in any order, with matching sizes. + Masks with the same name in different banks use the same dimension labels, though their sizes may differ. Each mask has its own dimensions, so a tube mask and a straw mask need not be combined into one array. The sizes are checked when masks are applied, because scipp ignores a mask with a dimension that the data lacks, without an error. - A file with several `NXentry` groups is an error, since the reader would use only one of them and leave pixels unmasked. diff --git a/packages/essreduce/src/ess/reduce/masking.py b/packages/essreduce/src/ess/reduce/masking.py index b862aea58..d6d4bff98 100644 --- a/packages/essreduce/src/ess/reduce/masking.py +++ b/packages/essreduce/src/ess/reduce/masking.py @@ -60,6 +60,8 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: ``masks`` collection. A pixel is masked if its value is not zero. The dimensions of a dataset are given by HDF5 dimension labels. They are named after the logical dimensions of the detector, and may be a subset of them, in any order. + Masks with the same name in different detectors must have the same dimension + labels, but their sizes may differ. Other entries of the file, such as the instrument name or a validity date, are ignored. - A file written by :py:func:`scipp.io.save_hdf5` with a variable of masked @@ -75,12 +77,15 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: ------ ValueError If a file has an unsupported suffix or content, or two files define the same - mask for a detector. One mask would replace the other otherwise. + mask for a detector, or same-named masks in different detectors have different + dimension labels. One mask would replace the other otherwise. """ masks = {} for filename in map(Path, filenames): for name, content in _read_mask_file(filename).items(): if name not in masks: + if isinstance(content, sc.DataGroup): + _validate_mask_dimension_labels(name, content, masks) masks[name] = content elif isinstance(content, sc.DataGroup) and isinstance( previous := masks[name], sc.DataGroup @@ -91,6 +96,7 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: f"Several mask files give detector masks {sorted(duplicates)} " f"for detector '{name}'." ) + _validate_mask_dimension_labels(name, content, masks) masks[name] = sc.DataGroup({**dict(previous), **dict(content)}) else: raise ValueError(f"Several mask files give the mask name '{name}'.") @@ -271,6 +277,28 @@ def _read_nexus_masks(entry: snx.Group, filename: Path) -> dict[str, sc.DataGrou return masks +def _validate_mask_dimension_labels( + detector_name: str, + detector_masks: sc.DataGroup, + masks: Mapping[str, sc.Variable | sc.DataGroup], +) -> None: + for mask_name, mask in detector_masks.items(): + for other_detector, other_masks in masks.items(): + if other_detector == detector_name or not isinstance( + other_masks, sc.DataGroup + ): + continue + if mask_name not in other_masks: + continue + other_mask = other_masks[mask_name] + if set(mask.dims) != set(other_mask.dims): + raise ValueError( + f"Mask '{mask_name}' has different dimension labels in detectors " + f"'{other_detector}' ({sorted(other_mask.dims)}) and " + f"'{detector_name}' ({sorted(mask.dims)})." + ) + + def _read_bank_mask(field: snx.Field | snx.Group, filename: Path) -> sc.Variable: if not isinstance(field, snx.Field): raise ValueError(f"Mask file '{filename}' has a group '{field.name}' in masks.") diff --git a/packages/essreduce/tests/masking_test.py b/packages/essreduce/tests/masking_test.py index aa1dea5b2..88b9fd697 100644 --- a/packages/essreduce/tests/masking_test.py +++ b/packages/essreduce/tests/masking_test.py @@ -117,10 +117,12 @@ def test_write_uses_detector_name_and_mask_name(tmp_path: Path) -> None: assert sc.identical(_read(path)['loki_detector_0'], sc.DataGroup(bad_tubes=mask)) -def test_read_bank_masks_keeps_dimensions_of_all_banks(tmp_path: Path) -> None: +def test_read_same_named_masks_can_have_different_shapes_and_order( + tmp_path: Path, +) -> None: banks = { 'bank_0': sc.array(dims=['layer', 'tube'], values=[[True, False]]), - 'bank_1': sc.array(dims=['straw'], values=[False, True, False]), + 'bank_1': sc.array(dims=['tube', 'layer'], values=[[True], [False]]), } write_pixel_masks( tmp_path / 'a.nxs', @@ -132,6 +134,19 @@ def test_read_bank_masks_keeps_dimensions_of_all_banks(tmp_path: Path) -> None: assert sc.identical(loaded['bank_1'], sc.DataGroup(m=banks['bank_1'])) +def test_read_raises_if_same_named_masks_have_different_dimension_labels( + tmp_path: Path, +) -> None: + masks = { + 'bank_0': {'m': sc.array(dims=['tube'], values=[True, False])}, + 'bank_1': {'m': sc.array(dims=['straw'], values=[True, False])}, + } + write_pixel_masks(tmp_path / 'a.nxs', masks, instrument='TEST') + + with pytest.raises(ValueError, match='different dimension labels'): + _read(tmp_path / 'a.nxs') + + def test_read_bank_masks_omits_banks_without_dataset_of_mask(tmp_path: Path) -> None: mask = sc.array(dims=['tube'], values=[True]) write_pixel_masks( From fa9ca3c741ce435305315190f493f370f75ac7da Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Thu, 19 Nov 2026 14:32:25 +0100 Subject: [PATCH 3/3] relax condition on masks with same names for different detector banks --- .../adr/0001-pixel-mask-file-format.md | 1 - packages/essreduce/src/ess/reduce/masking.py | 27 ------------------- packages/essreduce/tests/masking_test.py | 13 --------- 3 files changed, 41 deletions(-) diff --git a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md index 0ad657d64..50c80e4c9 100644 --- a/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md +++ b/packages/essreduce/docs/developer/adr/0001-pixel-mask-file-format.md @@ -55,7 +55,6 @@ with h5py.File(path) as f: Readers accept any integer type, and the boolean enumeration that h5py writes for numpy booleans. - Dimensions of a mask are named with HDF5 dimension labels. They are a subset of the logical dimensions of the bank, in any order, with matching sizes. - Masks with the same name in different banks use the same dimension labels, though their sizes may differ. Each mask has its own dimensions, so a tube mask and a straw mask need not be combined into one array. The sizes are checked when masks are applied, because scipp ignores a mask with a dimension that the data lacks, without an error. - A file with several `NXentry` groups is an error, since the reader would use only one of them and leave pixels unmasked. diff --git a/packages/essreduce/src/ess/reduce/masking.py b/packages/essreduce/src/ess/reduce/masking.py index d6d4bff98..a0e804d99 100644 --- a/packages/essreduce/src/ess/reduce/masking.py +++ b/packages/essreduce/src/ess/reduce/masking.py @@ -60,8 +60,6 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: ``masks`` collection. A pixel is masked if its value is not zero. The dimensions of a dataset are given by HDF5 dimension labels. They are named after the logical dimensions of the detector, and may be a subset of them, in any order. - Masks with the same name in different detectors must have the same dimension - labels, but their sizes may differ. Other entries of the file, such as the instrument name or a validity date, are ignored. - A file written by :py:func:`scipp.io.save_hdf5` with a variable of masked @@ -84,8 +82,6 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: for filename in map(Path, filenames): for name, content in _read_mask_file(filename).items(): if name not in masks: - if isinstance(content, sc.DataGroup): - _validate_mask_dimension_labels(name, content, masks) masks[name] = content elif isinstance(content, sc.DataGroup) and isinstance( previous := masks[name], sc.DataGroup @@ -96,7 +92,6 @@ def read_pixel_masks(filenames: PixelMaskFilenames) -> PixelMasks: f"Several mask files give detector masks {sorted(duplicates)} " f"for detector '{name}'." ) - _validate_mask_dimension_labels(name, content, masks) masks[name] = sc.DataGroup({**dict(previous), **dict(content)}) else: raise ValueError(f"Several mask files give the mask name '{name}'.") @@ -277,28 +272,6 @@ def _read_nexus_masks(entry: snx.Group, filename: Path) -> dict[str, sc.DataGrou return masks -def _validate_mask_dimension_labels( - detector_name: str, - detector_masks: sc.DataGroup, - masks: Mapping[str, sc.Variable | sc.DataGroup], -) -> None: - for mask_name, mask in detector_masks.items(): - for other_detector, other_masks in masks.items(): - if other_detector == detector_name or not isinstance( - other_masks, sc.DataGroup - ): - continue - if mask_name not in other_masks: - continue - other_mask = other_masks[mask_name] - if set(mask.dims) != set(other_mask.dims): - raise ValueError( - f"Mask '{mask_name}' has different dimension labels in detectors " - f"'{other_detector}' ({sorted(other_mask.dims)}) and " - f"'{detector_name}' ({sorted(mask.dims)})." - ) - - def _read_bank_mask(field: snx.Field | snx.Group, filename: Path) -> sc.Variable: if not isinstance(field, snx.Field): raise ValueError(f"Mask file '{filename}' has a group '{field.name}' in masks.") diff --git a/packages/essreduce/tests/masking_test.py b/packages/essreduce/tests/masking_test.py index 88b9fd697..bb74d918f 100644 --- a/packages/essreduce/tests/masking_test.py +++ b/packages/essreduce/tests/masking_test.py @@ -134,19 +134,6 @@ def test_read_same_named_masks_can_have_different_shapes_and_order( assert sc.identical(loaded['bank_1'], sc.DataGroup(m=banks['bank_1'])) -def test_read_raises_if_same_named_masks_have_different_dimension_labels( - tmp_path: Path, -) -> None: - masks = { - 'bank_0': {'m': sc.array(dims=['tube'], values=[True, False])}, - 'bank_1': {'m': sc.array(dims=['straw'], values=[True, False])}, - } - write_pixel_masks(tmp_path / 'a.nxs', masks, instrument='TEST') - - with pytest.raises(ValueError, match='different dimension labels'): - _read(tmp_path / 'a.nxs') - - def test_read_bank_masks_omits_banks_without_dataset_of_mask(tmp_path: Path) -> None: mask = sc.array(dims=['tube'], values=[True]) write_pixel_masks(