From 1b42bda2438a12533da81c8772efa41ac14cbaba Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Sat, 25 Jun 2022 09:28:28 +0200 Subject: [PATCH] Included interp_method parameter in config file, fixed issues with some mathtext --- docs/overview.rst | 11 +++++++++++ species/core/box.py | 6 ++++-- species/core/init.py | 15 ++++++++++++--- species/read/read_model.py | 13 +++++++++++-- species/util/plot_util.py | 14 +++++++------- species/util/test_util.py | 6 +++--- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/docs/overview.rst b/docs/overview.rst index e7c6b77b..da660942 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -32,6 +32,17 @@ The following data and models are currently supported: - `Sonora Bobcat `_ - `Sonora Cholla `_ +The :func:`~species.data.database.Database.available_models()` method of the :class:`~species.data.database.Database` class can be used for getting a complete overview of all model grids, including details on the input parameters, wavelength range, :math:`T_\mathrm{eff}` range, and spectral resolution: + +.. code-block:: python + + import species + + species.SpeciesInit() + + database = species.Database() + database.available_models() + **Spectral libraries** - `IRTF Spectral Library `_ diff --git a/species/core/box.py b/species/core/box.py index 86ad3ad3..31441cf4 100644 --- a/species/core/box.py +++ b/species/core/box.py @@ -135,8 +135,10 @@ def create_box(boxtype, **kwargs): box.spectrum = kwargs["spectrum"] box.wavelength = kwargs["wavelength"] box.flux = kwargs["flux"] - box.error = kwargs["error"] - box.name = kwargs["name"] + if "error" in kwargs: + box.error = kwargs["error"] + if "name" in kwargs: + box.name = kwargs["name"] if "simbad" in kwargs: box.simbad = kwargs["simbad"] if "sptype" in kwargs: diff --git a/species/core/init.py b/species/core/init.py index 9e287404..324c331f 100644 --- a/species/core/init.py +++ b/species/core/init.py @@ -57,9 +57,18 @@ def __init__(self): print("Creating species_config.ini...", end="", flush=True) with open(config_file, "w") as file_obj: - file_obj.write("[species]\n") - file_obj.write("database = species_database.hdf5\n") - file_obj.write("data_folder = ./data/\n") + file_obj.write("[species]\n\n") + + file_obj.write("; File with the HDF5 database\n") + file_obj.write("database = species_database.hdf5\n\n") + + file_obj.write("; Folder where data will be downloaded\n") + file_obj.write("data_folder = ./data/\n\n") + + file_obj.write("; Method for the grid interpolation\n") + file_obj.write("; Options: linear, nearest, slinear, " + "cubic, quintic, pchip\n") + file_obj.write("interp_method = linear\n") print(" [DONE]") diff --git a/species/read/read_model.py b/species/read/read_model.py index c445263b..e745e461 100644 --- a/species/read/read_model.py +++ b/species/read/read_model.py @@ -86,6 +86,7 @@ def __init__( config.read(config_file) self.database = config["species"]["database"] + self.interp_method = config["species"]["interp_method"] self.extra_param = [ "radius", @@ -209,7 +210,11 @@ def interpolate_model(self) -> None: flux = flux[..., self.wl_index] self.spectrum_interp = RegularGridInterpolator( - points, flux, method="linear", bounds_error=False, fill_value=np.nan + points, + flux, + method=self.interp_method, + bounds_error=False, + fill_value=np.nan, ) @typechecked @@ -382,7 +387,11 @@ def interpolate_grid( self.wl_points = wavel_resample self.spectrum_interp = RegularGridInterpolator( - points, flux_new, method="linear", bounds_error=False, fill_value=np.nan + points, + flux_new, + method=self.interp_method, + bounds_error=False, + fill_value=np.nan, ) @staticmethod diff --git a/species/util/plot_util.py b/species/util/plot_util.py index 97e0e2a8..5f3285ad 100644 --- a/species/util/plot_util.py +++ b/species/util/plot_util.py @@ -268,7 +268,7 @@ def update_labels(param: List[str]) -> List[str]: if "parallax" in param: index = param.index("parallax") - param[index] = r"$\pi$ (mas)" + param[index] = r"$\varpi$ (mas)" if "mass" in param: index = param.index("mass") @@ -320,11 +320,11 @@ def update_labels(param: List[str]) -> List[str]: if "mcore_1" in param: index = param.index("mcore_1") - param[index] = r"$M_\mathrm{core, b}$" + param[index] = r"$M_\mathrm{core,b}$ ($M_\mathrm{E}$)" if "mcore_2" in param: index = param.index("mcore_2") - param[index] = r"$M_\mathrm{core, c}$" + param[index] = r"$M_\mathrm{core,c}$ ($M_\mathrm{E}$)" if "luminosity" in param: index = param.index("luminosity") @@ -809,7 +809,7 @@ def quantity_unit( unit.append(r"$R_\mathrm{J}$") elif object_type == "star": - unit.append(r"$R_\mathrm{\odot}$$") + unit.append(r"$R_\mathrm{\odot}$") label.append(r"$R$") @@ -830,7 +830,7 @@ def quantity_unit( unit.append(r"$R_\mathrm{J}$") elif object_type == "star": - unit.append(r"$R_\mathrm{\odot}$$") + unit.append(r"$R_\mathrm{\odot}$") label.append(rf"$R_\mathrm{{{i+1}}}$") @@ -849,14 +849,14 @@ def quantity_unit( unit.append(r"$M_\mathrm{J}$") elif object_type == "star": - unit.append(r"$M_\mathrm{\odot}$$") + unit.append(r"$M_\mathrm{\odot}$") label.append("M") if "luminosity" in param: quantity.append("luminosity") unit.append(None) - label.append(r"$\log\,L/L_\mathrm{\odot}$$") + label.append(r"$\log\,L/L_\mathrm{\odot}$") if "ism_ext" in param: quantity.append("ism_ext") diff --git a/species/util/test_util.py b/species/util/test_util.py index 21fa43d2..2ed85624 100644 --- a/species/util/test_util.py +++ b/species/util/test_util.py @@ -25,7 +25,7 @@ def create_config(test_path): data_folder = os.path.join(test_path, "data/") with open(config_file, "w", encoding="utf-8") as config: - print(dir(config)) config.write("[species]\n") - config.write("database = " + database_file + "\n") - config.write("data_folder = " + data_folder) + config.write(f"database = {database_file}\n") + config.write(f"data_folder = {data_folder}\n") + config.write("interp_method = linear")