from astropy.coordinates import SkyCoord, Angle from regions import CircleSkyRegion from gammapy.image import SkyMask from gammapy.background import find_reflected_regions mask = SkyMask.empty(name='Exclusion Mask', nxpix=801, nypix=701, binsz=0.01, coordsys='CEL', xref=83.2, yref=22.7) mask.fill_random_circles(n=8, min_rad=30, max_rad=80) pos = SkyCoord(80.2, 23.5, unit='deg') radius = Angle(0.4, 'deg') test_region = CircleSkyRegion(pos, radius) center = SkyCoord(82.8, 22.5, unit='deg') regions = find_reflected_regions(test_region, center, mask) import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 5), dpi=80) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=mask.wcs) mask.plot(ax, fig) for reg in regions: reg.plot(ax, facecolor='red') test_region.plot(ax, facecolor='blue') plt.show()
from regions import ( make_example_dataset, CircleSkyRegion, ) import matplotlib.pyplot as plt config = dict(crpix=(18, 9), cdelt=(-10, 10), shape=(18, 36)) dataset = make_example_dataset(data='simulated', config=config) wcs = dataset.wcs fig = plt.figure() ax = fig.add_axes([0.15, 0.1, 0.8, 0.8], projection=wcs) ax.set_xlim(-0.5, dataset.config['shape'][1] - 0.5) ax.set_ylim(-0.5, dataset.config['shape'][0] - 0.5) ax.imshow(dataset.image.data, cmap='gray', vmin=0, vmax=1, interpolation='nearest', origin='lower') for source in dataset.source_table: # Plot a sky circle around each source center = SkyCoord(source['GLON'], source['GLAT'], unit='deg', frame='galactic') radius = Angle(20, 'deg') region = CircleSkyRegion(center=center, radius=radius) pix_region = region.to_pixel(wcs=wcs) pix_region.plot(ax, edgecolor='green', facecolor='none', alpha=0.8, lw=3) region.plot(ax, edgecolor='yellow', facecolor='none', alpha=0.8, lw=3) plt.show()
"""Example how to compute and plot reflected regions.""" from astropy.coordinates import SkyCoord, Angle from regions import CircleSkyRegion from gammapy.image import SkyMask from gammapy.background import find_reflected_regions mask = SkyMask.empty(name='Exclusion Mask', nxpix=801, nypix=701, binsz=0.01, coordsys='CEL', xref=83.2, yref=22.7) mask.fill_random_circles(n=8, min_rad=30, max_rad=80) pos = SkyCoord(80.2, 23.5, unit='deg') radius = Angle(0.4, 'deg') test_region = CircleSkyRegion(pos, radius) center = SkyCoord(82.8, 22.5, unit='deg') regions = find_reflected_regions(test_region, center, mask) import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 5), dpi=80) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection=mask.wcs) mask.plot(ax, fig) for reg in regions: reg.plot(ax, facecolor='red') test_region.plot(ax, facecolor='blue') plt.show()
dataset = make_example_dataset(data='simulated', config=config) wcs = dataset.wcs fig = plt.figure() ax = fig.add_axes([0.15, 0.1, 0.8, 0.8], projection=wcs) ax.set_xlim(-0.5, dataset.config['shape'][1] - 0.5) ax.set_ylim(-0.5, dataset.config['shape'][0] - 0.5) ax.imshow(dataset.image.data, cmap='gray', vmin=0, vmax=1, interpolation='nearest', origin='lower') for source in dataset.source_table: # Plot a sky circle around each source center = SkyCoord(source['GLON'], source['GLAT'], unit='deg', frame='galactic') radius = Angle(20, 'deg') region = CircleSkyRegion(center=center, radius=radius) pix_region = region.to_pixel(wcs=wcs) pix_region.plot(ax, edgecolor='green', facecolor='none', alpha=0.8, lw=3) region.plot(ax, edgecolor='yellow', facecolor='none', alpha=0.8, lw=3) plt.show()