Skip to content

Commit 86303ce

Browse files
committed
Fix labelled data counts not covering all selected train IDs
1 parent ff368ed commit 86303ce

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

extra_data/keydata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ def data_counts(self, labelled=True):
398398

399399
if labelled:
400400
import pandas as pd
401-
return pd.Series(counts, index=train_ids)
401+
res = pd.Series(0, index=self.train_ids)
402+
res.loc[train_ids] = counts
403+
return res
402404
else:
403405
all_tids_arr = np.array(self.train_ids)
404406
res = np.zeros(len(all_tids_arr), dtype=np.uint64)

extra_data/tests/test_keydata.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_get_train_keep_dims(mock_jungfrau_run):
170170
assert val.shape == (1, 16, 512, 1024)
171171

172172

173-
def test_data_counts(mock_reduced_spb_proc_run):
173+
def test_data_counts(mock_reduced_spb_proc_run, mock_jungfrau_run):
174174
run = RunDirectory(mock_reduced_spb_proc_run)
175175

176176
# control data
@@ -189,6 +189,14 @@ def test_data_counts(mock_reduced_spb_proc_run):
189189
assert count.index.tolist() == mod.train_ids
190190
assert count.values.sum() == mod.shape[0]
191191

192+
# Combine data with more train IDs than our original sources, and
193+
# ensure that the data counts now cover these additional train IDs
194+
# as well with 0.
195+
multi_run = run.union(RunDirectory(mock_jungfrau_run))
196+
mod = multi_run['SPB_DET_AGIPD1M-1/DET/0CH0:xtdf', 'image.data']
197+
count = mod.data_counts()
198+
assert count.index.tolist() == mod.train_ids
199+
192200

193201
def test_data_counts_empty(mock_fxe_raw_run):
194202
run = RunDirectory(mock_fxe_raw_run)
@@ -230,8 +238,8 @@ def test_data_counts_missing_train(fxe_run_module_offset):
230238
lpd_m8 = run['FXE_DET_LPD1M-1/DET/8CH0:xtdf', 'image.cellId']
231239

232240
ser = lpd_m8.data_counts(labelled=True)
233-
assert len(ser) == 480
234-
np.testing.assert_array_equal(ser.index, run.train_ids[1:])
241+
assert len(ser) == 481
242+
np.testing.assert_array_equal(ser.index, run.train_ids)
235243

236244
arr = lpd_m8.data_counts(labelled=False)
237245
assert len(arr) == 481

0 commit comments

Comments
 (0)