aperture_to_region#

photutils.aperture.aperture_to_region(aperture)[source]#

Convert a given Aperture object to a regions.Region or regions.Regions object.

Because a regions.Region object can only have one position, a regions.Region object is returned only if the input aperture is scalar (a single position that is not in a list or array). Otherwise, a regions.Regions object is returned with one region per position.

Parameters:
apertureAperture

An Aperture object to convert.

Returns:
regionregions.Region or regions.Regions

An equivalent regions.Region object. If the input aperture is not scalar, then a regions.Regions object is returned with one region per position.

Raises:
TypeError

The input is not an Aperture object, or the given Aperture object is not supported.

Notes

The elliptical aperture a and b parameters represent the semimajor and semiminor axes, respectively. The a and b parameters are mapped to the ellipse width and height region parameters, respectively, by multiplying by 2 because they represent the full extent of the ellipse.

The region angle for sky-based regions is defined as the angle of the width axis relative to the WCS longitude axis (PA=90). However, the sky-based apertures define theta as the position angle, relative to the North celestial pole (PA=0), of the semimajor axis (elliptical apertures) or of the width side (rectangular apertures). Therefore, for sky-based elliptical and rectangular apertures the theta parameter is converted to the region angle by adding 90 degrees.

The following Aperture objects are supported, shown with their equivalent regions.Region object:

Examples

>>> from photutils.aperture import CircularAperture, aperture_to_region
>>> aperture = CircularAperture((10, 20), r=5)
>>> region = aperture_to_region(aperture)
>>> region
<CirclePixelRegion(center=PixCoord(x=10.0, y=20.0), radius=5.0)>
>>> aperture = CircularAperture(((10, 20), (30, 40)), r=5)
>>> region = aperture_to_region(aperture)
>>> region
<Regions([
  <CirclePixelRegion(center=PixCoord(x=10.0, y=20.0), radius=5.0)>,
  <CirclePixelRegion(center=PixCoord(x=30.0, y=40.0), radius=5.0)>
])>