Skip to content

Commit

Permalink
Added lbl_opacity_sampling parameter to ReadRadtrans, adding and extr…
Browse files Browse the repository at this point in the history
…acting res_mode and lbl_opacity_sampling parameters from database
  • Loading branch information
tomasstolker committed Jul 24, 2023
1 parent 20ec5c1 commit 2209239
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
26 changes: 26 additions & 0 deletions species/data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,16 @@ def add_retrieval(
else:
dset.attrs["abund_nodes"] = radtrans["abund_nodes"]

if "res_mode" in radtrans:
dset.attrs["res_mode"] = radtrans["res_mode"]
else:
dset.attrs["res_mode"] = "c-k"

if "lbl_opacity_sampling" in radtrans:
dset.attrs["lbl_opacity_sampling"] = radtrans["lbl_opacity_sampling"]
else:
dset.attrs["lbl_opacity_sampling"] = None

print(" [DONE]")

# Set number of pressures
Expand Down Expand Up @@ -3797,6 +3807,20 @@ def get_retrieval_spectra(
for i in range(n_cloud_species):
cloud_species.append(dset.attrs[f"cloud_species{i}"])

# Get resolution mode

if "res_mode" in dset.attrs:
res_mode = dset.attrs["res_mode"]
else:
res_mode = "c-k"

# High-resolution downsampling factor

if "lbl_opacity_sampling" in dset.attrs:
lbl_opacity_sampling = dset.attrs["lbl_opacity_sampling"]
else:
lbl_opacity_sampling = None

# Create an instance of ReadRadtrans
# Afterwards, the names of the cloud_species have been shortened
# from e.g. 'MgSiO3(c)_cd' to 'MgSiO3(c)'
Expand All @@ -3809,6 +3833,8 @@ def get_retrieval_spectra(
pressure_grid=pressure_grid,
cloud_wavel=cloud_wavel,
max_press=max_press,
res_mode=res_mode,
lbl_opacity_sampling=lbl_opacity_sampling,
)

# Set quenching attribute such that the parameter of get_model is not required
Expand Down
12 changes: 12 additions & 0 deletions species/read/read_radtrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
cloud_wavel: Optional[Tuple[float, float]] = None,
max_press: float = None,
pt_manual: Optional[np.ndarray] = None,
lbl_opacity_sampling: Optional[Union[int, np.int_]] = None,
) -> None:
"""
Parameters
Expand Down Expand Up @@ -102,6 +103,15 @@ def __init__(
be (n_pressure, 2), with pressure (bar) as first column
and temperature (K) as second column. It is recommended
that the pressures are logarithmically spaced.
lbl_opacity_sampling : int, None
This is the same parameter as in ``petitRADTRANS`` which is
used with ``res_mode='lbl'`` to downsample the line-by-line
opacities by selecting every ``lbl_opacity_sampling``-th
wavelength from the original sampling of
:math:`\\lambda/\\Delta \\lambda = 10^6`. Setting this
parameter will lower the computation time. By setting the
argument to ``None``, the original sampling is used so no
downsampling is applied.
Returns
-------
Expand All @@ -117,6 +127,7 @@ def __init__(
self.pressure_grid = pressure_grid
self.cloud_wavel = cloud_wavel
self.pt_manual = pt_manual
self.lbl_opacity_sampling = lbl_opacity_sampling

# Set maximum pressure

Expand Down Expand Up @@ -205,6 +216,7 @@ def __init__(
mode=res_mode,
test_ck_shuffle_comp=self.scattering,
do_scat_emis=self.scattering,
lbl_opacity_sampling=lbl_opacity_sampling,
)

# Setup the opacity arrays
Expand Down

0 comments on commit 2209239

Please sign in to comment.