Skip to content

Commit

Permalink
More assertions -> ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jan 17, 2022
1 parent 2a58b0b commit 348115f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lstchain/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,10 @@ def check_mcheader(mcheader1, mcheader2):
-------
"""
assert mcheader1.keys() == mcheader2.keys()
if mcheader1.keys() != mcheader2.keys():
different = set(mcheader1.keys()).symmetric_difference(mcheader2.keys())
raise ValueError(f'MC header keys do not match, differing keys: {different}')

# It does not matter that the number of simulated showers is the same
keys = list(mcheader1.keys())
"""keys that don't need to be checked: """
Expand Down Expand Up @@ -792,7 +795,13 @@ def check_thrown_events_histogram(thrown_events_hist1, thrown_events_hist2):
thrown_events_hist1: `lstchain.io.lstcontainers.ThrownEventsHistogram`
thrown_events_hist2: `lstchain.io.lstcontainers.ThrownEventsHistogram`
"""
assert thrown_events_hist1.keys() == thrown_events_hist2.keys()
keys1 = set(thrown_events_hist1.keys())
keys2 = set(thrown_events_hist2.keys())
if keys1 != keys2:
different = keys1.symmetric_difference(keys2)
raise ValueError(f'Histogram keys do not match, differing keys: {different}')


# It does not matter that the number of simulated showers is the same
keys = ["bins_energy", "bins_core_dist"]
for k in keys:
Expand Down Expand Up @@ -848,7 +857,12 @@ def check_metadata(metadata1, metadata2):
metadata1: `lstchain.io.MetaData`
metadata2: `lstchain.io.MetaData`
"""
assert metadata1.keys() == metadata2.keys()
keys1 = set(metadata1.keys())
keys2 = set(metadata2.keys())
if keys1 != keys2:
different = keys1.symmetric_difference(keys2)
raise ValueError(f'Metadata keys do not match, differing keys: {different}')

keys = ["LSTCHAIN_VERSION"]
for k in keys:
v1 = metadata1[k]
Expand Down

0 comments on commit 348115f

Please sign in to comment.