Skip to content

Commit 4539f17

Browse files
authored
Merge branch 'wtbarnes:main' into main
2 parents 522f3b2 + c015fe1 commit 4539f17

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

fiasco/ions.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ def _instance_kwargs(self):
143143
kwargs['abundance'] = self.abundance
144144
return kwargs
145145

146+
def _has_dataset(self, dset_name):
147+
# There are some cases where we need to check for the existence of a dataset
148+
# within a function as opposed to checking for the existence of that dataset
149+
# before entering the function using the decorator approach.
150+
try:
151+
needs_dataset(dset_name)(lambda _: None)(self)
152+
except MissingDatasetException:
153+
return False
154+
else:
155+
return True
156+
146157
def next_ion(self):
147158
"""
148159
Return an `~fiasco.Ion` instance with the next highest ionization stage.
@@ -1409,13 +1420,7 @@ def free_bound(self,
14091420
wavelength = np.atleast_1d(wavelength)
14101421
prefactor = (2/np.sqrt(2*np.pi)/(const.h*(const.c**3) * (const.m_e * const.k_B)**(3/2)))
14111422
recombining = self.next_ion()
1412-
try:
1413-
# NOTE: This checks whether the fblvl data is available for the
1414-
# recombining ion
1415-
needs_dataset('fblvl')(lambda _: None)(recombining)
1416-
omega_0 = recombining._fblvl['multiplicity'][0]
1417-
except MissingDatasetException:
1418-
omega_0 = 1.0
1423+
omega_0 = recombining._fblvl['multiplicity'][0] if recombining._has_dataset('fblvl') else 1.0
14191424
E_photon = const.h * const.c / wavelength
14201425
energy_temperature_factor = np.outer(self.temperature**(-3/2), E_photon**5)
14211426
# Fill in observed energies with theoretical energies

fiasco/tests/test_ion.py

+9
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,12 @@ def test_new_instance_abundance_preserved_string(ion):
423423
new_ion = ion._new_instance()
424424
assert u.allclose(new_ion.abundance, 2.818382931264455e-05)
425425
assert new_ion._dset_names['abundance'] == 'sun_photospheric_2007_grevesse'
426+
427+
428+
def test_has_dataset(ion, c6):
429+
# Fe 5 has energy level data
430+
assert ion._has_dataset('elvlc')
431+
# Fe 5 has no proton data
432+
assert not ion._has_dataset('psplups')
433+
# C VI has no dielectronic data
434+
assert not c6._has_dataset('dielectronic_elvlc')

0 commit comments

Comments
 (0)