From 8bda932bea92de8929c45d7405c3149d1a76c9d7 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 17 Dec 2024 11:14:35 +0000 Subject: [PATCH 1/2] Allow getting values without timestamps for RUN data --- extra_data/sourcedata.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extra_data/sourcedata.py b/extra_data/sourcedata.py index 215a2142..68a38855 100644 --- a/extra_data/sourcedata.py +++ b/extra_data/sourcedata.py @@ -439,7 +439,7 @@ def run_value(self, key, *, allow_multi_run=False): return val.decode('utf-8', 'surrogateescape') return val - def run_values(self): + def run_values(self, inc_timestamps=True): """Get a dict of all RUN values for this source This includes keys which are also in CONTROL. @@ -461,6 +461,8 @@ def visitor(path, obj): # Arbitrary file - should be the same across a run self.files[0].file['RUN'][self.source].visititems(visitor) + if not inc_timestamps: + return {k[:-6]: v for (k, v) in res.items() if k.endswith('.value')} return res @property From 5c2e52cb874db2489e80f3c366a2770b00de0cc6 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 17 Dec 2024 11:21:06 +0000 Subject: [PATCH 2/2] Test run_values() method --- extra_data/tests/test_sourcedata.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extra_data/tests/test_sourcedata.py b/extra_data/tests/test_sourcedata.py index 1969f6a3..63a1cfeb 100644 --- a/extra_data/tests/test_sourcedata.py +++ b/extra_data/tests/test_sourcedata.py @@ -164,6 +164,14 @@ def test_run_value(mock_spb_raw_run): value = xgm.run_value('pulseEnergy.conversion.value') assert isinstance(value, np.float64) + run_dict = xgm.run_values() + assert 'pulseEnergy.conversion.value' in run_dict + assert 'pulseEnergy.conversion.timestamp' in run_dict + + values_dict = xgm.run_values(inc_timestamps=False) + assert 'pulseEnergy.conversion' in values_dict + assert 'pulseEnergy.conversion.timestamp' not in values_dict + with pytest.raises(ValueError): # no run values for instrument sources am0.run_values()