Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ PySME documentation
More than two decades ago `Valenti & Piskunov (1996) <https://ui.adsabs.harvard.edu/abs/1996A&AS..118..595V>`_ developed SME – Spectroscopy Made Easy, a high-precision stellar-spectra synthesis/analysis engine that has powered hundreds of studies.
PySME is its modern Python front-end: a wrapper around the original C++/Fortran core that lets you (1) compute accurate, high-resolution synthetic spectra from a linelist + model atmosphere, (2) invert observed spectra to derive stellar parameters, and (3) explore NLTE corrections — all from an interactive notebook or scripted pipeline. The same capabilities make PySME invaluable for exoplanet work, where characterising the host star is essential for understanding its planets.

🎉 PySME (version 0.6.14+) is now fully compatible with the arm64 MacOS! Feel free to try it out. 🎉

.. admonition:: Key features

* Plane-parallel and spherical radiative-transfer engine
Expand Down
31 changes: 20 additions & 11 deletions src/pysme/abund.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,19 @@ def fromtype(pattern, fromtype, raw=False):
if np.isnan(abund[0]):
raise ValueError("Pattern must define abundance of H")

# print(abund)

type = fromtype.lower()
if type == "h=12":
pass
elif type == "sme":
# sme -> H=12
abund[1:] += 12 - np.log10(abund[0])
abund[0] = 12
elif type == "kurucz":
# kurucz -> H=12
abund[2:] = abund[2:] + np.log10(abund[1] / abund[0] + 1) + 12
abund[1] = np.log10(abund[1]/abund[0]) + 12
abund[2:] += 12 - np.log10(abund[0])
abund[0] = 12
elif type == "n/ntot":
abund /= abund[0]
Expand All @@ -580,16 +587,17 @@ def fromtype(pattern, fromtype, raw=False):
"got abundance type '{}',".format(type)
+ " should be 'H=12', 'n/nH', 'n/nTot', 'n/nFe', 'Fe=12', or 'sme'"
)

if raw:
return abund
else:
return {el: abund[elements_dict[el]] for el in elements}

@staticmethod
def totype(pattern, totype, raw=False, copy=True):
def totype(pattern, totype, raw=False, copy=True, X=None):
"""Return a copy of the input abundance pattern, transformed from
the 'H=12' type to the output type. Valid abundance pattern types
are 'sme', 'n/nTot', 'n/nH', and 'H=12'.
are 'sme', 'kurucz', 'n/nTot', 'n/nH', and 'H=12'.
"""
if isinstance(pattern, dict):
abund = [pattern[el] if el in pattern.keys() else np.nan for el in elements]
Expand All @@ -604,12 +612,13 @@ def totype(pattern, totype, raw=False, copy=True):
if type == "h=12":
pass
elif type == "sme":
abund2 = 10 ** (abund - 12)
abund[0] = 1 / np.nansum(abund2)
abund[1] = 10**(abund[1] - 12) * abund[0]
abund[2:] = abund[2:] - 12 + np.log10(abund[0])
# abund /= np.sum(abund)
# abund[1:] = np.log10(abund[1:])
abund[0] = 1 / (1 + np.nansum(10**(abund[1:]-12)))
abund[1:] = np.log10(abund[0] * 10**(abund[1:] - 12))
elif type == "kurucz":
# H=12 -> kurucz
abund[0] = 1 / (1 + np.nansum(10**(abund[1:] - 12)))
abund[1] = 1 / (10**(12-abund[1]) + 1 + 10**(12-abund[1]) * np.nansum(10**(abund[2:]-12)))
abund[2:] = abund[2:] - 12 - np.log10(1 + 10**(abund[1]-12))
elif type == "n/ntot":
abund = 10 ** (abund - 12)
abund /= np.nansum(abund)
Expand All @@ -627,7 +636,7 @@ def totype(pattern, totype, raw=False, copy=True):
else:
raise ValueError(
"got abundance type '{}',".format(type)
+ " should be 'H=12', 'n/nH', 'n/nTot', 'n/nFe', 'Fe=12', or 'sme'"
+ " should be 'H=12', 'kurucz', 'n/nH', 'n/nTot', 'n/nFe', 'Fe=12', or 'sme'"
)

if raw:
Expand Down
2 changes: 1 addition & 1 deletion src/pysme/atmosphere/krzfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def load(self, filename):

# parse abundance
pattern = abun[:, 1]
self.abund = Abund(monh=self.monh, pattern=pattern, type="sme")
self.abund = Abund(monh=self.monh, pattern=pattern, type="kurucz")

# parse table
self.table = model_lines
Expand Down
3 changes: 2 additions & 1 deletion src/pysme/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ def update_cdr(self, sme, cdr_database=None, cdr_create=False, cdr_grid_overwrit
raise ValueError

if cdr_database is not None:
# cdr_database is provided, use it to update the central depth and line range
self._interpolate_or_compute_and_update_linelist(sme, cdr_database, cdr_create=cdr_create, cdr_grid_overwrite=cdr_grid_overwrite, mode=mode, dims=dims)
return sme

Expand Down Expand Up @@ -1022,7 +1023,7 @@ def update_cdr(self, sme, cdr_database=None, cdr_create=False, cdr_grid_overwrit
return sme

def _interpolate_or_compute_and_update_linelist(
self, sme, cdr_database, cdepth_decimals=4, cdepth_thres=0.0001,
self, sme, cdr_database, cdepth_decimals=4, cdepth_thres=0,
range_decimals=2, cdr_create=False, cdr_grid_overwrite=False,
mode='linear', dims=['teff', 'logg', 'monh']
):
Expand Down
Loading