# Licensed under a 3-clause BSD style license - see LICENSE.rstimportloggingimportastropy.unitsasufromastropy.tableimportTablefromregionsimportPointSkyRegionfromgammapy.datasetsimportMapDatasetMetaDatafromgammapy.irfimportEDispKernelMap,PSFMap,RecoPSFMapfromgammapy.mapsimportMapfrom.coreimportMakerfrom.utilsimport(make_counts_rad_max,make_edisp_kernel_map,make_edisp_map,make_map_background_irf,make_map_exposure_true_energy,make_psf_map,)__all__=["MapDatasetMaker"]log=logging.getLogger(__name__)
[docs]classMapDatasetMaker(Maker):"""Make binned maps for a single IACT observation. Parameters ---------- selection : list of str, optional Select which maps to make, the available options are: 'counts', 'exposure', 'background', 'psf', 'edisp'. By default, all maps are made. background_oversampling : int Background evaluation oversampling factor in energy. background_interp_missing_data : bool, optional Interpolate missing values in background 3d map. Default is True, have to be set to True for CTA IRF. background_pad_offset : bool, optional Pad one bin in offset for 2d background map. This avoids extrapolation at edges and use the nearest value. Default is True. Examples -------- This example shows how to run the MapMaker for a single observation. >>> from gammapy.data import DataStore >>> from gammapy.datasets import MapDataset >>> from gammapy.maps import WcsGeom, MapAxis >>> from gammapy.makers import MapDatasetMaker >>> # Load an observation >>> data_store = DataStore.from_dir("$GAMMAPY_DATA/hess-dl3-dr1") >>> obs = data_store.obs(23523) >>> # Prepare the geometry >>> energy_axis = MapAxis.from_energy_bounds(1.0, 10.0, 4, unit="TeV") >>> energy_axis_true = MapAxis.from_energy_bounds( 0.5, 20, 10, unit="TeV", name="energy_true") >>> geom = WcsGeom.create( ... skydir=(83.633, 22.014), ... binsz=0.02, ... width=(2, 2), ... frame="icrs", ... proj="CAR", ... axes=[energy_axis], ... ) >>> # Run the maker >>> empty = MapDataset.create(geom=geom, energy_axis_true=energy_axis_true, name="empty") >>> maker = MapDatasetMaker() >>> dataset = maker.run(empty, obs) >>> print(dataset) MapDataset ---------- <BLANKLINE> Name : empty <BLANKLINE> Total counts : 787 Total background counts : 684.52 Total excess counts : 102.48 <BLANKLINE> Predicted counts : 684.52 Predicted background counts : 684.52 Predicted excess counts : nan <BLANKLINE> Exposure min : 7.01e+07 m2 s Exposure max : 1.10e+09 m2 s <BLANKLINE> Number of total bins : 40000 Number of fit bins : 40000 <BLANKLINE> Fit statistic type : cash Fit statistic value (-2 log(L)) : nan <BLANKLINE> Number of models : 0 Number of parameters : 0 Number of free parameters : 0 """tag="MapDatasetMaker"available_selection=["counts","exposure","background","psf","edisp"]def__init__(self,selection=None,background_oversampling=None,background_interp_missing_data=True,background_pad_offset=True,):self.background_oversampling=background_oversamplingself.background_interp_missing_data=background_interp_missing_dataself.background_pad_offset=background_pad_offsetifselectionisNone:selection=self.available_selectionselection=set(selection)ifnotselection.issubset(self.available_selection):difference=selection.difference(self.available_selection)raiseValueError(f"{difference} is not a valid method.")self.selection=selection
[docs]@staticmethoddefmake_exposure(geom,observation,use_region_center=True):"""Make exposure map. Parameters ---------- geom : `~gammapy.maps.Geom` Reference map geometry. observation : `~gammapy.data.Observation` Observation container. use_region_center : bool, optional For geom as a `~gammapy.maps.RegionGeom`. If True, consider the values at the region center. If False, average over the whole region. Default is True. Returns ------- exposure : `~gammapy.maps.Map` Exposure map. """ifisinstance(observation.aeff,Map):returnobservation.aeff.interp_to_geom(geom=geom,)returnmake_map_exposure_true_energy(pointing=observation.get_pointing_icrs(observation.tmid),livetime=observation.observation_live_time_duration,aeff=observation.aeff,geom=geom,use_region_center=use_region_center,)
[docs]@staticmethoddefmake_exposure_irf(geom,observation,use_region_center=True):"""Make exposure map with IRF geometry. Parameters ---------- geom : `~gammapy.maps.Geom` Reference geometry. observation : `~gammapy.data.Observation` Observation container. use_region_center : bool, optional For geom as a `~gammapy.maps.RegionGeom`. If True, consider the values at the region center. If False, average over the whole region. Default is True. Returns ------- exposure : `~gammapy.maps.Map` Exposure map. """returnmake_map_exposure_true_energy(pointing=observation.get_pointing_icrs(observation.tmid),livetime=observation.observation_live_time_duration,aeff=observation.aeff,geom=geom,use_region_center=use_region_center,)