diff --git a/fiasco/ions.py b/fiasco/ions.py index 871a2ad1..5c549652 100644 --- a/fiasco/ions.py +++ b/fiasco/ions.py @@ -143,6 +143,17 @@ def _instance_kwargs(self): kwargs['abundance'] = self.abundance return kwargs + def _has_dataset(self, dset_name): + # There are some cases where we need to check for the existence of a dataset + # within a function as opposed to checking for the existence of that dataset + # before entering the function using the decorator approach. + try: + needs_dataset(dset_name)(lambda _: None)(self) + except MissingDatasetException: + return False + else: + return True + def next_ion(self): """ Return an `~fiasco.Ion` instance with the next highest ionization stage. @@ -1409,13 +1420,7 @@ def free_bound(self, wavelength = np.atleast_1d(wavelength) prefactor = (2/np.sqrt(2*np.pi)/(const.h*(const.c**3) * (const.m_e * const.k_B)**(3/2))) recombining = self.next_ion() - try: - # NOTE: This checks whether the fblvl data is available for the - # recombining ion - needs_dataset('fblvl')(lambda _: None)(recombining) - omega_0 = recombining._fblvl['multiplicity'][0] - except MissingDatasetException: - omega_0 = 1.0 + omega_0 = recombining._fblvl['multiplicity'][0] if recombining._has_dataset('fblvl') else 1.0 E_photon = const.h * const.c / wavelength energy_temperature_factor = np.outer(self.temperature**(-3/2), E_photon**5) # Fill in observed energies with theoretical energies diff --git a/fiasco/tests/test_ion.py b/fiasco/tests/test_ion.py index 3a0553d2..e3a6d755 100644 --- a/fiasco/tests/test_ion.py +++ b/fiasco/tests/test_ion.py @@ -423,3 +423,12 @@ def test_new_instance_abundance_preserved_string(ion): new_ion = ion._new_instance() assert u.allclose(new_ion.abundance, 2.818382931264455e-05) assert new_ion._dset_names['abundance'] == 'sun_photospheric_2007_grevesse' + + +def test_has_dataset(ion, c6): + # Fe 5 has energy level data + assert ion._has_dataset('elvlc') + # Fe 5 has no proton data + assert not ion._has_dataset('psplups') + # C VI has no dielectronic data + assert not c6._has_dataset('dielectronic_elvlc')