Skip to content

Commit e39dd6f

Browse files
committed
Fix bounding box calculation for Gaussian1D when units are present, and generalize ellipse_extent to work with Quantity objects.
1 parent 34f8179 commit e39dd6f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

astropy/modeling/functional_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def bounding_box(self, factor=5.5):
6464
(-4.0, 4.0)
6565
"""
6666

67-
x0 = self.mean.value
67+
x0 = self.mean
6868
dx = factor * self.stddev
6969

7070
return (x0 - dx, x0 + dx)

astropy/modeling/utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..utils import isiterable, check_broadcast
1818
from ..utils.compat.funcsigs import signature
1919

20+
from .. import units as u
2021

2122
__all__ = ['ExpressionTree', 'AliasDict', 'check_broadcast',
2223
'poly_map_domain', 'comb', 'ellipse_extent']
@@ -520,12 +521,13 @@ def ellipse_extent(a, b, theta):
520521
521522
Parameters
522523
----------
523-
a : float
524+
a : float or `~astropy.units.Quantity`
524525
Major axis.
525-
b : float
526+
b : float or `~astropy.units.Quantity`
526527
Minor axis.
527-
theta : float
528-
Rotation angle in radians.
528+
theta : float or `~astropy.units.Quantity`
529+
Rotation angle. If given as a floating-point value, it is assumed to be
530+
in radians.
529531
530532
Returns
531533
-------
@@ -571,7 +573,10 @@ def ellipse_extent(a, b, theta):
571573
t = np.arctan2(b, a * np.tan(theta))
572574
dy = b * np.sin(t) * np.cos(theta) + a * np.cos(t) * np.sin(theta)
573575

574-
return np.abs([dx, dy])
576+
if isinstance(dx, u.Quantity) or isinstance(dy, u.Quantity):
577+
return np.abs(u.Quantity([dx, dy]))
578+
else:
579+
return np.abs([dx, dy])
575580

576581

577582
def get_inputs_and_params(func):

0 commit comments

Comments
 (0)