""" Example script illustrating compound regions. """ import numpy as np import matplotlib.pyplot as plt from astropy.coordinates import SkyCoord, Angle from regions import CircleSkyRegion, make_example_dataset # load example dataset to get skymap config = dict(crval=(0, 0), crpix=(180, 90), cdelt=(-1, 1), shape=(180, 360)) dataset = make_example_dataset(data='simulated', config=config) wcs = dataset.wcs # remove sources dataset.image.data = np.zeros_like(dataset.image.data) # define 2 sky circles circle1 = CircleSkyRegion( center=SkyCoord(20, 0, unit='deg', frame='galactic'), radius=Angle('30 deg') ) circle2 = CircleSkyRegion( center=SkyCoord(50, 45, unit='deg', frame='galactic'), radius=Angle('30 deg'), )
"""Example how to plot sky regions on a sky image. """ from astropy.coordinates import SkyCoord, Angle 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=ax, edgecolor='yellow', facecolor='yellow', alpha=0.5, lw=3)