Skip to content

Commit

Permalink
Raise and catch an exception when no events are found within the maxi…
Browse files Browse the repository at this point in the history
…mum allowed distance. Exit with proper error code.
  • Loading branch information
aleberti committed Nov 2, 2024
1 parent e30630f commit bf87916
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions magicctapipe/scripts/lst1_magic/lst1_magic_stereo_reco.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
get_stereo_events,
save_pandas_data_in_table,
)
from magicctapipe.utils import calculate_impact, calculate_mean_direction
from magicctapipe.utils import (
NO_EVENTS_WITHIN_MAXIMUM_DISTANCE,
calculate_impact,
calculate_mean_direction,
)

__all__ = ["calculate_pointing_separation", "stereo_reconstruction"]

Expand Down Expand Up @@ -207,25 +211,28 @@ def stereo_reconstruction(input_file, output_dir, config, magic_only_analysis=Fa
theta_uplim = u.Quantity(config_stereo["theta_uplim"])
mask = u.Quantity(theta, unit="deg") < theta_uplim

if all(mask):
logger.info(
"--> All the events were taken with smaller angular distances "
f"than the limit {theta_uplim}."
)
try:
if all(mask):
logger.info(
"--> All the events were taken with smaller angular distances "
f"than the limit {theta_uplim}."
)

elif not any(mask):
logger.info(
"--> All the events were taken with larger angular distances "
f"than the limit {theta_uplim}. Exiting..."
)
sys.exit()
elif not any(mask):
raise Exception(
f"--> All the events were taken with larger angular distances "
f"than the limit {theta_uplim}. Exiting..."
)

else:
logger.info(
f"--> Exclude {np.count_nonzero(mask)} stereo events whose "
f"angular distances are larger than the limit {theta_uplim}."
)
event_data = event_data.loc[theta[mask].index]
else:
logger.info(
f"--> Exclude {np.count_nonzero(mask)} stereo events whose "
f"angular distances are larger than the limit {theta_uplim}."
)
event_data = event_data.loc[theta[mask].index]
except Exception as e:
logger.error(f"{e}")
sys.exit(NO_EVENTS_WITHIN_MAXIMUM_DISTANCE)

event_data.set_index("tel_id", append=True, inplace=True)

Expand Down

0 comments on commit bf87916

Please sign in to comment.