Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions regions/shapes/annulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ def to_sky(self, wcs):
return CircleAnnulusSkyRegion(center, inner_radius, outer_radius,
self.meta.copy(), self.visual.copy())

def to_polygon(self, npoints=100):
def to_polygon(self, n_points=100):
"""
Return a `~regions.CompoundPixelRegion` of two
`~regions.PolygonPixelRegion` objects that approximates this
annulus.

Parameters
----------
npoints : int, optional
n_points : int, optional
The number of polygon vertices for each circle. Default
is 100.

Expand All @@ -178,8 +178,8 @@ def to_polygon(self, npoints=100):
A compound region of two polygon regions approximating the
annulus.
"""
inner_polygon = self._inner_region.to_polygon(npoints=npoints)
outer_polygon = self._outer_region.to_polygon(npoints=npoints)
inner_polygon = self._inner_region.to_polygon(n_points=n_points)
outer_polygon = self._outer_region.to_polygon(n_points=n_points)
return CompoundPixelRegion(inner_polygon, outer_polygon,
operator.xor, self.meta.copy(),
self.visual.copy())
Expand Down Expand Up @@ -232,7 +232,7 @@ def to_pixel(self, wcs):
meta=self.meta.copy(),
visual=self.visual.copy())

def to_polygon(self, wcs, npoints=100):
def to_polygon(self, wcs, n_points=100):
"""
Return a `~regions.CompoundSkyRegion` of two
`~regions.PolygonSkyRegion` objects that approximates this
Expand All @@ -242,7 +242,7 @@ def to_polygon(self, wcs, npoints=100):
----------
wcs : `~astropy.wcs.WCS`
The WCS to use for the sky-to-pixel-to-sky conversion.
npoints : int, optional
n_points : int, optional
The number of polygon vertices for each circle. Default
is 100.

Expand All @@ -252,7 +252,7 @@ def to_polygon(self, wcs, npoints=100):
A compound region of two polygon regions approximating the
annulus.
"""
return self.to_pixel(wcs).to_polygon(npoints=npoints).to_sky(wcs)
return self.to_pixel(wcs).to_polygon(n_points=n_points).to_sky(wcs)


class AsymmetricAnnulusPixelRegion(AnnulusPixelRegion):
Expand Down Expand Up @@ -500,15 +500,15 @@ def to_sky(self, wcs):
meta=self.meta.copy(),
visual=self.visual.copy())

def to_polygon(self, npoints=100):
def to_polygon(self, n_points=100):
"""
Return a `~regions.CompoundPixelRegion` of two
`~regions.PolygonPixelRegion` objects that approximates this
annulus.

Parameters
----------
npoints : int, optional
n_points : int, optional
The number of polygon vertices for each ellipse. Default
is 100.

Expand All @@ -518,8 +518,8 @@ def to_polygon(self, npoints=100):
A compound region of two polygon regions approximating the
annulus.
"""
inner_polygon = self._inner_region.to_polygon(npoints=npoints)
outer_polygon = self._outer_region.to_polygon(npoints=npoints)
inner_polygon = self._inner_region.to_polygon(n_points=n_points)
outer_polygon = self._outer_region.to_polygon(n_points=n_points)
return CompoundPixelRegion(inner_polygon, outer_polygon,
operator.xor, self.meta.copy(),
self.visual.copy())
Expand Down Expand Up @@ -582,7 +582,7 @@ def to_pixel(self, wcs):
meta=self.meta.copy(),
visual=self.visual.copy())

def to_polygon(self, wcs, npoints=100):
def to_polygon(self, wcs, n_points=100):
"""
Return a `~regions.CompoundSkyRegion` of two
`~regions.PolygonSkyRegion` objects that approximates this
Expand All @@ -592,7 +592,7 @@ def to_polygon(self, wcs, npoints=100):
----------
wcs : `~astropy.wcs.WCS`
The WCS to use for the sky-to-pixel-to-sky conversion.
npoints : int, optional
n_points : int, optional
The number of polygon vertices for each ellipse. Default
is 100.

Expand All @@ -602,7 +602,7 @@ def to_polygon(self, wcs, npoints=100):
A compound region of two polygon regions approximating the
annulus.
"""
return self.to_pixel(wcs).to_polygon(npoints=npoints).to_sky(wcs)
return self.to_pixel(wcs).to_polygon(n_points=n_points).to_sky(wcs)


class RectangleAnnulusPixelRegion(AsymmetricAnnulusPixelRegion):
Expand Down
12 changes: 6 additions & 6 deletions regions/shapes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,22 @@ def rotate(self, center, angle):
center = self.center.rotate(center, angle)
return self.copy(center=center)

def to_polygon(self, npoints=100):
def to_polygon(self, n_points=100):
"""
Return a `~regions.PolygonPixelRegion` that approximates this
circle.

Parameters
----------
npoints : int, optional
n_points : int, optional
The number of polygon vertices. Default is 100.

Returns
-------
polygon : `~regions.PolygonPixelRegion`
A polygon region approximating the circle.
"""
theta = np.linspace(0, 2 * np.pi, npoints, endpoint=False)
theta = np.linspace(0, 2 * np.pi, n_points, endpoint=False)
x = self.radius * np.cos(theta) + self.center.x
y = self.radius * np.sin(theta) + self.center.y
vertices = PixCoord(x=x, y=y)
Expand Down Expand Up @@ -239,7 +239,7 @@ def to_pixel(self, wcs):
return CirclePixelRegion(center, radius, meta=self.meta.copy(),
visual=self.visual.copy())

def to_polygon(self, wcs, npoints=100):
def to_polygon(self, wcs, n_points=100):
"""
Return a `~regions.PolygonSkyRegion` that approximates this
circle.
Expand All @@ -248,12 +248,12 @@ def to_polygon(self, wcs, npoints=100):
----------
wcs : `~astropy.wcs.WCS`
The WCS to use for the sky-to-pixel-to-sky conversion.
npoints : int, optional
n_points : int, optional
The number of polygon vertices. Default is 100.

Returns
-------
polygon : `~regions.PolygonSkyRegion`
A polygon region approximating the circle.
"""
return self.to_pixel(wcs).to_polygon(npoints=npoints).to_sky(wcs)
return self.to_pixel(wcs).to_polygon(n_points=n_points).to_sky(wcs)
12 changes: 6 additions & 6 deletions regions/shapes/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,22 +319,22 @@ def rotate(self, center, angle):
angle = self.angle + angle
return self.copy(center=center, angle=angle)

def to_polygon(self, npoints=100):
def to_polygon(self, n_points=100):
"""
Return a `~regions.PolygonPixelRegion` that approximates this
ellipse.

Parameters
----------
npoints : int, optional
n_points : int, optional
The number of polygon vertices. Default is 100.

Returns
-------
polygon : `~regions.PolygonPixelRegion`
A polygon region approximating the ellipse.
"""
theta = np.linspace(0, 2 * np.pi, npoints, endpoint=False)
theta = np.linspace(0, 2 * np.pi, n_points, endpoint=False)
x = 0.5 * self.width * np.cos(theta)
y = 0.5 * self.height * np.sin(theta)
cos_angle = np.cos(self.angle)
Expand Down Expand Up @@ -401,7 +401,7 @@ def to_pixel(self, wcs):
meta=self.meta.copy(),
visual=self.visual.copy())

def to_polygon(self, wcs, npoints=100):
def to_polygon(self, wcs, n_points=100):
"""
Return a `~regions.PolygonSkyRegion` that approximates this
ellipse.
Expand All @@ -410,12 +410,12 @@ def to_polygon(self, wcs, npoints=100):
----------
wcs : `~astropy.wcs.WCS`
The WCS to use for the sky-to-pixel-to-sky conversion.
npoints : int, optional
n_points : int, optional
The number of polygon vertices. Default is 100.

Returns
-------
polygon : `~regions.PolygonSkyRegion`
A polygon region approximating the ellipse.
"""
return self.to_pixel(wcs).to_polygon(npoints=npoints).to_sky(wcs)
return self.to_pixel(wcs).to_polygon(n_points=n_points).to_sky(wcs)
42 changes: 21 additions & 21 deletions regions/shapes/tests/test_to_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_to_polygon_nvertices(self):
poly = self.reg.to_polygon()
assert len(poly.vertices.x) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(n_points=50)
assert len(poly.vertices.x) == 50

def test_to_polygon_meta(self):
Expand All @@ -49,13 +49,13 @@ def test_to_polygon_meta(self):
assert poly.visual['color'] != self.visual['color']

def test_to_polygon_vertices(self):
poly = self.reg.to_polygon(npoints=4)
poly = self.reg.to_polygon(n_points=4)
# theta = [0, pi/2, pi, 3*pi/2]
assert_allclose(poly.vertices.x, [5, 3, 1, 3], atol=1e-10)
assert_allclose(poly.vertices.y, [4, 6, 4, 2], atol=1e-10)

def test_to_polygon_area(self):
poly = self.reg.to_polygon(npoints=1000)
poly = self.reg.to_polygon(n_points=1000)
assert_allclose(poly.area, self.reg.area, rtol=1e-4)

def test_to_polygon_contains(self):
Expand All @@ -79,8 +79,8 @@ def test_to_polygon_nvertices(self):
poly = self.reg.to_polygon(self.wcs)
assert len(poly.vertices.ra) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(self.wcs, npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(self.wcs, n_points=50)
assert len(poly.vertices.ra) == 50


Expand All @@ -98,8 +98,8 @@ def test_to_polygon_nvertices(self):
poly = self.reg.to_polygon()
assert len(poly.vertices.x) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(n_points=50)
assert len(poly.vertices.x) == 50

def test_to_polygon_meta(self):
Expand All @@ -112,7 +112,7 @@ def test_to_polygon_meta(self):
assert poly.visual['color'] != self.visual['color']

def test_to_polygon_vertices_no_rotation(self):
poly = self.reg.to_polygon(npoints=4)
poly = self.reg.to_polygon(n_points=4)
# Ellipse: width=6, height=4, center=(3,4), angle=0
# theta = [0, pi/2, pi, 3*pi/2]
# x = 0.5*6*cos(theta) + 3 = [6, 3, 0, 3]
Expand All @@ -123,13 +123,13 @@ def test_to_polygon_vertices_no_rotation(self):
def test_to_polygon_vertices_rotated(self):
reg = EllipsePixelRegion(PixCoord(0, 0), width=4, height=2,
angle=90 * u.deg)
poly = reg.to_polygon(npoints=4)
poly = reg.to_polygon(n_points=4)
# After 90 deg rotation, width along y and height along x
assert_allclose(poly.vertices.x, [0, -1, 0, 1], atol=1e-10)
assert_allclose(poly.vertices.y, [2, 0, -2, 0], atol=1e-10)

def test_to_polygon_area(self):
poly = self.reg.to_polygon(npoints=1000)
poly = self.reg.to_polygon(n_points=1000)
assert_allclose(poly.area, self.reg.area, rtol=1e-4)

def test_to_polygon_contains(self):
Expand All @@ -154,8 +154,8 @@ def test_to_polygon_nvertices(self):
poly = self.reg.to_polygon(self.wcs)
assert len(poly.vertices.ra) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(self.wcs, npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(self.wcs, n_points=50)
assert len(poly.vertices.ra) == 50


Expand Down Expand Up @@ -259,8 +259,8 @@ def test_to_polygon_nvertices(self):
assert len(poly.region1.vertices.x) == 100
assert len(poly.region2.vertices.x) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(n_points=50)
assert len(poly.region1.vertices.x) == 50
assert len(poly.region2.vertices.x) == 50

Expand Down Expand Up @@ -291,8 +291,8 @@ def test_to_polygon_type(self):
poly = self.reg.to_polygon(self.wcs)
assert isinstance(poly, CompoundSkyRegion)

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(self.wcs, npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(self.wcs, n_points=50)
assert isinstance(poly, CompoundSkyRegion)


Expand All @@ -314,8 +314,8 @@ def test_to_polygon_nvertices(self):
assert len(poly.region1.vertices.x) == 100
assert len(poly.region2.vertices.x) == 100

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(n_points=50)
assert len(poly.region1.vertices.x) == 50
assert len(poly.region2.vertices.x) == 50

Expand Down Expand Up @@ -345,8 +345,8 @@ def test_to_polygon_type(self):
poly = self.reg.to_polygon(self.wcs)
assert isinstance(poly, CompoundSkyRegion)

def test_to_polygon_npoints(self):
poly = self.reg.to_polygon(self.wcs, npoints=50)
def test_to_polygon_n_points(self):
poly = self.reg.to_polygon(self.wcs, n_points=50)
assert isinstance(poly, CompoundSkyRegion)


Expand Down
Loading