Skip to content

Commit

Permalink
Rename AngleOrPixelScalarQuantity; check for strictly positive
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybradley committed Feb 16, 2022
1 parent 5e36dbe commit d61630e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
18 changes: 12 additions & 6 deletions photutils/aperture/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

__all__ = ['ApertureAttribute', 'PixelPositions', 'SkyCoordPositions',
'Scalar', 'PositiveScalar', 'AngleOrPixelScalarQuantity']
'Scalar', 'PositiveScalar', 'ScalarAngle', 'ScalarAngleOrPixel']


class ApertureAttribute:
Expand Down Expand Up @@ -142,10 +142,13 @@ def _validate(self, value):
raise TypeError(f'{self.name} must be a scalar angle')


class AngleOrPixelScalarQuantity(ApertureAttribute):
class ScalarAngleOrPixel(ApertureAttribute):
"""
Check that value is either an angular or a pixel scalar
`~astropy.units.Quantity`.
Check that value is a scalar angle, either as a
`~astropy.coordinates.Angle` or `~astropy.units.Quantity` with
angular units, or a scalar `~astropy.units.Quantity` in pixel units.
The value must be strictly positive (> 0).
"""

def _validate(self, value):
Expand All @@ -157,6 +160,9 @@ def _validate(self, value):
value.unit == u.pixel):
raise ValueError(f'{self.name} must have angular or pixel '
'units')

if not value > 0:
raise ValueError(f'{self.name} must be strictly positive')
else:
raise TypeError(f'{self.name} must be an astropy Quantity '
'instance')
raise TypeError(f'{self.name} must be a scalar angle or pixel '
'Quantity')
10 changes: 5 additions & 5 deletions photutils/aperture/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import numpy as np

from .attributes import (AngleOrPixelScalarQuantity, PixelPositions,
PositiveScalar, SkyCoordPositions)
from .attributes import (PixelPositions, PositiveScalar, SkyCoordPositions,
ScalarAngleOrPixel)
from .core import PixelAperture, SkyAperture
from .mask import ApertureMask
from ..geometry import circular_overlap_grid
Expand Down Expand Up @@ -370,7 +370,7 @@ class SkyCircularAperture(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
r = AngleOrPixelScalarQuantity(
r = ScalarAngleOrPixel(
'r',
description='The radius, in angular or pixel units.')

Expand Down Expand Up @@ -433,10 +433,10 @@ class SkyCircularAnnulus(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
r_in = AngleOrPixelScalarQuantity(
r_in = ScalarAngleOrPixel(
'r_in',
description='The inner radius, in angular or pixel units.')
r_out = AngleOrPixelScalarQuantity(
r_out = ScalarAngleOrPixel(
'r_out',
description='The outer radius, in angular or pixel units.')

Expand Down
16 changes: 8 additions & 8 deletions photutils/aperture/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import astropy.units as u
import numpy as np

from .attributes import (AngleOrPixelScalarQuantity, ScalarAngle, PixelPositions,
PositiveScalar, Scalar, SkyCoordPositions)
from .attributes import (ScalarAngle, PixelPositions, PositiveScalar, Scalar,
SkyCoordPositions, ScalarAngleOrPixel)
from .core import PixelAperture, SkyAperture
from .mask import ApertureMask
from ..geometry import elliptical_overlap_grid
Expand Down Expand Up @@ -455,10 +455,10 @@ class SkyEllipticalAperture(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
a = AngleOrPixelScalarQuantity(
a = ScalarAngleOrPixel(
'a',
description='The semimajor axis, in angular or pixel units.')
b = AngleOrPixelScalarQuantity(
b = ScalarAngleOrPixel(
'b',
description='The semiminor axis, in angular or pixel units.')
theta = ScalarAngle(
Expand Down Expand Up @@ -546,16 +546,16 @@ class SkyEllipticalAnnulus(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
a_in = AngleOrPixelScalarQuantity(
a_in = ScalarAngleOrPixel(
'a_in',
description='The inner semimajor axis, in angular or pixel units.')
a_out = AngleOrPixelScalarQuantity(
a_out = ScalarAngleOrPixel(
'a_out',
description='The outer semimajor axis, in angular or pixel units.')
b_in = AngleOrPixelScalarQuantity(
b_in = ScalarAngleOrPixel(
'b_in',
description='The inner semiminor axis, in angular or pixel units.')
b_out = AngleOrPixelScalarQuantity(
b_out = ScalarAngleOrPixel(
'b_out',
description='The outer semiminor axis, in angular or pixel units.')
theta = ScalarAngle(
Expand Down
16 changes: 8 additions & 8 deletions photutils/aperture/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import astropy.units as u
import numpy as np

from .attributes import (AngleOrPixelScalarQuantity, ScalarAngle, PixelPositions,
PositiveScalar, Scalar, SkyCoordPositions)
from .attributes import (ScalarAngle, PixelPositions, PositiveScalar, Scalar,
SkyCoordPositions, ScalarAngleOrPixel)
from .core import PixelAperture, SkyAperture
from .mask import ApertureMask
from ..geometry import rectangular_overlap_grid
Expand Down Expand Up @@ -493,10 +493,10 @@ class SkyRectangularAperture(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
w = AngleOrPixelScalarQuantity(
w = ScalarAngleOrPixel(
'w',
description='The full width, in angular or pixel units.')
h = AngleOrPixelScalarQuantity(
h = ScalarAngleOrPixel(
'h',
description='The full height, in angular or pixel units.')
theta = ScalarAngle(
Expand Down Expand Up @@ -592,16 +592,16 @@ class SkyRectangularAnnulus(SkyAperture):
positions = SkyCoordPositions(
'positions',
description='The center position(s) in sky coordinates.')
w_in = AngleOrPixelScalarQuantity(
w_in = ScalarAngleOrPixel(
'w_in',
description='The inner full width, in angular or pixel units.')
w_out = AngleOrPixelScalarQuantity(
w_out = ScalarAngleOrPixel(
'w_out',
description='The outer full width, in angular or pixel units.')
h_in = AngleOrPixelScalarQuantity(
h_in = ScalarAngleOrPixel(
'h_in',
description='The inner full height, in angular or pixel units.')
h_out = AngleOrPixelScalarQuantity(
h_out = ScalarAngleOrPixel(
'h_out',
description='The outer full height, in angular or pixel units.')
theta = ScalarAngle(
Expand Down

0 comments on commit d61630e

Please sign in to comment.