# Licensed under a 3-clause BSD style license - see LICENSE.rstimportloggingfromregionsimportCircleSkyRegionfrom.mapimportMapDatasetMaker__all__=["SpectrumDatasetMaker"]log=logging.getLogger(__name__)
[docs]classSpectrumDatasetMaker(MapDatasetMaker):"""Make spectrum for a single IACT observation. The IRFs and background are computed at a single fixed offset, which is recommended only for point-sources. Parameters ---------- selection : list of str, optional Select which maps to make, the available options are: 'counts', 'exposure', 'background', 'edisp'. By default, all maps are made. containment_correction : bool Apply containment correction for point sources and circular on regions. background_oversampling : int Background evaluation oversampling factor in energy. use_region_center : bool If True, approximate the IRFs by the value at the center of the region. If False, the IRFs are averaged over the entire. """tag="SpectrumDatasetMaker"available_selection=["counts","background","exposure","edisp"]def__init__(self,selection=None,containment_correction=False,background_oversampling=None,use_region_center=True,):self.containment_correction=containment_correctionself.use_region_center=use_region_centersuper().__init__(selection=selection,background_oversampling=background_oversampling)
[docs]defmake_exposure(self,geom,observation):"""Make exposure. Parameters ---------- geom : `~gammapy.maps.RegionGeom` Reference map geometry. observation : `~gammapy.data.Observation` Observation to compute effective area for. Returns ------- exposure : `~gammapy.maps.RegionNDMap` Exposure map. """exposure=super().make_exposure(geom,observation,use_region_center=self.use_region_center)is_pointlike=exposure.meta.get("is_pointlike",False)ifis_pointlikeandself.use_region_centerisFalse:log.warning("MapMaker: use_region_center=False should not be used with point-like IRF. ""Results are likely inaccurate.")ifself.containment_correction:ifis_pointlike:raiseValueError("Cannot apply containment correction for point-like IRF.")ifnotisinstance(geom.region,CircleSkyRegion):raiseTypeError("Containment correction only supported for circular regions.")offset=geom.separation(observation.get_pointing_icrs(observation.tmid))containment=observation.psf.containment(rad=geom.region.radius,offset=offset,energy_true=geom.axes["energy_true"].center,)exposure.quantity*=containment.reshape(geom.data_shape)returnexposure
[docs]@staticmethoddefmake_counts(geom,observation):"""Make counts map. If the `~gammapy.maps.RegionGeom` is built from a `~regions.CircleSkyRegion`, the latter will be directly used to extract the counts. If instead the `~gammapy.maps.RegionGeom` is built from a `~regions.PointSkyRegion`, the size of the ON region is taken from the `RAD_MAX_2D` table containing energy-dependent theta2 cuts. Parameters ---------- geom : `~gammapy.maps.Geom` Reference map geometry. observation : `~gammapy.data.Observation` Observation container. Returns ------- counts : `~gammapy.maps.RegionNDMap` Counts map. """returnsuper(SpectrumDatasetMaker,SpectrumDatasetMaker).make_counts(geom,observation)