Skip to content

Commit 753b9c4

Browse files
committed
Fixes for ADQ & pulse components with no trains of data
1 parent 04f52d2 commit 753b9c4

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/extra/components/adq.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,10 @@ def pulse_data(self, labelled=True, pulse_dim='pulseId', train_roi=(),
11371137
pulse_ids = pulses.pulse_ids(labelled=False)
11381138

11391139
# Prepare output buffer shape.
1140-
out_shape = (len(pulse_ids), pulse_layout['length'].max())
1140+
if len(pulse_ids):
1141+
out_shape = (len(pulse_ids), pulse_layout['length'].max())
1142+
else:
1143+
out_shape = (0, 0)
11411144

11421145
if parallel is not False:
11431146
# Prepare parallelization.

src/extra/components/pulses.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,10 @@ def _get_pulse_ids(self):
11451145

11461146
if not counts:
11471147
# Immediately return an empty series if there is no data.
1148-
return pd.Series([], dtype=np.int32)
1148+
index = pd.MultiIndex.from_arrays([
1149+
np.zeros(0, dtype=np.uint64), np.zeros(0, dtype=np.int64)
1150+
], names=['trainId', 'pulseIndex'])
1151+
return pd.Series([], index=index, dtype=np.int32)
11491152

11501153
index = pd.MultiIndex.from_arrays([
11511154
np.repeat(self._key.train_id_coordinates(), counts),
@@ -1899,13 +1902,19 @@ def _get_pulse_ids(self):
18991902
fel_by_train.append(np.isin(pids, fel_pids))
19001903
ppl_by_train.append(np.isin(pids, ppl_pids))
19011904

1905+
def concat_1d(arrays, dtype): # Allows an empty list of arrays
1906+
if len(arrays) == 0:
1907+
return np.zeros(0, dtype=dtype)
1908+
return np.concatenate(arrays)
1909+
19021910
index = pd.MultiIndex.from_arrays([
19031911
np.repeat(train_ids, counts),
1904-
np.concatenate([np.arange(count) for count in counts]),
1905-
np.concatenate(fel_by_train), np.concatenate(ppl_by_train)
1912+
concat_1d([np.arange(count) for count in counts], np.int64),
1913+
concat_1d(fel_by_train, np.bool_),
1914+
concat_1d(ppl_by_train, np.bool_),
19061915
], names=['trainId', 'pulseIndex', 'fel', 'ppl'])
19071916

1908-
return pd.Series(data=np.concatenate(pids_by_train),
1917+
return pd.Series(data=concat_1d(pids_by_train, np.int32),
19091918
index=index, dtype=np.int32)
19101919

19111920
def _get_pulse_mask(self, reduced=False):

tests/test_components_adq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ def test_pulse_data(mock_sqs_remi_run, parallel):
235235
# Test whether all pulses after the trace are nan.
236236
assert np.isnan(max_by_pulse[21:50]).all()
237237

238+
# No trains in data
239+
empty_data = ch.select_trains(np.s_[:0]).pulse_data()
240+
assert empty_data.dims == ('pulse', 'sample')
241+
assert empty_data.shape[0] == 0
242+
238243
# Use pulse information with not all trains available.
239244
ch = AdqRawChannel(
240245
mock_sqs_remi_run, '3B', digitizer='SQS_DIGITIZER_UTC2',

tests/test_components_pulses.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ def test_pulse_ids(mock_spb_aux_run, source):
364364
# Test unlabelled.
365365
np.testing.assert_equal(pulses.pulse_ids(labelled=False), pids)
366366

367+
# Test with no trains selected
368+
pids_empty = pulses.select_trains(np.s_[:0]).pulse_ids()
369+
assert len(pids_empty) == 0
370+
assert pids_empty.index.names == ['trainId', 'pulseIndex']
371+
367372
# Test deprecated method.
368373
with pytest.warns():
369374
assert pulses.get_pulse_ids().equals(pulses.pulse_ids())
@@ -670,6 +675,11 @@ def test_pump_probe_basic(mock_spb_aux_run, source):
670675
assert not ppl[0]
671676
assert ppl[1:51].all()
672677

678+
# Pulse IDs with no data
679+
pids_empty = pulses.select_trains(np.s_[:0]).pulse_ids()
680+
assert len(pids_empty) == 0
681+
assert pids_empty.index.names == ['trainId', 'pulseIndex', 'fel', 'ppl']
682+
673683
# Pulse mask.
674684
assert pulses.pulse_mask(labelled=False)[0, 1000:1306:6].all()
675685

0 commit comments

Comments
 (0)