ManglePolygon

class pydl.pydlutils.mangle.ManglePolygon(*args, **kwargs)[source]

Bases: object

Simple object to represent a polygon.

A polygon may be instantiated with a row (FITS_record) from a FITS_polygon object, another ManglePolygon object (copy constructor), keyword arguments, or with no arguments at all, in which case it represents the whole sky.

Attributes

cm (ndarray) The size of each cap in the polygon.
id (int) An arbitrary ID number.
pixel (int) Pixel this polygon is in.
use_caps (int) Bitmask indicating which caps to use.
weight (float) Weight factor assigned to the polygon.

Attributes Summary

ncaps Number of caps in the polygon.
str Solid angle of this polygon (steradians).
x The orientation of each cap in the polygon.

Methods Summary

add_caps(x, cm) Create a new polygon that contains additional caps.
cmminf() The index of the smallest cap in the polygon, accounting for negative caps and use_caps.
copy() Return an exact copy of the polygon.
garea() Compute the area of a polygon.
gzeroar() If at least one cap has zero area, then the whole polygon has zero area.
polyn(other, n[, complement]) Intersection of a polygon with the n th cap of another polygon.

Attributes Documentation

ncaps

Number of caps in the polygon.

str

Solid angle of this polygon (steradians).

x

The orientation of each cap in the polygon. The direction is specified by a unit 3-vector.

Methods Documentation

add_caps(x, cm)[source]

Create a new polygon that contains additional caps. The caps are appended to the existing polygon’s caps.

Parameters:

x : ndarray or recarray

X values of the new caps.

cm : ndarray or recarray

CM values of the new caps.

Returns:

ManglePolygon

A new polygon object.

cmminf()[source]

The index of the smallest cap in the polygon, accounting for negative caps and use_caps.

Returns:

int

Integer index of the smallest cap.

copy()[source]

Return an exact copy of the polygon.

Returns:

ManglePolygon

A new polygon object.

garea()[source]

Compute the area of a polygon.

See [1] for the detailed area formula, which is summarized here:

  • An empty polygon with no caps is defined to be the whole sky.
  • A polygon with one cap has area 2*pi*self.cm.
  • A polygon with at least one cap with an area less than \(2\pi\) has an area less than \(2\pi\).
  • If every cap has an area greater than \(2\pi\), split the polygon into two smaller polygons and sum the two areas.
Returns:

float

The area of the polygon.

References

[1]Hamilton, A. J. S.; Tegmark, Max, 2004 MNRAS 349, 115.
gzeroar()[source]

If at least one cap has zero area, then the whole polygon has zero area.

Returns:

bool

True if the area is zero.

polyn(other, n, complement=False)[source]

Intersection of a polygon with the n th cap of another polygon.

Parameters:

other : ManglePolygon

Polygon containing a cap to intersect the first polygon with.

n : int

Index of the cap in other.

complement : bool, optional

If True, set the sign of the cm value of other to be the complement of the original value.

Returns:

ManglePolygon

A polygon containing the intersected caps.