Skip to content

Commit

Permalink
Generalized the implementation of the mean_molecular_weight function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstolker committed Jul 23, 2023
1 parent d517148 commit 20ec5c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
9 changes: 9 additions & 0 deletions species/data/model_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def add_model_grid(
"be downloaded and added to the HDF5 database."
)

elif model_name == "exo-rem-highres" and teff_range is None:
warnings.warn(
"Adding the full high-resolution grid of Exo-Rem to the "
"HDF5 database may not be feasible since it requires "
"a large amount of memory. Please consider using the "
"'teff_range' parameter to only add a small "
"Teff range of model spectra to the database."
)

if not os.path.exists(input_path):
os.makedirs(input_path)

Expand Down
3 changes: 3 additions & 0 deletions species/util/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ def convert_model_name(in_name: str) -> str:
elif in_name == "exo-rem":
out_name = "Exo-REM"

elif in_name == "exo-rem-highres":
out_name = "Exo-REM"

elif in_name == "planck":
out_name = "Blackbody radiation"

Expand Down
26 changes: 6 additions & 20 deletions species/util/retrieval_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1711,16 +1711,15 @@ def calc_metal_ratio(


@typechecked
def mean_molecular_weight(abundances: Dict[str, float]) -> float:
def mean_molecular_weight(mass_frac: Dict[str, float]) -> float:
"""
Function to calculate the mean molecular weight from a
dictionary with mass fractions.
Parameters
----------
abundances : dict
mass_frac : dict
Dictionary with the mass fraction of each species.
Keys should be the line species, always ending with "_0".
Returns
-------
Expand All @@ -1731,24 +1730,11 @@ def mean_molecular_weight(abundances: Dict[str, float]) -> float:
masses = atomic_masses()
mmw_sum = 0.0

for abund_item in abundances:
if abund_item in ["CO_all_iso", "CO_all_iso_HITEMP", "CO_all_iso_Chubb"]:
mmw_sum += abundances[abund_item] / masses["CO"]

elif abund_item in ["Na_lor_cut", "Na_allard", "Na_burrows"]:
mmw_sum += abundances[abund_item] / masses["Na"]

elif abund_item in ["K_lor_cut", "K_allard", "K_burrows"]:
mmw_sum += abundances[abund_item] / masses["K"]

elif abund_item == "CH4_main_iso":
mmw_sum += abundances[abund_item] / masses["CH4"]

elif abund_item in ["H2O_main_iso", "H2O_HITEMP"]:
mmw_sum += abundances[abund_item] / masses["H2O"]

for abund_item in mass_frac:
if "_" in abund_item:
mmw_sum += mass_frac[abund_item] / masses[abund_item.split("_")[0]]
else:
mmw_sum += abundances[abund_item] / masses[abund_item]
mmw_sum += mass_frac[abund_item] / masses[abund_item]

return 1.0 / mmw_sum

Expand Down

0 comments on commit 20ec5c1

Please sign in to comment.