Skip to content

Commit

Permalink
Included interp_method parameter in config file, fixed issues with so…
Browse files Browse the repository at this point in the history
…me mathtext
  • Loading branch information
tomasstolker committed Jun 25, 2022
1 parent 4b01e7e commit 1b42bda
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
11 changes: 11 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ The following data and models are currently supported:
- `Sonora Bobcat <https://zenodo.org/record/5063476>`_
- `Sonora Cholla <https://zenodo.org/record/4450269>`_

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 <http://irtfweb.ifa.hawaii.edu/~spex/IRTF_Spectral_Library/>`_
Expand Down
6 changes: 4 additions & 2 deletions species/core/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions species/core/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down
13 changes: 11 additions & 2 deletions species/read/read_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions species/util/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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$")

Expand All @@ -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}}}$")

Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions species/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 1b42bda

Please sign in to comment.