Skip to content

Commit b48c82b

Browse files
committed
Add SourceData.run_keys()
1 parent 1eb2cc3 commit b48c82b

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

extra_data/sourcedata.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,29 @@ def run_value(self, key, *, allow_multi_run=False):
493493
return val.decode('utf-8', 'surrogateescape')
494494
return val
495495

496+
def run_keys(self, inc_timestamps=True):
497+
"""Get a set of RUN keys for this source.
498+
499+
Unlike :meth:`keys`, RUN keys are not affected by selection.
500+
"""
501+
502+
if not self.is_single_run:
503+
raise MultiRunError()
504+
505+
if self.source not in self.files[0].file['RUN']:
506+
raise ValueError('{self.source} has no RUN values')
507+
508+
res = set()
509+
def visitor(path, obj):
510+
if isinstance(obj, h5py.Dataset):
511+
res.add(path.replace('/', '.'))
512+
513+
# Arbitrary file - should be the same across a run
514+
self.files[0].file['RUN'][self.source].visititems(visitor)
515+
if not inc_timestamps:
516+
return {k[:-6] for k in res if k.endswith('.value')}
517+
return res
518+
496519
def run_values(self, inc_timestamps=True):
497520
"""Get a dict of all RUN values for this source
498521

extra_data/tests/test_sourcedata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def test_run_value(mock_spb_raw_run):
186186
assert 'pulseEnergy.conversion' in values_dict
187187
assert 'pulseEnergy.conversion.timestamp' not in values_dict
188188

189+
assert xgm.run_keys() == xgm.keys() | {'classId.timestamp', 'classId.value'}
190+
assert xgm.run_keys(False) == xgm.keys(False) | {'classId'}
191+
189192
with pytest.raises(ValueError):
190193
# no run values for AGIPD instrument data.
191194
am0.run_values()

0 commit comments

Comments
 (0)