Skip to content

Commit

Permalink
add collection tests + doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Reep committed Aug 12, 2024
1 parent f0c0dc6 commit 66311a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
32 changes: 29 additions & 3 deletions fiasco/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,19 @@ def radiative_loss(self, density: u.cm**(-3), **kwargs) -> u.Unit('erg cm3 s-1')

@u.quantity_input
def radiative_loss_bound_bound(self, density, **kwargs) -> u.Unit('erg cm3 s-1'):
"""
r"""
Calculate the radiative loss rate from bound-bound emission (line emission)
integrated over wavelength.
Parameters
----------
density : `~astropy.units.Quantity`
Electron number density
Returns
-------
rad_loss : `~astropy.units.Quantity`
The bolometric bound-bound radiative loss rate per unit emission measure
"""
density = np.atleast_1d(density)
rad_loss = u.Quantity(np.zeros(self.temperature.shape + density.shape), 'erg cm^3 s^-1')
Expand All @@ -351,7 +363,14 @@ def radiative_loss_bound_bound(self, density, **kwargs) -> u.Unit('erg cm3 s-1')

@u.quantity_input
def radiative_loss_free_free(self) -> u.Unit('erg cm3 s-1'):
"""
r"""
Calculate the radiative loss rate from free-free emission (bremsstrahlung)
integrated over wavelength.
Returns
-------
rad_loss : `~astropy.units.Quantity`
The bolometric free-free radiative loss rate per unit emission measure
"""
free_free = u.Quantity(np.zeros(self.temperature.shape), 'erg cm^3 s^-1')
for ion in self:
Expand All @@ -368,7 +387,14 @@ def radiative_loss_free_free(self) -> u.Unit('erg cm3 s-1'):

@u.quantity_input
def radiative_loss_free_bound(self) -> u.Unit('erg cm3 s-1'):
"""
r"""
Calculate the radiative loss rate from free-bound emission (collisional recombination)
integrated over wavelength.
Returns
-------
rad_loss : `~astropy.units.Quantity`
The bolometric free-bound radiative loss rate per unit emission measure
"""
free_bound = u.Quantity(np.zeros(self.temperature.shape), 'erg cm^3 s^-1')
for ion in self:
Expand Down
28 changes: 28 additions & 0 deletions fiasco/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,34 @@ def test_radiative_loss(collection, hdf5_dbase_root):
# These values have not been checked for correctness
u.allclose(rl[0], [3.90235371e-24, 4.06540902e-24, 4.08411295e-24] * u.erg * u.cm**3 / u.s)

@pytest.mark.requires_dbase_version('>= 8')
def test_radiative_loss_bound_bound(collection, hdf5_dbase_root):
# add Li III to the test to include an ion that throws a MissingDatasetException
collection = collection + fiasco.Ion('Li III', collection.temperature, hdf5_dbase_root=hdf5_dbase_root)
density = [1e9,1e10,1e11] * u.cm**-3
rl = collection.radiative_loss_bound_bound(density)
assert rl.shape == (len(temperature), len(density))
# These values have not been checked for correctness
u.allclose(rl[0], [3.90235371e-24, 4.06540902e-24, 4.08411295e-24] * u.erg * u.cm**3 / u.s)

@pytest.mark.requires_dbase_version('>=8')
def test_radiative_loss_free_free(collection, hdf5_dbase_root):
# add Li III to the test to include an ion that throws a MissingDatasetException
collection = collection + fiasco.Ion('Li III', collection.temperature, hdf5_dbase_root=hdf5_dbase_root)
rl = collection.radiative_loss_free_free()
assert rl.shape == collection.temperature.shape

Check warning on line 149 in fiasco/tests/test_collections.py

View check run for this annotation

Codecov / codecov/patch

fiasco/tests/test_collections.py#L147-L149

Added lines #L147 - L149 were not covered by tests
# This value has not been checked for correctness
u.isclose(rl[0], 2.72706455e-35 * u.erg * u.cm**3 / u.s)

Check warning on line 151 in fiasco/tests/test_collections.py

View check run for this annotation

Codecov / codecov/patch

fiasco/tests/test_collections.py#L151

Added line #L151 was not covered by tests

@pytest.mark.requires_dbase_version('>=8')
def test_radiative_loss_free_bound(collection, hdf5_dbase_root):
# add Li III to the test to include an ion that throws a MissingDatasetException
collection = collection + fiasco.Ion('Li III', collection.temperature, hdf5_dbase_root=hdf5_dbase_root)
rl = collection.radiative_loss_free_bound()
assert rl.shape == collection.temperature.shape

Check warning on line 158 in fiasco/tests/test_collections.py

View check run for this annotation

Codecov / codecov/patch

fiasco/tests/test_collections.py#L156-L158

Added lines #L156 - L158 were not covered by tests
# This value has not been checked for correctness
u.isclose(rl[0], 1.13808317e-33 * u.erg * u.cm**3 / u.s)

Check warning on line 160 in fiasco/tests/test_collections.py

View check run for this annotation

Codecov / codecov/patch

fiasco/tests/test_collections.py#L160

Added line #L160 was not covered by tests

@pytest.mark.requires_dbase_version('>= 8')
def test_spectrum(hdf5_dbase_root):
i1 = fiasco.Ion('H 1', 1 * u.MK, hdf5_dbase_root=hdf5_dbase_root)
Expand Down

0 comments on commit 66311a9

Please sign in to comment.