diff --git a/photutils/aperture/attributes.py b/photutils/aperture/attributes.py index 242a464de..ba1713d45 100644 --- a/photutils/aperture/attributes.py +++ b/photutils/aperture/attributes.py @@ -9,7 +9,7 @@ import numpy as np __all__ = ['ApertureAttribute', 'PixelPositions', 'SkyCoordPositions', - 'Scalar', 'PositiveScalar', 'AngleOrPixelScalarQuantity'] + 'Scalar', 'PositiveScalar', 'ScalarAngle', 'ScalarAngleOrPixel'] class ApertureAttribute: @@ -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): @@ -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') diff --git a/photutils/aperture/circle.py b/photutils/aperture/circle.py index 493f00385..d0da66a19 100644 --- a/photutils/aperture/circle.py +++ b/photutils/aperture/circle.py @@ -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 @@ -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.') @@ -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.') diff --git a/photutils/aperture/ellipse.py b/photutils/aperture/ellipse.py index f4b7ffe09..4dc30d6ca 100644 --- a/photutils/aperture/ellipse.py +++ b/photutils/aperture/ellipse.py @@ -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 @@ -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( @@ -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( diff --git a/photutils/aperture/rectangle.py b/photutils/aperture/rectangle.py index 398db667e..3ee7912f3 100644 --- a/photutils/aperture/rectangle.py +++ b/photutils/aperture/rectangle.py @@ -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 @@ -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( @@ -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(