def make_map_dataset(observations, target_pos, geom, geom_true, offset_max=2 * u.deg): maker = MapMaker(geom, offset_max, geom_true=geom_true) maps = maker.run(observations) table_psf = make_mean_psf(observations, target_pos) # PSF kernel used for the model convolution psf_kernel = PSFKernel.from_table_psf(table_psf, geom_true, max_radius="0.3 deg") edisp = make_mean_edisp( observations, target_pos, e_true=geom_true.axes[0].edges, e_reco=geom.axes[0].edges, ) background_model = BackgroundModel(maps["background"]) background_model.parameters["norm"].frozen = False background_model.parameters["tilt"].frozen = True dataset = MapDataset( counts=maps["counts"], exposure=maps["exposure"], background_model=background_model, psf=psf_kernel, edisp=edisp, ) return dataset
def test_make_mean_psf(data_store): position = SkyCoord(83.63, 22.01, unit="deg") observations = data_store.get_observations([23523, 23526]) psf = make_mean_psf(observations, position=position) assert not np.isnan(psf.psf_value.value).any() assert_allclose(psf.psf_value.value[22, 22], 12206.1665)
# In[ ]: get_ipython().run_cell_magic('time', '', 'maker = MapMaker(geom, offset_max=4.0 * u.deg)\nmaps = maker.run(observations)') # ### Making a PSF Map # # Make a PSF map and weigh it with the exposure at the source position to get a 2D PSF # In[ ]: # mean PSF src_pos = SkyCoord(0, 0, unit="deg", frame="galactic") table_psf = make_mean_psf(observations, src_pos) # PSF kernel used for the model convolution psf_kernel = PSFKernel.from_table_psf(table_psf, geom, max_radius="0.3 deg") # get the exposure at the source position exposure_at_pos = maps["exposure"].get_by_coord( { "lon": src_pos.l.value, "lat": src_pos.b.value, "energy": energy_axis.center, } ) # now compute the 2D PSF psf2D = psf_kernel.make_image(exposures=exposure_at_pos)
maps.keys() # In[ ]: images["counts"].smooth(3).plot(stretch="sqrt", vmax=2) # ## PSF # # Compute the mean PSF for these observations at the Crab position. # In[ ]: from gammapy.irf import make_mean_psf table_psf = make_mean_psf(observations, pos_crab) # In[ ]: psf_kernel = PSFKernel.from_table_psf(table_psf, geom, max_radius="0.3 deg") psf_kernel_array = psf_kernel.psf_kernel_map.sum_over_axes().data # psf_kernel.psf_kernel_map.slice_by_idx({'energy': 0}).plot() # plt.imshow(psf_kernel_array) # ## Map fit # # Let's fit this source assuming a Gaussian spatial shape and a power-law spectral shape, and a background with a flexible normalisation # In[ ]: spatial_model = SkyPointSource(lon_0="83.6 deg",