File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,17 @@ def _instance_kwargs(self):
143
143
kwargs ['abundance' ] = self .abundance
144
144
return kwargs
145
145
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
+
146
157
def next_ion (self ):
147
158
"""
148
159
Return an `~fiasco.Ion` instance with the next highest ionization stage.
@@ -1409,13 +1420,7 @@ def free_bound(self,
1409
1420
wavelength = np .atleast_1d (wavelength )
1410
1421
prefactor = (2 / np .sqrt (2 * np .pi )/ (const .h * (const .c ** 3 ) * (const .m_e * const .k_B )** (3 / 2 )))
1411
1422
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
1419
1424
E_photon = const .h * const .c / wavelength
1420
1425
energy_temperature_factor = np .outer (self .temperature ** (- 3 / 2 ), E_photon ** 5 )
1421
1426
# Fill in observed energies with theoretical energies
Original file line number Diff line number Diff line change @@ -423,3 +423,12 @@ def test_new_instance_abundance_preserved_string(ion):
423
423
new_ion = ion ._new_instance ()
424
424
assert u .allclose (new_ion .abundance , 2.818382931264455e-05 )
425
425
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' )
You can’t perform that action at this time.
0 commit comments