No interpolation of events az/zd/ra/dec gives error in astropy
When running hillas_preprocessing_MAGICCleaning_stereo.py
from https://gitlab.mpcdf.mpg.de/ievo/magic-cta-pipe (as of commit 8005e0914eb0910d2014cdc212ffe925b0e79861) repository on a run of OFF data (run 05085314 from 20190925, source AT2019pqh), I get the error:
Traceback (most recent call last):
File "hillas_preprocessing_MAGICCleaning_stereo.py", line 493, in <module>
output_name=config['data_files'][data_type][sample][telescope_type]['hillas_output'])
File "hillas_preprocessing_MAGICCleaning_stereo.py", line 321, in process_dataset_data
frame=horizon_frame,
File "/storage/gpfs_data/ctalocal/aberti/miniconda3/envs/magic-lst/lib/python3.7/site-packages/astropy/coordinates/sky_coordinate.py", line 315, in __init__
frame_cls(**frame_kwargs), args, kwargs)
File "/storage/gpfs_data/ctalocal/aberti/miniconda3/envs/magic-lst/lib/python3.7/site-packages/astropy/coordinates/sky_coordinate_parsers.py", line 245, in _parse_coordinate_data
valid_components.update(_get_representation_attrs(frame, units, kwargs))
File "/storage/gpfs_data/ctalocal/aberti/miniconda3/envs/magic-lst/lib/python3.7/site-packages/astropy/coordinates/sky_coordinate_parsers.py", line 592, in _get_representation_attrs
valid_kwargs[frame_attr_name] = repr_attr_class(value, unit=unit)
File "/storage/gpfs_data/ctalocal/aberti/miniconda3/envs/magic-lst/lib/python3.7/site-packages/astropy/coordinates/angles.py", line 536, in __new__
self._validate_angles()
File "/storage/gpfs_data/ctalocal/aberti/miniconda3/envs/magic-lst/lib/python3.7/site-packages/astropy/coordinates/angles.py", line 558, in _validate_angles
'got {}'.format(angles.to(u.degree)))
ValueError: Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got 91.0 deg
The error is thrown for an event for which event.pointing.array_altitude
is set to 91 deg. Checking the zenith values of the events in that run, they are all around 40-45deg, so the value must come from somewhere else. Indeed, I could trace the strange value of altitude to ctapipe_io_magic, in particular to the portion of code where interpolation of zd/az/ra/dec is performed. Examining the code, the interpolation of the events zd/az/ra/dec is performed subrun-wise starting from the drive reports. In the case there are 2 or less drive reports in a subrun, zd/az/ra/dec are set to -1 for all events in that subrun (and there is no warning about that). The altitude is then calculated as 90-zd
, which results in a value of 91deg for zd=-1, that is the value retrieved in the magic-cta-pipe
script.
Indeed, in one of the subruns for M1, there is only 1 drive report, therefore interpolation is not performed.