profile.scale_to_local_density() position = SkyCoord(0.0, 0.0, frame="galactic", unit="deg") geom = WcsGeom.create(binsz=0.05, skydir=position, width=3.0, coordsys="GAL") # In[ ]: jfactory = JFactory(geom=geom, profile=profile, distance=profiles.DMProfile.DISTANCE_GC) jfact = jfactory.compute_jfactor() # In[ ]: jfact_map = WcsNDMap(geom=geom, data=jfact.value, unit=jfact.unit) fig, ax, im = jfact_map.plot(cmap="viridis", norm=LogNorm(), add_cbar=True) plt.title("J-Factor [{}]".format(jfact_map.unit)) # 1 deg circle usually used in H.E.S.S. analyses sky_reg = CircleSkyRegion(center=position, radius=1 * u.deg) pix_reg = sky_reg.to_pixel(wcs=geom.wcs) pix_reg.plot(ax=ax, facecolor="none", edgecolor="red", label="1 deg circle") plt.legend() # In[ ]: # NOTE: https://arxiv.org/abs/1607.08142 quote 2.67e21 without the +/- 0.3 deg band around the plane total_jfact = pix_reg.to_mask().multiply(jfact).sum() print("J-factor in 1 deg circle around GC assuming a " "{} is {:.3g}".format(profile.__class__.__name__, total_jfact))
# Exclusion mask currently unused. Remove here or move to later in the tutorial? # In[ ]: target_position = SkyCoord(0, 0, unit="deg", frame="galactic") on_radius = 0.2 * u.deg on_region = CircleSkyRegion(center=target_position, radius=on_radius) # In[ ]: exclusion_mask = geom.to_image().region_mask([on_region], inside=False) exclusion_mask = WcsNDMap(geom.to_image(), exclusion_mask) exclusion_mask.plot(); # In[ ]: get_ipython().run_cell_magic('time', '', 'maker = MapMaker(geom, offset_max="2 deg")\nmaps = maker.run(observations)\nprint(maps.keys())') # In[ ]: # The maps are cubes, with an energy axis. # Let's also make some images: images = maker.run_images()
# ### Compute images # # Exclusion mask currently unused. Remove here or move to later in the tutorial? # In[ ]: target_position = SkyCoord(0, 0, unit="deg", frame="galactic") on_radius = 0.2 * u.deg on_region = CircleSkyRegion(center=target_position, radius=on_radius) # In[ ]: exclusion_mask = geom.to_image().region_mask([on_region], inside=False) exclusion_mask = WcsNDMap(geom.to_image(), exclusion_mask) exclusion_mask.plot() # In[ ]: get_ipython().run_cell_magic( 'time', '', 'stacked = MapDataset.create(geom=geom)\nmaker = MapDatasetMaker(selection=["counts", "background", "exposure"])\nmaker_safe_mask = SafeMaskMaker(methods=["offset-max"], offset_max=2.5 * u.deg)\n\nfor obs in observations:\n cutout = stacked.cutout(obs.pointing_radec, width="5 deg")\n dataset = maker.run(cutout, obs)\n dataset = maker_safe_mask.run(dataset, obs)\n stacked.stack(dataset)' ) # In[ ]: # The maps are cubes, with an energy axis. # Let's also make some images: dataset_image = stacked.to_image() images = {