Skip to content

Commit

Permalink
Updated pyproject.toml, replaced interp1d to spectres resampling to c…
Browse files Browse the repository at this point in the history
…onserve flux, allow for negative extinction, extinction support in ReadPlanck, support for grids with log(12CO/13CO) parameter
  • Loading branch information
tomasstolker committed Oct 30, 2024
1 parent f12d422 commit 319db96
Show file tree
Hide file tree
Showing 21 changed files with 342 additions and 215 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/synthetic_photometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we use the [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.phot.html#species.phot.syn_phot.SyntheticPhotometry) class to calculate the flux and magnitude for the [MKO/NSFCam.J](http://svo2.cab.inta-csic.es/svo/theory/fps/index.php?id=MKO/NSFCam.J&&mode=browse&gname=MKO&gname2=NSFCam#filter) filter. We first create and instance of [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.phot.html#species.phot.syn_phot.SyntheticPhotometry) with the filter name from the SVO website."
"Next, we use the [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.phot.html#species.phot.syn_phot.SyntheticPhotometry) class to calculate the flux and magnitude for the [MKO/NSFCam.J](http://svo2.cab.inta-csic.es/svo/theory/fps/index.php?id=MKO/NSFCam.J&&mode=browse&gname=MKO&gname2=NSFCam#filter) filter. We first create an instance of [SyntheticPhotometry](https://species.readthedocs.io/en/latest/species.phot.html#species.phot.syn_phot.SyntheticPhotometry) with the filter name from the SVO website."
]
},
{
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ Repository = "https://github.com/tomasstolker/species"
Issues = "https://github.com/tomasstolker/species/issues"

[tool.setuptools]
packages = ["species"]
packages = [
"species",
"species.core",
"species.data",
"species.fit",
"species.phot",
"species.plot",
"species.read",
"species.util"
]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
Expand Down
18 changes: 9 additions & 9 deletions species/data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def add_object(
units : dict, None
Dictionary with the units of the data provided with
``flux_density`` and ``spectrum``. Only required if
the wavelength units are not :math:`\\mu\\text{m}^{-1}`
the wavelength units are not :math:`\\mu\\text{m}`
and/or the flux units are not provided as
:math:`\\text{W} \\text{m}^{-2} \\mu\\text{m}^{-1}`.
Otherwise, the argument of ``units`` can be set to
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def add_object(
except KeyError:
warnings.warn(
f"Filter '{mag_item}' is not available on the SVO Filter "
f"Profile Service so a flux calibration can not be done. "
f"Profile Service so a flux calibration cannot be done. "
f"Please add the filter manually with the 'add_filter' "
f"function. For now, only the '{mag_item}' magnitude of "
f"'{object_name}' is stored."
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def add_object(
except KeyError:
warnings.warn(
f"Filter '{mag_item}' is not available on the SVO "
f"Filter Profile Service so a flux calibration can not "
f"Filter Profile Service so a flux calibration cannot "
f"be done. Please add the filter manually with the "
f"'add_filter' function. For now, only the "
f"'{mag_item}' magnitude of '{object_name}' is "
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def add_object(

if spec_item not in read_spec:
raise ValueError(
f"The spectrum data from {spec_value[0]} can not "
f"The spectrum data from {spec_value[0]} cannot "
f"be read. The data format should be 2D with "
f"3 columns."
)
Expand All @@ -1357,14 +1357,14 @@ def add_object(

except UnicodeDecodeError:
raise ValueError(
f"The spectrum data from {spec_value[0]} can not "
f"The spectrum data from {spec_value[0]} cannot "
"be read. Please provide a FITS or ASCII file."
)

if data.ndim != 2 or 3 not in data.shape:
raise ValueError(
f"The spectrum data from {spec_value[0]} "
"can not be read. The data format "
"cannot be read. The data format "
"should be 2D with 3 columns."
)

Expand Down Expand Up @@ -1530,7 +1530,7 @@ def add_object(

if spec_item not in read_cov:
raise ValueError(
f"The covariance matrix from {spec_value[1]} can not "
f"The covariance matrix from {spec_value[1]} cannot "
f"be read. The data format should be 2D with the "
f"same number of wavelength points as the "
f"spectrum."
Expand All @@ -1542,14 +1542,14 @@ def add_object(
except UnicodeDecodeError:
raise ValueError(
f"The covariance matrix from {spec_value[1]} "
f"can not be read. Please provide a "
f"cannot be read. Please provide a "
f"FITS or ASCII file."
)

if data.ndim != 2 or data.shape[0] != data.shape[1]:
raise ValueError(
f"The covariance matrix from {spec_value[1]} "
f"can not be read. The data format "
f"cannot be read. The data format "
f"should be 2D with the same number of "
f"wavelength points as the spectrum."
)
Expand Down
40 changes: 30 additions & 10 deletions species/data/model_data/model_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"ames-cond": {
"parameters": ["teff", "logg"],
"name": "AMES-Cond",
"file size": "150 MB",
"file size": "57 MB",
"wavelength range": [0.5, 40],
"lambda/d_lambda": 4000,
"lambda/d_lambda": 2000,
"teff range": [100, 6600]
},
"ames-dusty": {
"parameters": ["teff", "logg"],
"name": "AMES-Dusty",
"file size": "58 MB",
"file size": "22 MB",
"wavelength range": [0.5, 40],
"lambda/d_lambda": 4000,
"lambda/d_lambda": 2000,
"teff range": [500, 4000]
},
"atmo": {
Expand Down Expand Up @@ -100,7 +100,7 @@
"bt-nextgen": {
"parameters": ["teff", "logg", "feh"],
"name": "BT-NextGen",
"file size": "343 MB",
"file size": "328 MB",
"wavelength range": [0.1, 5000],
"lambda/d_lambda": 2000,
"teff range": [2600, 30000]
Expand Down Expand Up @@ -140,22 +140,42 @@
"reference": "Helling et al. (2008)",
"url": "https://ui.adsabs.harvard.edu/abs/2008ApJ...675L.105H"
},
"exo-rem": {
"exo-rem-cloud-r500": {
"parameters": ["teff", "logg", "feh", "c_o_ratio"],
"name": "Exo-REM",
"file size": "643 MB",
"file size": "703 MB",
"wavelength range": [0.35, 250.0],
"lambda/d_lambda": 500,
"teff range": [400, 2000],
"reference": "Charnay et al. (2018)",
"url": "https://ui.adsabs.harvard.edu/abs/2018ApJ...854..172C"
},
"exo-rem-highres": {
"exo-rem-nocloud-r500": {
"parameters": ["teff", "logg", "feh", "c_o_ratio"],
"name": "Exo-REM",
"file size": "22 GB",
"file size": "508 MB",
"wavelength range": [0.35, 250.0],
"lambda/d_lambda": 500,
"teff range": [400, 2000],
"reference": "Charnay et al. (2018)",
"url": "https://ui.adsabs.harvard.edu/abs/2018ApJ...854..172C"
},
"exo-rem-cloud-r20000": {
"parameters": ["teff", "logg", "feh", "c_o_ratio"],
"name": "Exo-REM",
"file size": "21 GB",
"wavelength range": [0.67, 250.0],
"lambda/d_lambda": 20000,
"lambda/d_lambda": 500,
"teff range": [400, 2000],
"reference": "Charnay et al. (2018)",
"url": "https://ui.adsabs.harvard.edu/abs/2018ApJ...854..172C"
},
"exo-rem-cloud-r20000-isotopes": {
"parameters": ["teff", "logg", "feh", "c_o_ratio", "log_co_iso"],
"name": "Exo-REM",
"file size": "239 MB",
"wavelength range": [0.67, 250.0],
"lambda/d_lambda": 500,
"teff range": [400, 2000],
"reference": "Charnay et al. (2018)",
"url": "https://ui.adsabs.harvard.edu/abs/2018ApJ...854..172C"
Expand Down
25 changes: 22 additions & 3 deletions species/data/model_data/model_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import pooch

from scipy.interpolate import interp1d
from spectres.spectral_resampling_numba import spectres_numba
from typeguard import typechecked

from species.util.core_util import print_section
Expand Down Expand Up @@ -245,6 +245,11 @@ def add_model_grid(
else:
ad_index = None

if "log_co_iso" in model_info["parameters"]:
log_co_iso = []
else:
log_co_iso = None

flux = []

print()
Expand Down Expand Up @@ -319,6 +324,10 @@ def add_model_grid(
param_index = file_split.index("adindex") + 1
ad_index.append(float(file_split[param_index]))

if log_co_iso is not None:
param_index = file_split.index("coiso") + 1
log_co_iso.append(float(file_split[param_index]))

empty_message = len(print_message) * " "
print(f"\r{empty_message}", end="")

Expand Down Expand Up @@ -363,8 +372,14 @@ def add_model_grid(
flux.append(data_flux[wavel_select]) # (W m-2 um-1)

else:
flux_interp = interp1d(data_wavel, data_flux)
flux_resample = flux_interp(wavelength)
flux_resample = spectres_numba(
wavelength,
data_wavel,
data_flux,
spec_errs=None,
fill=np.nan,
verbose=True,
)

if np.isnan(np.sum(flux_resample)):
raise ValueError(
Expand Down Expand Up @@ -397,6 +412,9 @@ def add_model_grid(
if ad_index is not None:
ad_index = np.asarray(ad_index)

if log_co_iso is not None:
log_co_iso = np.asarray(log_co_iso)

data_sorted = sort_data(
np.asarray(teff),
logg,
Expand All @@ -405,6 +423,7 @@ def add_model_grid(
fsed,
log_kzz,
ad_index,
log_co_iso,
wavelength,
np.asarray(flux),
)
Expand Down
2 changes: 1 addition & 1 deletion species/fit/compare_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def compare_model(
fix_logg : float, None
Fix the value of :math:`\\log(g)`, for example if estimated
from gravity-sensitive spectral features. Typically,
:math:`\\log(g)` can not be accurately determined when
:math:`\\log(g)` cannot be accurately determined when
comparing the spectra over a broad wavelength range.
scale_spec : list(str), None
List with names of observed spectra to which an additional
Expand Down
6 changes: 3 additions & 3 deletions species/fit/fit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,13 +1469,13 @@ def _lnlike_func(
warnings.warn(
"The 'logg' parameter is not used "
f"by the '{self.model}' model so "
"the mass prior can not be applied."
"the mass prior cannot be applied."
)

elif "radius" not in self.modelpar:
warnings.warn(
"The 'radius' parameter is not fitted "
"so the mass prior can not be applied."
"so the mass prior cannot be applied."
)

elif prior_key[:6] == "ratio_":
Expand Down Expand Up @@ -2506,7 +2506,7 @@ def _lnlike_ultranest(params: np.ndarray) -> Union[float, np.float64]:
ln_like = self._lnlike_func(params)

if not np.isfinite(ln_like):
# UltraNest can not handle np.inf in the likelihood
# UltraNest cannot handle np.inf in the likelihood
ln_like = -1e100

return ln_like
Expand Down
4 changes: 2 additions & 2 deletions species/fit/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3573,7 +3573,7 @@ def setup_retrieval(

elif "fsed_1" in bounds or "fsed_2" in bounds:
raise ValueError(
"The cross_corr parameter can not be "
"The cross_corr parameter cannot be "
"used with multiple fsed parameters."
)

Expand Down Expand Up @@ -3663,7 +3663,7 @@ def setup_retrieval(
if param_item in bounds:
warnings.warn(
f"The '{param_item}' parameter "
"can not be used if the "
"cannot be used if the "
"'abund_nodes' argument is set. "
"The prior boundaries of "
f"'{param_item}' will therefore "
Expand Down
4 changes: 2 additions & 2 deletions species/phot/syn_phot.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def spectrum_to_flux(
error_flux = np.std(phot_random)

elif error is not None and np.any(np.isnan(error)):
warnings.warn("Spectum contains NaN so can not calculate the error.")
warnings.warn("Spectum contains NaN so cannot calculate the error.")
error_flux = None

else:
Expand Down Expand Up @@ -479,7 +479,7 @@ def spectrum_to_magnitude(
error_app_mag = np.std(mag_random)

elif error is not None and np.any(np.isnan(error)):
warnings.warn("Spectum contains NaN so can not calculate the error.")
warnings.warn("Spectum contains NaN so cannot calculate the error.")
error_app_mag = None

else:
Expand Down
2 changes: 1 addition & 1 deletion species/plot/plot_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ def plot_spectrum(

if obj_index is None:
raise ValueError(
"ObjectBox not found so can not create "
"ObjectBox not found so cannot create "
"residuals. Please add an ObjectBox to "
"the list of boxes."
)
Expand Down
Loading

0 comments on commit 319db96

Please sign in to comment.