コード例 #1
0
class RectangleSkySlit(_RectangleSlitBase):
    """
    Slit constructed using WCS and coords information.
    Utilizes `regions` package.

    Parameters
    ----------
    wcs : `astropy.wcs.WCS`
    ra, dec : float
        Center (ra, dec) of slit in deg.
    width, length : float
        Angular width and length of slit in arcsec.
    """
    def __init__(self, wcs, ra, dec, width, length, *args, **kwargs):
        self.wcs = wcs

        skycoord = SkyCoord(ra,
                            dec,
                            unit=(u.Unit(u.deg), u.Unit(u.deg)),
                            frame='fk5')

        length = Angle(length, u.arcsec)
        width = Angle(width, u.arcsec)

        self._sky_region = RectangleSkyRegion(center=skycoord,
                                              width=width,
                                              height=length)

        # N.B: The following step will not be needed when
        # regions.RectangleSkyRegion.as_artist is implemented
        self._pix_region = self._sky_region.to_pixel(wcs)
        self._patch = self._pix_region.as_artist(edgecolor='red',
                                                 facecolor='none')
        self._is_active = False
コード例 #2
0
class RectangleSkySlit(_RectangleSlitBase):
    """
    Slit constructed using WCS and coords information.
    Utilizes `regions` package.

    Parameters
    ----------
    wcs : `astropy.wcs.WCS`
    ra, dec : float
        Center (ra, dec) of slit in deg.
    width, length : float
        Angular width and length of slit in arcsec.
    """

    def __init__(self, wcs, ra, dec, width, length, *args, **kwargs):
        self.wcs = wcs

        skycoord = SkyCoord(ra, dec,
                            unit=(u.Unit(u.deg),
                                  u.Unit(u.deg)),
                            frame='fk5')

        length = Angle(length, u.arcsec)
        width = Angle(width, u.arcsec)

        self._sky_region = RectangleSkyRegion(center=skycoord, width=width, height=length)

        # N.B: The following step will not be needed when
        # regions.RectangleSkyRegion.as_artist is implemented
        self._pix_region = self._sky_region.to_pixel(wcs)
        self._patch = self._pix_region.as_artist(edgecolor='red', facecolor='none')
        self._is_active = False
コード例 #3
0
on_ellipse_annulus = EllipseAnnulusSkyRegion(
    center=position,
    inner_width=1.5 * u.deg,
    outer_width=2.5 * u.deg,
    inner_height=3 * u.deg,
    outer_height=4 * u.deg,
    angle=130 * u.deg,
)

another_position = SkyCoord(80.3, 22.0, unit="deg")
on_rectangle = RectangleSkyRegion(center=another_position,
                                  width=2.0 * u.deg,
                                  height=4.0 * u.deg,
                                  angle=50 * u.deg)

# Now we plot those regions. We first create an empty map
empty_map = WcsNDMap.create(skydir=position,
                            width=10 * u.deg,
                            binsz=0.1 * u.deg,
                            proj="TAN")
empty_map.data += 1.0
empty_map.plot(cmap="gray", vmin=0, vmax=1)

# To plot the regions, we convert them to PixelRegion with the map wcs
on_circle.to_pixel(empty_map.geom.wcs).plot()
on_rectangle.to_pixel(empty_map.geom.wcs).plot()
on_ellipse_annulus.to_pixel(empty_map.geom.wcs).plot()

plt.show()
コード例 #4
0
# The ON region center is defined in the icrs frame. The angle is defined w.r.t. to its axis.
rectangle = RectangleSkyRegion(center=crab_position,
                               width=0.5 * u.deg,
                               height=0.4 * u.deg,
                               angle=0 * u.deg)

bkg_maker = ReflectedRegionsBackgroundMaker(min_distance=0.1 * u.rad)
dataset_maker = SpectrumDatasetMaker(selection=["counts"])

e_reco = MapAxis.from_energy_bounds(0.1, 100, 30, unit="TeV")
dataset_empty = SpectrumDataset.create(e_reco=e_reco, region=rectangle)

datasets = []

for obs in observations:

    dataset = dataset_maker.run(dataset_empty.copy(name=f"obs-{obs.obs_id}"),
                                obs)
    dataset_on_off = bkg_maker.run(observation=obs, dataset=dataset)
    datasets.append(dataset_on_off)

m = Map.create(skydir=crab_position, width=(8, 8), proj="TAN")

_, ax, _ = m.plot(vmin=-1, vmax=0)

rectangle.to_pixel(ax.wcs).plot(ax=ax, color="black")

plot_spectrum_datasets_off_regions(datasets=datasets, ax=ax)
plt.show()