Skip to content

Commit

Permalink
Adding in more tests - and correcting code so they work
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Apr 26, 2017
1 parent afb5a43 commit 2a37983
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dust_extinction/dust_extinction_averages.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ class G03_SMCBar(BaseExtAve):

x_range = x_range_G03

Rv = 2.74

obsdata_x = np.array([0.455, 0.606, 0.800,
1.235, 1.538,
1.818, 2.273, 2.703,
Expand Down Expand Up @@ -361,6 +363,8 @@ class G03_LMCAvg(BaseExtAve):

x_range = x_range_G03

Rv = 3.41

obsdata_x = np.array([0.455, 0.606, 0.800,
1.818, 2.273, 2.703,
3.375, 3.625, 3.875,
Expand Down Expand Up @@ -469,6 +473,8 @@ class G03_LMC2(BaseExtAve):

x_range = x_range_G03

Rv = 2.76

obsdata_x = np.array([0.455, 0.606, 0.800,
1.818, 2.273, 2.703,
3.375, 3.625, 3.875,
Expand Down
31 changes: 31 additions & 0 deletions dust_extinction/tests/test_g03.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def test_invalid_micron(x_invalid_angstrom, tmodel):
+ str(tmodel.x_range[1]) \
+ ', x has units 1/micron]'

@pytest.mark.parametrize("tmodel", models)
def test_extinguish_no_av_or_ebv(tmodel):
with pytest.raises(InputParameterError) as exc:
tmodel.extinguish([1.0])
assert exc.value.args[0] == 'neither Av or Ebv passed, one required'

@pytest.mark.parametrize("tmodel", models)
def test_extinction_G03_values(tmodel):
# test
Expand All @@ -72,3 +78,28 @@ def test_extinction_G03_single_values(tmodel):
for x, cor_val in zip(tmodel.obsdata_x, tmodel.obsdata_axav):
np.testing.assert_allclose(tmodel(x), cor_val, rtol=6e-02)

@pytest.mark.parametrize("tmodel", models)
def test_extinction_G03_extinguish_values_Av(tmodel):
cor_vals = tmodel.obsdata_axav

# calculate the cor_vals in fractional units
Av = 1.0
cor_vals = np.power(10.0,-0.4*(cor_vals*Av))

# test
np.testing.assert_allclose(tmodel.extinguish(tmodel.obsdata_x, Av=Av),
cor_vals, atol=0.01)

@pytest.mark.parametrize("tmodel", models)
def test_extinction_G03_extinguish_values_Ebv(tmodel):
cor_vals = tmodel.obsdata_axav

# calculate the cor_vals in fractional units
Ebv = 1.0
Av = Ebv*tmodel.Rv
cor_vals = np.power(10.0,-0.4*(cor_vals*Av))

# test
np.testing.assert_allclose(tmodel.extinguish(tmodel.obsdata_x, Ebv=Ebv),
cor_vals, atol=0.01)

0 comments on commit 2a37983

Please sign in to comment.