Skip to content

Commit

Permalink
Add method to read the shower distributions to table loader
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jul 14, 2022
1 parent 96d76b0 commit 2e60e91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ctapipe/io/tableloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TRUE_PARAMETERS_GROUP = "/simulation/event/telescope/parameters"
TRUE_IMPACT_GROUP = "/simulation/event/telescope/impact"
SIMULATION_CONFIG_TABLE = "/configuration/simulation/run"
SHOWER_DISTRIBUTION_TABLE = "/simulation/service/shower_distribution"

DL2_SUBARRAY_GROUP = "/dl2/event/subarray"
DL2_TELESCOPE_GROUP = "/dl2/event/telescope"
Expand Down Expand Up @@ -306,6 +307,12 @@ def read_simulation_configuration(self):
"""
return read_table(self.h5file, SIMULATION_CONFIG_TABLE)

def read_shower_distribution(self):
"""
Read the simulated shower distribution histograms
"""
return read_table(self.h5file, SHOWER_DISTRIBUTION_TABLE)

def read_subarray_events(self, start=None, stop=None, keep_order=True):
"""Read subarray-based event information.
Expand Down
11 changes: 11 additions & 0 deletions ctapipe/io/tests/test_table_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,14 @@ def test_read_simulation_config(dl2_merged_file):
assert len(runs) == 2
assert np.all(runs["obs_id"] == [4, 1])
assert u.allclose(runs["energy_range_min"].quantity, [0.004, 0.003] * u.TeV)


def test_read_shower_distributions(dl2_merged_file):
from ctapipe.io import TableLoader

with TableLoader(dl2_merged_file) as table_loader:
histograms = table_loader.read_shower_distribution()
assert len(histograms) == 2
assert np.all(histograms["obs_id"] == [4, 1])
assert np.all(histograms["num_entries"] == [2000, 1000])
assert np.all(histograms["histogram"].sum(axis=(1, 2)) == [2000, 1000])

0 comments on commit 2e60e91

Please sign in to comment.