Skip to content

Commit

Permalink
Merge 87e446d into 2d3fa6d
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Jan 15, 2019
2 parents 2d3fa6d + 87e446d commit bf6e553
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 81 deletions.
11 changes: 2 additions & 9 deletions dust_extinction/averages.py
Expand Up @@ -2,9 +2,7 @@

import numpy as np

import astropy.units as u

from .helpers import _test_valid_x_range
from .helpers import (_get_x_in_wavenumbers, _test_valid_x_range)
from .baseclasses import BaseExtAveModel
from .shapes import (P92, _curve_F99_method)

Expand Down Expand Up @@ -640,13 +638,8 @@ def evaluate(self, in_x):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)
x = _get_x_in_wavenumbers(in_x)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_GCC09, 'GCC09')

Expand Down
34 changes: 33 additions & 1 deletion dust_extinction/helpers.py
@@ -1,8 +1,40 @@
from __future__ import (absolute_import, print_function, division)

import warnings

import numpy as np
import astropy.units as u

__all__ = ['_get_x_in_wavenumbers', '_test_valid_x_range']


def _get_x_in_wavenumbers(in_x):
"""
Convert input x to wavenumber given x has units.
Otherwise, assume x is in waveneumbers and issue a warning to this effect.
Parameters
----------
in_x : astropy.quantity or simple floats
x values
Returns
-------
x : floats
input x values in wavenumbers w/o units
"""
# check if in_x is an astropy quantity, if not issue a warning
if not isinstance(in_x, u.Quantity):
warnings.warn("x has no units, assuming x units are inverse microns")

# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

__all__ = ['_test_valid_x_range']
# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
return x_quant.value


def _test_valid_x_range(x, x_range, outname):
Expand Down
40 changes: 5 additions & 35 deletions dust_extinction/parameter_averages.py
Expand Up @@ -3,10 +3,8 @@
import numpy as np
from scipy import interpolate

import astropy.units as u

from .baseclasses import (BaseExtRvModel, BaseExtRvAfAModel)
from .helpers import _test_valid_x_range
from .helpers import (_get_x_in_wavenumbers, _test_valid_x_range)
from .averages import G03_SMCBar
from .shapes import _curve_F99_method

Expand Down Expand Up @@ -93,14 +91,7 @@ def evaluate(in_x, Rv):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_CCM89, 'CCM89')
Expand Down Expand Up @@ -224,14 +215,7 @@ def evaluate(in_x, Rv):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_O94, 'O94')
Expand Down Expand Up @@ -622,14 +606,7 @@ def evaluate(self, in_x, Rv):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_M14, 'M14')
Expand Down Expand Up @@ -834,14 +811,7 @@ def evaluate(in_x, RvA, fA):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_G16, 'G16')
Expand Down
30 changes: 4 additions & 26 deletions dust_extinction/shapes.py
Expand Up @@ -3,10 +3,9 @@
import numpy as np
from scipy import interpolate

import astropy.units as u
from astropy.modeling import (Fittable1DModel, Parameter)

from .helpers import _test_valid_x_range
from .helpers import (_get_x_in_wavenumbers, _test_valid_x_range)

__all__ = ['FM90', 'P92']

Expand Down Expand Up @@ -66,14 +65,7 @@ def _curve_F99_method(in_x, Rv,
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, valid_x_range, model_name)
Expand Down Expand Up @@ -242,14 +234,7 @@ def evaluate(in_x, C1, C2, C3, C4, xo, gamma):
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_FM90, 'FM90')
Expand Down Expand Up @@ -563,14 +548,7 @@ def evaluate(self, in_x,
ValueError
Input x values outside of defined range
"""
# convert to wavenumbers (1/micron) if x input in units
# otherwise, assume x in appropriate wavenumber units
with u.add_enabled_equivalencies(u.spectral()):
x_quant = u.Quantity(in_x, 1.0/u.micron, dtype=np.float64)

# strip the quantity to avoid needing to add units to all the
# polynomical coefficients
x = x_quant.value
x = _get_x_in_wavenumbers(in_x)

# check that the wavenumbers are within the defined range
_test_valid_x_range(x, x_range_P92, 'P92')
Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_ccm89.py
Expand Up @@ -34,7 +34,7 @@ def test_invalid_micron(x_invalid_micron):

@pytest.mark.parametrize("x_invalid_angstrom",
u.angstrom*1e4/[-1.0, 0.2, 10.1, 100.])
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, CCM89(Rv=3.1), 'CCM89')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_f04.py
Expand Up @@ -26,7 +26,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, F04(), 'F04')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_f99.py
Expand Up @@ -26,7 +26,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, F99(), 'F99')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_fm90.py
Expand Up @@ -28,7 +28,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, FM90(), 'FM90')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_g03.py
Expand Up @@ -31,7 +31,7 @@ def test_invalid_micron(x_invalid_micron, tmodel):

@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
@pytest.mark.parametrize("tmodel", models)
def test_invalid_micron(x_invalid_angstrom, tmodel):
def test_invalid_anstrom(x_invalid_angstrom, tmodel):
_invalid_x_range(x_invalid_angstrom, tmodel, 'G03')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_g16.py
Expand Up @@ -43,7 +43,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, G16(), 'G16')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_gcc09_ave.py
Expand Up @@ -27,7 +27,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, GCC09_MWAvg(), 'GCC09')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_ma14.py
Expand Up @@ -26,7 +26,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, M14(), 'M14')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_o94.py
Expand Up @@ -34,7 +34,7 @@ def test_invalid_micron(x_invalid_micron):

@pytest.mark.parametrize("x_invalid_angstrom",
u.angstrom*1e4/[-1.0, 0.2, 10.1, 100.])
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, O94(Rv=3.1), 'O94')


Expand Down
2 changes: 1 addition & 1 deletion dust_extinction/tests/test_p92.py
Expand Up @@ -26,7 +26,7 @@ def test_invalid_micron(x_invalid_micron):


@pytest.mark.parametrize("x_invalid_angstrom", u.angstrom*1e4/x_bad)
def test_invalid_micron(x_invalid_angstrom):
def test_invalid_angstrom(x_invalid_angstrom):
_invalid_x_range(x_invalid_angstrom, P92(), 'P92')


Expand Down

0 comments on commit bf6e553

Please sign in to comment.