def make_image(): table = Table.read('acceptance_curve.fits') table.pprint() center = SkyCoord(83.63, 22.01, unit='deg').galactic counts_image = make_empty_image(nxpix=1000, nypix=1000, binsz=0.01, xref=center.l.deg, yref=center.b.deg, proj='TAN') bkg_image = counts_image.copy() data_store = DataStore.from_dir('$GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2') for events in data_store.load_all("events"): center = events.pointing_radec.galactic livetime = events.observation_live_time_duration solid_angle = Angle(0.01, "deg") ** 2 counts_image.data += bin_events_in_image(events, counts_image).data #interp_param = dict(bounds_error=False, fill_value=None) acc_hdu = fill_acceptance_image(bkg_image.header, center, table["offset"], table["Acceptance"]) acc = Quantity(acc_hdu.data, table["Acceptance"].unit) * solid_angle * livetime bkg_image.data += acc.decompose() print(acc.decompose().sum()) counts_image.writeto("counts_image.fits", clobber=True) bkg_image.writeto("bkg_image.fits", clobber=True)
"""Produces an image from 1FHL catalog point sources. """ from gammapy.datasets import FermiGalacticCenter from gammapy.image import make_empty_image, catalog_image # Create image of defined size reference = make_empty_image(nxpix=3600, nypix=1800, binsz=0.1) psf_file = FermiGalacticCenter.psf() # Create image image = catalog_image(reference, psf, catalog='1FHL', source_type='point', total_flux='True') hdu = image.to_fits()[0] hdu.writeto('Image_1FHL.fits', clobber=True)
"""Produces an image from 1FHL catalog point sources. """ from aplpy import FITSFigure from gammapy.datasets import FermiGalacticCenter from gammapy.image import make_empty_image, catalog_image from gammapy.irf import EnergyDependentTablePSF # Create image of defined size reference = make_empty_image(nxpix=300, nypix=100, binsz=1) psf_file = FermiGalacticCenter.filenames()['psf'] psf = EnergyDependentTablePSF.read(psf_file) # Create image image = catalog_image(reference, psf, catalog='1FHL', source_type='point', total_flux='True') # Plot fig = FITSFigure(image.to_fits()[0]) fig.show_grayscale(stretch='linear', interpolation='none') fig.add_colorbar()
from astropy.coordinates import SkyCoord, Angle from astropy.wcs import WCS from gammapy.region import find_reflected_regions, SkyCircleRegion from gammapy.image import ExclusionMask, make_empty_image from gammapy.utils.testing import requires_data hdu = make_empty_image(nxpix=801, nypix=701, binsz=0.01, coordsys='CEL', xref=83.2, yref=22.7) mask = ExclusionMask.create_random(hdu, n=8, min_rad=30, max_rad=80) pos = SkyCoord(80.2, 23.5, unit='deg', frame='icrs') radius = Angle(0.4, 'deg') test_region = SkyCircleRegion(pos=pos, radius=radius) center = SkyCoord(82.8, 22.5, unit='deg', frame='icrs') regions = find_reflected_regions(test_region, center, mask) import matplotlib.pyplot as plt wcs = WCS(hdu.header) fig = plt.figure(figsize=(8, 5), dpi=80) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=wcs) mask.plot(ax) for reg in regions: patch = reg.plot(ax, facecolor='red') ax.add_patch(patch) patch2 = test_region.plot(ax, facecolor='blue') ax.add_patch(patch2) plt.show()
# We use [APLPy](http://aplpy.github.io/) to plot an empty sky image showing the locations of the sources as markers. # # This is a bit complicated because we don't have an image or WCS to instantiate the [aplpy.FITSFigure](http://aplpy.readthedocs.org/en/stable/api/aplpy.FITSFigure.html). # Here we'll use the [gammapy.image.make_empty_image](https://gammapy.readthedocs.org/en/latest/api/gammapy.image.make_empty_image.html) utility function to make an empty image to plot on. # In[14]: from gammapy.image import make_empty_image from aplpy import FITSFigure # In[15]: image = make_empty_image(nxpix=62, nypix=12, binsz=1) figure = FITSFigure(image) # This call to `show_grayscale` is a workaround to get the Figure stretch correct. figure.show_grayscale(vmin=-1, vmax=0) for catalog in catalogs: figure.show_markers(catalog['GLON'], catalog['GLAT'], facecolor=catalog.meta['color'], alpha=0.5, label=catalog.meta['name'], ) figure.ticks.set_xspacing(5) figure.ticks.set_yspacing(2) figure.tick_labels.set_xformat('dd') figure.tick_labels.set_yformat('dd') figure.axis_labels.set_xtext('GLON (deg)') figure.axis_labels.set_ytext('GLAT (deg)')