Skip to content

Commit

Permalink
add some small tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwreep committed Sep 21, 2024
1 parent af55bc0 commit 97c2b19
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fiasco/gaunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def free_free_integrated(self, temperature: u.K, charge_state, use_itoh=False) -
gf_itoh = self._free_free_itoh_integrated(temperature, charge_state)
gf = np.where(np.isnan(gf_itoh), gf, gf_itoh)
return gf

@needs_dataset('gffint')
@u.quantity_input
def _free_free_sutherland_integrated(self, temperature: u.K, charge_state) -> u.dimensionless_unscaled:
Expand Down
2 changes: 1 addition & 1 deletion fiasco/ions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ def free_free_radiative_loss(self, use_itoh=False) -> u.erg * u.cm**3 / u.s:
wavelength-integrated free-free Gaunt factor. The prefactor :math:`F_{k}`
is defined in Equation 19 of :cite:t:`sutherland_accurate_1998`, with a value
of :math:`F_k\approx1.42555669\times10^{-27}\,\mathrm{cm}^{5}\,\mathrm{g}\,\mathrm{K}^{-1/2}\,\mathrm{s}^{3}`.
Parameters
----------
use_itoh : `bool`, optional
Expand Down
6 changes: 3 additions & 3 deletions fiasco/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_radiative_loss_bound_bound(collection, hdf5_dbase_root):

@pytest.mark.requires_dbase_version('>= 8')
@pytest.mark.parametrize(('index','expected'),
[(0, 2.72706455e-35),
[(0, 2.72706455e-35),
(75, 5.59153955e-31),])
def test_radiative_loss_free_free(collection, index, expected):
rl = collection.free_free_radiative_loss()
Expand All @@ -153,11 +153,11 @@ def test_radiative_loss_free_free(collection, index, expected):

@pytest.mark.requires_dbase_version('>= 9.0.1')
@pytest.mark.parametrize(('index','expected'),
[(0, 2.71800458e-35),
[(0, 2.71800458e-35),
(75, 5.57346003e-31),])
def test_radiative_loss_free_free_itoh(collection, index, expected):
"""
For database versions >= 9.0.1, the Itoh Gaunt factors give a different
For database versions >= 9.0.1, the Itoh Gaunt factors give a different
result for the free-free radiative loss.
"""
rl = collection.free_free_radiative_loss(use_itoh=True)
Expand Down
7 changes: 6 additions & 1 deletion fiasco/tests/test_gaunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ def test_gaunt_factor_free_free_integrated_itoh(gaunt_factor, charge_state, inde
# This value has not been tested for correctness
assert u.allclose(gf[index], expected * u.dimensionless_unscaled)

def test_gaunt_factor_free_bound_integrated(ion):
def test_gaunt_factor_free_bound_nl_missing(gaunt_factor):
#test cases where n or l is not in the klgfb data
assert u.isclose(gaunt_factor.free_bound(0.5, 10, 1), 1.0 * u.dimensionless_unscaled)

def test_gaunt_factor_free_bound_integrated(gaunt_factor, ion):
ion_gf_0 = ion.gaunt_factor.free_bound_integrated(ion.temperature, ion.atomic_number, ion.charge_state, ion.previous_ion()._fblvl['n'][0], ion.previous_ion().ip, ground_state=True)
ion_gf_1 = ion.gaunt_factor.free_bound_integrated(ion.temperature, ion.atomic_number, ion.charge_state, ion.previous_ion()._fblvl['n'][0], ion.previous_ion().ip, ground_state=False)
assert ion_gf_0.shape == ion.temperature.shape
assert u.allclose(gaunt_factor.free_bound_integrated(temperature, 1, 0, 1, 13.6*u.eV), 0.0 * u.dimensionless_unscaled)
# These values have not been tested for correctness
assert u.isclose(ion_gf_0[20], 55.18573076316151 * u.dimensionless_unscaled)
assert u.isclose(ion_gf_1[20], 11.849092513590998 * u.dimensionless_unscaled)
Expand Down
6 changes: 3 additions & 3 deletions fiasco/tests/test_ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_free_free(ion):
assert u.allclose(emission[0], 1.72804216e-29 * u.cm**3 * u.erg / u.Angstrom / u.s)

@pytest.mark.parametrize(('index','expected'),
[(0, 1.79093013e-22),
[(0, 1.79093013e-22),
(75, 3.06577525e-21), ])
def test_free_free_radiative_loss(h1, fe20, index, expected):
assert fe20.free_free_radiative_loss().shape == fe20.temperature.shape
Expand All @@ -350,11 +350,11 @@ def test_free_free_radiative_loss(h1, fe20, index, expected):

@pytest.mark.requires_dbase_version('>= 9.0.1')
@pytest.mark.parametrize(('index','expected'),
[(0, 1.79093013e-22),
[(0, 1.79093013e-22),
(75, 3.05628894e-21), ])
def test_free_free_radiative_loss_itoh(h1, fe20, index, expected):
"""
For database versions >= 9.0.1, the Itoh Gaunt factors give a different
For database versions >= 9.0.1, the Itoh Gaunt factors give a different
result for the free-free radiative loss at temperature > 1 MK.
"""
assert fe20.free_free_radiative_loss(use_itoh=True).shape == fe20.temperature.shape
Expand Down

0 comments on commit 97c2b19

Please sign in to comment.