diff --git a/ctaplot/gammaboard/gammaboard.py b/ctaplot/gammaboard/gammaboard.py index 555e344..e897198 100644 --- a/ctaplot/gammaboard/gammaboard.py +++ b/ctaplot/gammaboard/gammaboard.py @@ -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 @@ -83,20 +83,19 @@ 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') + _, indices = np.unique(dl1_params[['obs_id', 'event_id']], axis=0, return_index=True) + trig_energies = dl1_params['mc_energy'][indices] + 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