Unsafe SafeMaskMaker
See original GitHub issueGammapy version The dev version
Bug description
The issue happens during the Data Reduction step, without the use of a cutout. When using a large FoV of the final stacked MapDataset
, the processing by the SafeMaskMaker
of an observation with a pointing position far from the center of the final MapDataset
(e.g. >2.5deg for HESS) leads to a python error. The mask_safe
can not be computed (crash in L176 of makers/safe.py
).
If a cutout centered on the pointing position is used to make an empty MapDataset
from the final stacked MapDataset
, the SafeMaskMaker
works correctly.
It seems that there are two issues:
- the handling of the
position
parameter ofSafeMastMaker
: the observation center is not used for a standard treatment of a run (inmake_mask_energy_aeff_max
and also inmake_mask_energy_edisp_bias
) - if no threshold is found in
make_mask_energy_aeff_max
, one should return an empty mask
Expected behavior If an observation is at the very edge of a MapDataset, the worst case should be that an empty mask is return. In all other case, no crash should happen and the mask_safe should be correctly computed.
To Reproduce
import astropy.units as u
from gammapy.maps import Map, MapAxis, WcsGeom
from gammapy.datasets import MapDataset
from gammapy.makers import MapDatasetMaker, SafeMaskMaker
data_store = DataStore.from_dir("$GAMMAPY_DATA/hess-dl3-dr1")
selection = dict(
type="sky_circle",
frame="icrs",
lon="83.633 deg",
lat="22.014 deg",
radius="5 deg",
)
selected_obs_table = data_store.obs_table.select_observations(selection)
observations = data_store.get_observations(selected_obs_table["OBS_ID"])
energy_axis = MapAxis.from_energy_bounds(1.0, 10.0, 4, unit="TeV")
geom = WcsGeom.create(
skydir=(85.633, 22.014),
binsz=0.02,
width=(10, 10),
frame="icrs",
proj="CAR",
axes=[energy_axis],
)
# Reduced IRFs are defined in true energy (i.e. not measured energy).
energy_axis_true = MapAxis.from_energy_bounds(
0.5, 20, 10, unit="TeV", name="energy_true"
)
stacked = MapDataset.create(
geom=geom, energy_axis_true=energy_axis_true, name="crab-stacked"
)
offset_max = 2.5 * u.deg
maker = MapDatasetMaker()
maker_safe_mask = SafeMaskMaker(
methods=["offset-max", "aeff-max"], offset_max=offset_max
)
for obs in observations:
empty = stacked.copy(name=f"obs-{obs.obs_id}")
# A MapDataset is filled in this cutout geometry
dataset = maker.run(empty, obs)
# The data quality cut is applied
dataset = maker_safe_mask.run(dataset, obs)
Other information Any other information you think will be useful for us to fix the issue can go here.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (10 by maintainers)
With the current code, the example returns:
Effective area is all zero at [85d37m58.8s 22d00m50.4s]. No safe energy band can be defined for the dataset 'obs-23592': setting
mask_safeto all False.
So, I think that we are safe now!A second point is the improvement of the documentation about the Data Reduction as mentioned @AtreyeeS . One should use:
empty = stacked.cutout(obs.pointing_radec, width=2 * offset_max, name=f"obs-{obs.obs_id}" )
instead ofempty = stacked.copy(name=f"obs-{obs.obs_id}")
I think that this is well described in this tutorial https://docs.gammapy.org/0.20.1/tutorials/starting/analysis_2.html.So, I propose to close this issue.
Addressed in #3987.