diff --git a/docs/index.rst b/docs/index.rst index dab90ca0..4f24a6dd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,6 +4,8 @@ PySME documentation More than two decades ago `Valenti & Piskunov (1996) `_ 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 diff --git a/src/pysme/abund.py b/src/pysme/abund.py index 1417a830..60b31600 100644 --- a/src/pysme/abund.py +++ b/src/pysme/abund.py @@ -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] @@ -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] @@ -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) @@ -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: diff --git a/src/pysme/atmosphere/krzfile.py b/src/pysme/atmosphere/krzfile.py index cb23e49f..813721e7 100644 --- a/src/pysme/atmosphere/krzfile.py +++ b/src/pysme/atmosphere/krzfile.py @@ -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 diff --git a/src/pysme/synthesize.py b/src/pysme/synthesize.py index 45d1e967..c3af10f6 100644 --- a/src/pysme/synthesize.py +++ b/src/pysme/synthesize.py @@ -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 @@ -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'] ):