Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve energies of triggered events from dl1 parameters #188

Merged
merged 7 commits into from
Jul 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions ctaplot/gammaboard/gammaboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ipywidgets import HBox, Tab, Output, VBox, FloatSlider, Layout, Button, Dropdown, Text, Label
from sklearn.metrics import roc_auc_score, precision_recall_curve
from sklearn.multiclass import LabelBinarizer
from astropy.table import Table
from astropy.table import Table, vstack
import astropy.units as u
from tqdm.auto import tqdm
from .. import plots
Expand Down Expand Up @@ -80,20 +80,23 @@ def load_trig_events(experiment, experiments_directory):
result_files = find_data_files(experiment, experiments_directory)
trig_energies = []
for file in result_files:
try:
result_file = tables.open_file(file)
except Exception as e:
print('Could not open data file {}'.format(file))
print(e)
else:
if guess_particle_type_from_file(file) == GAMMA_ID:
try:
if guess_particle_type_from_file(file) == GAMMA_ID:
result_file.close()
trig_energies.append(pd.read_hdf(file, key='triggered_events'))
except:
print("Cannot load the number of triggered events for experiment {} file".format(experiment))
return None
energies = Table.from_pandas(pd.concat(trig_energies))
dl1_params = Table.read(file, path='dl1/event/telescope/parameters/LST_LSTCam')
for obs_id in np.unique(dl1_params['obs_id']):
mask = dl1_params['obs_id'] == obs_id
dl1_filtered = dl1_params[mask]
_, indices = np.unique(dl1_filtered['event_id'],
return_index=True)
trig_energies.append(dl1_filtered['mc_energy'][indices])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to our discussion, this can be simplified using axis

mask = np.unique(dl1_params[['obs_id', 'event_id']], axis=0, return_index=True)
trig_energies = dl1_params['mc_energy'][mask]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

except OSError:
try:
trig_energies.append(Table.from_pandas(pd.read_hdf(file, key='triggered_events')))
except KeyError as e:
print("Cannot load the number of triggered events for experiment {} file".format(experiment))
return None
energies = vstack(trig_energies)
energies.rename_column('mc_energy', 'mc_trig_energies')
energies['mc_trig_energies'] *= u.TeV
return energies

Expand Down