Skip to content

Commit

Permalink
Added additional tests using units on input wavenumber or wavelength
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Mar 5, 2017
1 parent 0b3adce commit 37b8521
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
12 changes: 10 additions & 2 deletions dust_extinction/dust_extinction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

__all__ = ['CCM89']

x_range_CCM89 = [0.3,10.0]

class CCM89(Model):
"""
CCM89 extinction model calculation
Expand Down Expand Up @@ -57,6 +59,7 @@ class CCM89(Model):
+ "total-to-selective extinction",
default=3.1)
Rv_range = [2.0,6.0]
x_range = x_range_CCM89

@Rv.validator
def Rv(self, value):
Expand Down Expand Up @@ -93,9 +96,14 @@ def evaluate(in_x, Rv):
x = x_quant.value

# check that the wavenumbers are within the defined range
if np.logical_or(np.any(x < 0.3),np.any(x > 10.0)):
if np.logical_or(np.any(x < x_range_CCM89[0]),
np.any(x > x_range_CCM89[1])):
raise ValueError('Input x outside of range defined for CCM89' \
+ ' [0.3 <= x <= 10, x has units 1/micron]')
+ ' ['
+ str(x_range_CCM89[0])
+ ' <= x <= '
+ str(x_range_CCM89[1])
+ ', x has units 1/micron]')

# setup the a & b coefficient vectors
n_x = len(x)
Expand Down
47 changes: 45 additions & 2 deletions dust_extinction/tests/test_ccm89.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,52 @@ def test_invalid_Rv_input(Rv_invalid):
def test_invalid_wavenumbers(x_invalid):
tmodel = CCM89(Rv=3.1)
with pytest.raises(ValueError) as exc:
tmodel([x_invalid])
tmodel(x_invalid)
assert exc.value.args[0] == 'Input x outside of range defined for CCM89' \
+ ' [0.3 <= x <= 10, x has units 1/micron]'
+ ' [' \
+ str(tmodel.x_range[0]) \
+ ' <= x <= ' \
+ str(tmodel.x_range[1]) \
+ ', x has units 1/micron]'

@pytest.mark.parametrize("x_invalid_wavenumber",
[-1.0, 0.2, 10.1, 100.]/u.micron)
def test_invalid_wavenumbers_imicron(x_invalid_wavenumber):
tmodel = CCM89(Rv=3.1)
with pytest.raises(ValueError) as exc:
tmodel(x_invalid_wavenumber)
assert exc.value.args[0] == 'Input x outside of range defined for CCM89' \
+ ' [' \
+ str(tmodel.x_range[0]) \
+ ' <= x <= ' \
+ str(tmodel.x_range[1]) \
+ ', x has units 1/micron]'

@pytest.mark.parametrize("x_invalid_micron",
u.micron/[-1.0, 0.2, 10.1, 100.])
def test_invalid_micron(x_invalid_micron):
tmodel = CCM89(Rv=3.1)
with pytest.raises(ValueError) as exc:
tmodel(x_invalid_micron)
assert exc.value.args[0] == 'Input x outside of range defined for CCM89' \
+ ' [' \
+ str(tmodel.x_range[0]) \
+ ' <= x <= ' \
+ str(tmodel.x_range[1]) \
+ ', x has units 1/micron]'

@pytest.mark.parametrize("x_invalid_angstrom",
u.angstrom*1e4/[-1.0, 0.2, 10.1, 100.])
def test_invalid_micron(x_invalid_angstrom):
tmodel = CCM89(Rv=3.1)
with pytest.raises(ValueError) as exc:
tmodel(x_invalid_angstrom)
assert exc.value.args[0] == 'Input x outside of range defined for CCM89' \
+ ' [' \
+ str(tmodel.x_range[0]) \
+ ' <= x <= ' \
+ str(tmodel.x_range[1]) \
+ ', x has units 1/micron]'

@pytest.mark.parametrize("Rv", [2.0, 3.0, 3.1, 4.0, 5.0, 6.0])
def test_extinction_CCM89_values(Rv):
Expand Down

0 comments on commit 37b8521

Please sign in to comment.