def make_map_background_irf_with_symmetry(fpi, symmetry="constant"): axis = MapAxis.from_edges([0.1, 1, 10], name="energy", unit="TeV", interp="log") return make_map_background_irf( pointing=fpi, ontime="42 s", bkg=bkg_3d_custom(symmetry), geom=WcsGeom.create(npix=(3, 3), binsz=4, axes=[axis], skydir=fpi.radec), )
def test_make_map_background_irf(bkg_3d, pars, fixed_pointing_info): m = make_map_background_irf( pointing=fixed_pointing_info, ontime="42 s", bkg=bkg_3d, geom=geom( map_type=pars["map_type"], ebounds=pars["ebounds"], skydir=fixed_pointing_info.radec, ), oversampling=10, ) assert m.data.shape == pars["shape"] assert m.unit == "" assert_allclose(m.data.sum(), pars["sum"], rtol=1e-5)
offset = Angle("2 deg") # In[ ]: exposure = make_map_exposure_true_energy(pointing=pointing.radec, livetime=livetime, aeff=irfs["aeff"], geom=geom) exposure.slice_by_idx({ "energy": 3 }).plot(add_cbar=True) # In[ ]: background = make_map_background_irf(pointing=pointing, ontime=livetime, bkg=irfs["bkg"], geom=geom) background.slice_by_idx({ "energy": 3 }).plot(add_cbar=True) # In[ ]: psf = irfs["psf"].to_energy_dependent_table_psf(theta=offset) psf_kernel = PSFKernel.from_table_psf(psf, geom, max_radius=0.3 * u.deg) psf_kernel.psf_kernel_map.sum_over_axes().plot(stretch="log") # In[ ]: energy = axis.edges edisp = irfs["edisp"].to_energy_dispersion(offset,
def simulate_dataset( skymodel, geom, pointing, irfs, livetime=1 * u.h, offset=0 * u.deg, max_radius=0.8 * u.deg, random_state="random-seed", ): """Simulate a 3D dataset. Simulate a source defined with a sky model for a given pointing, geometry and irfs for a given exposure time. This will return a dataset object which includes the counts cube, the exposure cube, the psf cube, the background model and the sky model. Parameters ---------- skymodel : `~gammapy.modeling.models.SkyModel` Background model map geom : `~gammapy.maps.WcsGeom` Geometry object for the observation pointing : `~astropy.coordinates.SkyCoord` Pointing position irfs : dict Irfs used for simulating the observation livetime : `~astropy.units.Quantity` Livetime exposure of the simulated observation offset : `~astropy.units.Quantity` Offset from the center of the pointing position. This is used for the PSF and Edisp estimation max_radius : `~astropy.coordinates.Angle` The maximum radius of the PSF kernel. random_state: {int, 'random-seed', 'global-rng', `~numpy.random.RandomState`} Defines random number generator initialisation. Returns ------- dataset : `~gammapy.cube.MapDataset` A dataset of the simulated observation. """ background = make_map_background_irf( pointing=pointing, ontime=livetime, bkg=irfs["bkg"], geom=geom ) background_model = BackgroundModel(background) psf = irfs["psf"].to_energy_dependent_table_psf(theta=offset) psf_kernel = PSFKernel.from_table_psf(psf, geom, max_radius=max_radius) exposure = make_map_exposure_true_energy( pointing=pointing, livetime=livetime, aeff=irfs["aeff"], geom=geom ) if "edisp" in irfs: energy = geom.axes[0].edges edisp = irfs["edisp"].to_energy_dispersion(offset, e_reco=energy, e_true=energy) else: edisp = None dataset = MapDataset( model=skymodel, exposure=exposure, background_model=background_model, psf=psf_kernel, edisp=edisp, ) npred_map = dataset.npred() rng = get_random_state(random_state) counts = rng.poisson(npred_map.data) dataset.counts = WcsNDMap(geom, counts) return dataset