Skip to content

Commit

Permalink
rearrange if-else logic to be more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
jwreep committed Sep 18, 2024
1 parent 7f48cdc commit 7f17671
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
31 changes: 15 additions & 16 deletions fiasco/gaunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def free_free_total(self, temperature: u.K, charge_state, itoh=False, relativist
charge_state : `int`,
The charge state of the ion
itoh : `bool`, optional
Specify whether to use the approximations specified by :cite:t:`itoh_radiative_2002`.
Specify whether to use the approximations specified by :cite:t:`itoh_radiative_2002`.
If true, use the forms by :cite:t:`itoh_radiative_2002`. If false, use the forms by
:cite:t:`sutherland_accurate_1998`.
relativistic : `bool`, optional
Expand All @@ -176,24 +176,23 @@ def free_free_total(self, temperature: u.K, charge_state, itoh=False, relativist
if charge_state == 0:
return u.Quantity(np.zeros(temperature.shape))
else:
if not itoh:
return self._free_free_sutherland_integrated(temperature, charge_state)
if itoh and relativistic:
return self._free_free_itoh_integrated_relativistic(temperature, charge_state)
elif itoh and not relativistic:
return self._free_free_itoh_integrated_nonrelativistic(temperature, charge_state)
else:
if relativistic:
return self._free_free_itoh_integrated_relativistic(temperature, charge_state)
else:
return self._free_free_itoh_integrated_nonrelativistic(temperature, charge_state)
return self._free_free_sutherland_integrated(temperature, charge_state)

@needs_dataset('gffint')
@u.quantity_input
def _free_free_sutherland_integrated(self, temperature: u.K, charge_state) -> u.dimensionless_unscaled:
"""
The total (wavelength-averaged) free-free Gaunt factor, as specified by :cite:t:`sutherland_accurate_1998`,
in Section 2.4 of that work.
This is the default option used by CHIANTI for integrated free-free Gaunt factor, and we also use it
This is the default option used by CHIANTI for integrated free-free Gaunt factor, and we also use it
where the other versions are not valid.
Parameters
----------
temperature : `~astropy.units.Quantity`
Expand All @@ -213,13 +212,13 @@ def _free_free_sutherland_integrated(self, temperature: u.K, charge_state) -> u.
@needs_dataset('itohintnonrel')
@u.quantity_input
def _free_free_itoh_integrated_nonrelativistic(self, temperature: u.K, charge_state) -> u.dimensionless_unscaled:
"""
r"""
The total (wavelength-averaged) non-relativistic free-free Gaunt factor, as specified by
:cite:t:`itoh_radiative_2002`.
This form is only valid between :math:`-3.0 \leq \log_{10} \gamma^{2} \leq 2.0`. We use the form
specified by :cite:t:`sutherland_accurate_1998` outside of this range.
specified by :cite:t:`sutherland_accurate_1998` outside of this range.
Parameters
----------
temperature : `~astropy.units.Quantity`
Expand All @@ -243,12 +242,12 @@ def _free_free_itoh_integrated_nonrelativistic(self, temperature: u.K, charge_st
@needs_dataset('itohintrel')
@u.quantity_input
def _free_free_itoh_integrated_relativistic(self, temperature: u.K, charge_state) -> u.dimensionless_unscaled:
"""
r"""
The total (wavelength-averaged) relativistic free-free Gaunt factor, as specified by
:cite:t:`itoh_radiative_2002`.
The relativistic approximation is only valid between :math:`6.0 \leq \log_{10} T_{e} \leq 8.5`, and charges between 1 and 28.
At cooler temperatures, the calculation uses the non-relativistic form, while at higher temperatures it defaults back to the
At cooler temperatures, the calculation uses the non-relativistic form, while at higher temperatures it defaults back to the
expressions from :cite:t:`sutherland_accurate_1998`.
Parameters
Expand Down
8 changes: 4 additions & 4 deletions fiasco/io/sources/continuum_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, filename, **kwargs):
def preprocessor(self, table, line, index):
line = line.strip().split()
gf = np.array(line, dtype=float)
table.append([line])
table.append([gf])

def extract_footer(self, *args):
return """Fit parameters for relativistic free-free Gaunt factors integrated over frequency.
Expand Down Expand Up @@ -179,7 +179,7 @@ def to_hdf5(self, hf, df, **kwargs):
grp.attrs['footer'] = df.meta['footer']
else:
grp = hf[grp_name]

for name in df.colnames:
col = df[name]
if type(col) == u.Quantity:
Expand All @@ -199,8 +199,8 @@ def to_hdf5(self, hf, df, **kwargs):
ds = grp.create_dataset(name, data=data, dtype=data.dtype)
ds.attrs['unit'] = col.unit.to_string()
ds.attrs['description'] = df.meta['descriptions'][name]


class KlgfbParser(GenericParser):
"""
Free-bound gaunt factor as a function of photon energy for several different energy levels.
Expand Down

0 comments on commit 7f17671

Please sign in to comment.