Skip to content

Commit 2f3bc23

Browse files
committed
Remove interleave patches (keep order non compatible), add tel_index to merge get_balanced_patches
1 parent deed98c commit 2f3bc23

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

dl1_data_handler/reader.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _construct_mono_example_identifiers(self):
557557
example_identifiers.append(events)
558558
# Constrcut the example identifiers for all files
559559
self.example_identifiers = vstack(example_identifiers)
560-
self.example_identifiers.sort(["obs_id", "event_id", "tel_id", "tel_type_id"])
560+
561561

562562
# For the RawTriggerReader to have the required number of rows for each option
563563
# If balanced patches selected append the patches index and cherenkov p.e. to each event
@@ -586,6 +586,7 @@ def _construct_mono_example_identifiers(self):
586586
self.example_identifiers.add_column(patch_indices, name="patch_index", index=6)
587587
self.example_identifiers.add_column(nsb_cosmic, name="patch_class", index=7)
588588

589+
self.example_identifiers.sort(["obs_id", "event_id", "tel_id", "tel_type_id"])
589590
# Construct simulation information for all files
590591
if self.process_type == ProcessType.Simulation:
591592
self.simulation_info = vstack(simulation_info)
@@ -1727,11 +1728,6 @@ class DLRawTriggerReader(DLWaveformReader):
17271728
),
17281729
).tag(config=True)
17291730

1730-
interleave_patches = Bool(
1731-
default_value=True,
1732-
help="Get alternate nsb and cosmic patches in the batch output. Only for ``balanced_patches`` output setting.",
1733-
).tag(config=True)
1734-
17351731
hot_pixel_from_simulation = Bool(
17361732
default_value=True,
17371733
help="Get the hot pixel index from the simulation (more Cherenkov p.e.) or the pixel with highest integrated signal",
@@ -1787,6 +1783,7 @@ def _get_balanced_patches(self, batch):
17871783
cherenkov = []
17881784
table_index = []
17891785
file_index = []
1786+
tel_index = []
17901787
nsb_cosmic = []
17911788
# Compute trigger patches and its characteristics
17921789
self.trigger_settings = get_trigger_patches(
@@ -1832,32 +1829,28 @@ def _get_balanced_patches(self, batch):
18321829
if comparator >0:
18331830
temp_index_nsb = np.random.choice(nsb_patches, size=comparator, replace=False)
18341831
temp_index_cosmic = np.random.choice(cosmic_patches, size=comparator, replace=False)
1835-
if self.interleave_patches:
1836-
temp_index = np.empty(temp_index_cosmic.size + temp_index_nsb.size, dtype=temp_index_cosmic.dtype)
1837-
temp_index[0::2] = temp_index_cosmic
1838-
temp_index[1::2] = temp_index_nsb
1839-
temp_nsb_cosmic = np.tile(np.arange(2), comparator)
1840-
else:
1841-
temp_index = np.concatenate((temp_index_cosmic,temp_index_nsb))
1842-
temp_nsb_cosmic = np.concatenate([np.zeros(comparator, dtype=int), np.ones(comparator, dtype=int)])
1832+
temp_index = np.concatenate((temp_index_cosmic,temp_index_nsb))
1833+
temp_nsb_cosmic = np.concatenate([np.zeros(comparator, dtype=int), np.ones(comparator, dtype=int)])
18431834
patches_indexes.extend(temp_index.tolist())
18441835
cherenkov.extend(true_sums[temp_index].tolist())
18451836
nsb_cosmic.extend(temp_nsb_cosmic)
18461837
table_index.extend([table_idx] * 2 * comparator)
18471838
file_index.extend([file_idx] * 2 * comparator)
1839+
tel_index.extend([tel_id] * 2 * comparator)
18481840
# If there is no cosmic or nsb patches append -1
18491841
else:
18501842
patches_indexes.append(-1)
18511843
cherenkov.append(-1)
18521844
nsb_cosmic.append(-1)
18531845
table_index.append(table_idx)
18541846
file_index.append(file_idx)
1847+
tel_index.append(tel_id)
18551848
# Create a table and join with the example table so that the rows are added for a same event
18561849
table_patches = Table(
1857-
[file_index, table_index, patches_indexes, cherenkov, nsb_cosmic],
1858-
names=["file_index", "table_index", "patch_index", "cherenkov_pe", "patch_class"]
1850+
[file_index, table_index, tel_index, patches_indexes, cherenkov, nsb_cosmic],
1851+
names=["file_index", "table_index", "tel_id", "patch_index", "cherenkov_pe", "patch_class"]
18591852
)
1860-
batch = join(left=batch, right=table_patches, keys=["file_index","table_index"], join_type="right", keep_order=True)
1853+
batch = join(left=batch, right=table_patches, keys=["file_index","table_index", "tel_id"], join_type="right")
18611854
column_order = batch.colnames
18621855
new_order = column_order[:6] + ["patch_index", "cherenkov_pe", "patch_class"] + column_order[6:-3]
18631856
batch = batch[new_order]

0 commit comments

Comments
 (0)