gammapy/estimators/excess_map.py
def estimate_excess_map(self, dataset):
        """Estimate excess and ts maps for single dataset.

        If exposure is defined, a flux map is also computed.

        Parameters
        ----------
        dataset : `MapDataset`
            Map dataset
        """

        pixel_size = np.mean(np.abs(dataset.counts.geom.wcs.wcs.cdelt))
        size = self.correlation_radius.deg / pixel_size
        kernel = Tophat2DKernel(size)

        geom = dataset.counts.geom

        if self.apply_mask_fit:
            mask = dataset.mask
        elif dataset.mask_safe:
            mask = dataset.mask_safe
        else:
            mask = np.ones(dataset.data_shape, dtype=bool)

        counts_stat = convolved_map_dataset_counts_statistics(dataset, kernel, mask, self.correlate_off)

        n_on = Map.from_geom(geom, data=counts_stat.n_on)
        bkg = Map.from_geom(geom, data=counts_stat.n_on - counts_stat.n_sig)
        excess = Map.from_geom(geom, data=counts_stat.n_sig)

        result = {"counts": n_on, "background": bkg, "excess": excess}

        tsmap = Map.from_geom(geom, data=counts_stat.ts)
        sqrt_ts = Map.from_geom(geom, data=counts_stat.sqrt_ts)
        result.update({"ts": tsmap, "sqrt_ts": sqrt_ts})

        err = Map.from_geom(geom, data=counts_stat.error * self.n_sigma)
        result.update({"err": err})

        if dataset.exposure:
            reco_exposure = estimate_exposure_reco_energy(dataset)
            with np.errstate(invalid="ignore", divide="ignore"):
                flux = excess / reco_exposure
            flux.quantity = flux.quantity.to("1 / (cm2 s)")
        else:
            flux = Map.from_geom(
                geom=dataset.counts.geom, data=np.nan * np.ones(dataset.data_shape)
            )
        result.update({"flux": flux})

        if "errn-errp" in self.selection_optional:
            errn = Map.from_geom(geom, data=counts_stat.compute_errn(self.n_sigma))
            errp = Map.from_geom(geom, data=counts_stat.compute_errp(self.n_sigma))
            result.update({"errn": errn, "errp": errp})

        if "ul" in self.selection_optional:
            ul = Map.from_geom(
                geom, data=counts_stat.compute_upper_limit(self.n_sigma_ul)
            )
            result.update({"ul": ul})

        # return nan values outside mask
        for key in result:
            result[key].data[~mask] = np.nan

        return result
Estimate excess and ts maps for single dataset.

        If exposure is defined, a flux map is also computed.

        Parameters
        ----------
        dataset : `MapDataset`
            Map dataset
        
Estimate excess and ts maps for single dataset.
If exposure is defined, a flux map is also computed.

Parameters

dataset : `MapDataset`
Map dataset
Estimate excess and ts maps for single dataset . If exposure is defined a flux map is also computed . Parameters dataset : ` MapDataset ` Map dataset
def estimate_excess_map(self, dataset):
        pixel_size = np.mean(np.abs(dataset.counts.geom.wcs.wcs.cdelt))
        size = self.correlation_radius.deg / pixel_size
        kernel = Tophat2DKernel(size)
        geom = dataset.counts.geom
        if self.apply_mask_fit:
            mask = dataset.mask
        elif dataset.mask_safe:
            mask = dataset.mask_safe
        else:
            mask = np.ones(dataset.data_shape, dtype=bool)
        counts_stat = convolved_map_dataset_counts_statistics(dataset, kernel, mask, self.correlate_off)
        n_on = Map.from_geom(geom, data=counts_stat.n_on)
        bkg = Map.from_geom(geom, data=counts_stat.n_on - counts_stat.n_sig)
        excess = Map.from_geom(geom, data=counts_stat.n_sig)
        result = {"counts": n_on, "background": bkg, "excess": excess}
        tsmap = Map.from_geom(geom, data=counts_stat.ts)
        sqrt_ts = Map.from_geom(geom, data=counts_stat.sqrt_ts)
        result.update({"ts": tsmap, "sqrt_ts": sqrt_ts})
        err = Map.from_geom(geom, data=counts_stat.error * self.n_sigma)
        result.update({"err": err})
        if dataset.exposure:
            reco_exposure = estimate_exposure_reco_energy(dataset)
            with np.errstate(invalid="ignore", divide="ignore"):
                flux = excess / reco_exposure
            flux.quantity = flux.quantity.to("1 / (cm2 s)")
        else:
            flux = Map.from_geom(
                geom=dataset.counts.geom, data=np.nan * np.ones(dataset.data_shape)
            )
        result.update({"flux": flux})
        if "errn-errp" in self.selection_optional:
            errn = Map.from_geom(geom, data=counts_stat.compute_errn(self.n_sigma))
            errp = Map.from_geom(geom, data=counts_stat.compute_errp(self.n_sigma))
            result.update({"errn": errn, "errp": errp})
        if "ul" in self.selection_optional:
            ul = Map.from_geom(
                geom, data=counts_stat.compute_upper_limit(self.n_sigma_ul)
            )
            result.update({"ul": ul})
        for key in result:
            result[key].data[~mask] = np.nan
        return result
def estimate_excess_map ( self , dataset ) : pixel_size = np . mean ( np . abs ( dataset . counts . geom . wcs . wcs . cdelt ) ) size = self . correlation_radius . deg / pixel_size kernel = Tophat2DKernel ( size ) geom = dataset . counts . geom if self . apply_mask_fit : mask = dataset . mask elif dataset . mask_safe : mask = dataset . mask_safe else : mask = np . ones ( dataset . data_shape , dtype = bool ) counts_stat = convolved_map_dataset_counts_statistics ( dataset , kernel , mask , self . correlate_off ) n_on = Map . from_geom ( geom , data = counts_stat . n_on ) bkg = Map . from_geom ( geom , data = counts_stat . n_on - counts_stat . n_sig ) excess = Map . from_geom ( geom , data = counts_stat . n_sig ) result = { "counts" : n_on , "background" : bkg , "excess" : excess } tsmap = Map . from_geom ( geom , data = counts_stat . ts ) sqrt_ts = Map . from_geom ( geom , data = counts_stat . sqrt_ts ) result . update ( { "ts" : tsmap , "sqrt_ts" : sqrt_ts } ) err = Map . from_geom ( geom , data = counts_stat . error * self . n_sigma ) result . update ( { "err" : err } ) if dataset . exposure : reco_exposure = estimate_exposure_reco_energy ( dataset ) with np . errstate ( invalid = "ignore" , divide = "ignore" ) : flux = excess / reco_exposure flux . quantity = flux . quantity . to ( "1 / (cm2 s)" ) else : flux = Map . from_geom ( geom = dataset . counts . geom , data = np . nan * np . ones ( dataset . data_shape ) ) result . update ( { "flux" : flux } ) if "errn-errp" in self . selection_optional : errn = Map . from_geom ( geom , data = counts_stat . compute_errn ( self . n_sigma ) ) errp = Map . from_geom ( geom , data = counts_stat . compute_errp ( self . n_sigma ) ) result . update ( { "errn" : errn , "errp" : errp } ) if "ul" in self . selection_optional : ul = Map . from_geom ( geom , data = counts_stat . compute_upper_limit ( self . n_sigma_ul ) ) result . update ( { "ul" : ul } ) for key in result : result [ key ] . data [ ~ mask ] = np . nan return result
Estimate excess and ts maps for single dataset.
Estimate excess and ts maps for single dataset .
"""Estimate excess and ts maps for single dataset.

        If exposure is defined, a flux map is also computed.

        Parameters
        ----------
        dataset : `MapDataset`
            Map dataset
        """ # return nan values outside mask
self
dataset