Skip to content

Commit d5a6ac1

Browse files
authored
Merge pull request #7936 from astrofrog/avoid-stats-import
Avoid importing astropy.stats for astropy.modeling
2 parents 66c7967 + fd809c5 commit d5a6ac1

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎astropy/modeling/functional_models.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
ModelDefinitionError)
1212
from .parameters import Parameter, InputParameterError
1313
from .utils import ellipse_extent
14-
from ..stats.funcs import gaussian_sigma_to_fwhm
1514
from .. import units as u
1615
from ..units import Quantity, UnitsError
1716

@@ -25,6 +24,11 @@
2524
TWOPI = 2 * np.pi
2625
FLOAT_EPSILON = float(np.finfo(np.float32).tiny)
2726

27+
# Note that we define this here rather than using the value defined in
28+
# astropy.stats to avoid importing astropy.stats every time astropy.modeling
29+
# is loaded.
30+
GAUSSIAN_SIGMA_TO_FWHM = 2.0 * np.sqrt(2.0 * np.log(2.0))
31+
2832

2933
class Gaussian1D(Fittable1DModel):
3034
"""
@@ -150,7 +154,7 @@ def bounding_box(self, factor=5.5):
150154
@property
151155
def fwhm(self):
152156
"""Gaussian full width at half maximum."""
153-
return self.stddev * gaussian_sigma_to_fwhm
157+
return self.stddev * GAUSSIAN_SIGMA_TO_FWHM
154158

155159
@staticmethod
156160
def evaluate(x, amplitude, mean, stddev):
@@ -314,12 +318,12 @@ def __init__(self, amplitude=amplitude.default, x_mean=x_mean.default,
314318
@property
315319
def x_fwhm(self):
316320
"""Gaussian full width at half maximum in X."""
317-
return self.x_stddev * gaussian_sigma_to_fwhm
321+
return self.x_stddev * GAUSSIAN_SIGMA_TO_FWHM
318322

319323
@property
320324
def y_fwhm(self):
321325
"""Gaussian full width at half maximum in Y."""
322-
return self.y_stddev * gaussian_sigma_to_fwhm
326+
return self.y_stddev * GAUSSIAN_SIGMA_TO_FWHM
323327

324328
def bounding_box(self, factor=5.5):
325329
"""

‎astropy/modeling/tests/test_functional_models.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
HAS_SCIPY = False
1919

2020

21+
def test_sigma_constant():
22+
"""
23+
Test that the GAUSSIAN_SIGMA_TO_FWHM constant matches the
24+
gaussian_sigma_to_fwhm constant in astropy.stats. We define
25+
it manually in astropy.modeling to avoid importing from
26+
astropy.stats.
27+
"""
28+
from ...stats.funcs import gaussian_sigma_to_fwhm
29+
from ..functional_models import GAUSSIAN_SIGMA_TO_FWHM
30+
assert gaussian_sigma_to_fwhm == GAUSSIAN_SIGMA_TO_FWHM
31+
32+
2133
def test_Trapezoid1D():
2234
"""Regression test for https://github.com/astropy/astropy/issues/1721"""
2335

0 commit comments

Comments
 (0)