def run_benchmark(): # Set up data store and select N_OBS times the observation OBS_ID data_store = DataStore.from_dir('$GAMMAPY_EXTRA/test_datasets/cta_1dc/') obs_ids = OBS_ID * np.ones(N_OBS) obs_list = data_store.obs_list(obs_id=obs_ids) target_position = SkyCoord(0, 0, unit='deg', frame='galactic') on_radius = 0.2 * u.deg on_region = CircleSkyRegion(center=target_position, radius=on_radius) bkg_estimator = RingBackgroundEstimator( r_in=0.5 * u.deg, width=0.2 * u.deg, ) # Define reference image centered on the target xref = target_position.galactic.l.value yref = target_position.galactic.b.value ref_image = SkyImage.empty( nxpix=800, nypix=600, binsz=0.02, xref=xref, yref=yref, proj='TAN', coordsys='GAL', ) exclusion_mask = ref_image.region_mask(on_region) exclusion_mask.data = 1 - exclusion_mask.data image_estimator = IACTBasicImageEstimator( reference=ref_image, emin=100 * u.GeV, emax=100 * u.TeV, offset_max=3 * u.deg, background_estimator=bkg_estimator, exclusion_mask=exclusion_mask, ) result = image_estimator.run(obs_list)
exclusion_mask = ref_image.region_mask(on_region) exclusion_mask.data = 1 - exclusion_mask.data bkg_estimator = RingBackgroundEstimator( r_in=0.5 * u.deg, width=0.2 * u.deg, ) image_estimator = IACTBasicImageEstimator( reference=ref_image, emin=100 * u.GeV, emax=100 * u.TeV, #offset_max=3 * u.deg, background_estimator=bkg_estimator, exclusion_mask=exclusion_mask, ) images_new = image_estimator.run(obs_list) print("\n\n\n") print(images_new.names) print(result2.names) print("\n\n\n") # Let's have a look at the background image and the exclusion mask # This doesn't work yet ... need to do SkyImage.plot fixes: # fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 3)) # background_image.plot(ax=axes[0]) # exclusion_image.plot(ax=axes[1]) # significance_image.plot(ax=axes[2]) print("bkg metodo 1") background_image = result2['background'] background_image2 = images_new['background'] norm = simple_norm(background_image.data, stretch='sqrt', min_cut=0, max_cut=0.5)
# In[12]: bkg_estimator = RingBackgroundEstimator( r_in=0.5 * u.deg, width=0.2 * u.deg, ) image_estimator = IACTBasicImageEstimator( reference=ref_image, emin=100 * u.GeV, emax=100 * u.TeV, offset_max=3 * u.deg, background_estimator=bkg_estimator, exclusion_mask=exclusion_mask, ) images = image_estimator.run(obs_list) images.names # ### Show images # # Let's define a little helper function and then show all the resulting images that were computed. # In[13]: def show_image(image, radius=3, vmin=0, vmax=3): """Little helper function to show the images for this application here.""" image.smooth(radius=radius).show(vmin=vmin, vmax=vmax, add_cbar=True) image.cutout( position=SkyCoord(0.5, 0, unit='deg', frame='galactic'), size=(2 * u.deg, 3 * u.deg),
exclusion_mask.plot(add_cbar=True) bkg_estimator = FoVBackgroundEstimator() emin = 0.5 * u.TeV emax = 20 * u.TeV offset_max = 2.3 * u.deg image_estimator = IACTBasicImageEstimator(reference=ref_image, emin=emin, emax=emax, offset_max=offset_max, background_estimator=bkg_estimator, exclusion_mask=exclusion_mask) comp_image = image_estimator.run(mylist) comp_image.names images = comp_image print("Total number of counts", images[0].data.sum()) print("Total number of excess events", images[3].data.sum()) fermi = SkyImage.read("FDA16.fits") fermi_rep = fermi.reproject(ref_image) #Make sure that the exclusion mask properly excludes all sources masked_excess = SkyImage.empty_like(images['excess']) masked_excess.data = comp_image['excess'].data * exclusion_mask.data masked_excess_cutout = masked_excess.cutout(position=SkyCoord(