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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ["3.7", "3.8", "3.9", "3.10"]
version: ["3.11", "3.12", "3.13", "3.14"]
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch: ["x64"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup python ${{ matrix.version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
architecture: ${{ matrix.arch }}
Expand All @@ -33,14 +33,14 @@ jobs:
pip install -U pip
pip install .[test]
- name: Cache Test Data
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: tests/data
key: ${{ runner.os }}-test-data
- name: Test
run: |
pytest --cov=Starfish --cov-report=xml --benchmark-skip --black
pytest --cov=Starfish --cov-report=xml --benchmark-skip
- name: Coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U pep517 twine
pip install -U build twine
- name: Build
run: |
python -m pep517.build --source --binary --out-dir dist/ .
python -m build --outdir dist/ .
- name: Deploy
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: ${{ secrets.PYPI_USER }}
password: ${{ secrets.PYPI_PASSWORD }}
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.12"

sphinx:
configuration: docs/conf.py

formats: all

python:
version: 3.7
install:
- method: pip
path: .
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

### Changed
- Minor refactoring
- Support Python 3.11 through 3.14; dropped support for Python 3.10 and earlier
- Packaging metadata moved from `setup.py` to PEP 621 `pyproject.toml`
- Removed the `nptyping` dependency in favor of `numpy.typing`, and the obsolete
`dataclasses` backport; relaxed upper version caps on `astropy`, `numpy`,
`scipy`, `scikit-learn`, `extinction`, `h5py`, `flatdict`, `toml`, and `tqdm`
- Replaced `np.trapz` with `scipy.integrate.trapezoid` and `np.Inf` with
`np.inf` for NumPy 2 compatibility

### Fixed
- A bug in how fix_c0 is toggled during Chebyshev polynomial optimization
Expand Down
10 changes: 3 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
[requires]
python_version = "3.7"
python_version = "3.11"

[packages]
astropy = "*"
dataclasses = "*"
flatdict = "*"
h5py = "*"
nptyping = "*"
numpy = "*"
scikit-learn = "*"
scipy = "*"
toml = ">=0.10.1"
toml = ">=0.10.2"
tqdm = "*"
extinction = ">=0.4.2"
extinction = ">=0.4.7"

[dev-packages]
black = "*"
coveralls = "*"
flake8 = "*"
ipython = "*"
mypy = "*"
Expand All @@ -29,7 +26,6 @@ sphinx-bootstrap-theme = "*"
pytest-benchmark = "*"
sphinx-autodoc-typehints = "*"
pre-commit = "*"
pytest-black = "*"

[pipenv]
allow_prereleases = true
1 change: 0 additions & 1 deletion Starfish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"emulator",
"grid_tools",
"models",
"samplers",
"spectrum",
"Spectrum",
"transforms",
Expand Down
44 changes: 22 additions & 22 deletions Starfish/emulator/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import h5py
import numpy as np
from nptyping import NDArray
from numpy.typing import NDArray
from scipy.interpolate import LinearNDInterpolator
from scipy.linalg import cho_factor, cho_solve
from scipy.optimize import minimize
Expand Down Expand Up @@ -68,18 +68,18 @@ class Emulator:

def __init__(
self,
grid_points: NDArray[float],
grid_points: NDArray[np.float64],
param_names: Sequence[str],
wavelength: NDArray[float],
weights: NDArray[float],
eigenspectra: NDArray[float],
w_hat: NDArray[float],
flux_mean: NDArray[float],
flux_std: NDArray[float],
factors: NDArray[float],
wavelength: NDArray[np.float64],
weights: NDArray[np.float64],
eigenspectra: NDArray[np.float64],
w_hat: NDArray[np.float64],
flux_mean: NDArray[np.float64],
flux_std: NDArray[np.float64],
factors: NDArray[np.float64],
lambda_xi: float = 1.0,
variances: Optional[NDArray[float]] = None,
lengthscales: Optional[NDArray[float]] = None,
variances: Optional[NDArray[np.float64]] = None,
lengthscales: Optional[NDArray[np.float64]] = None,
name: Optional[str] = None,
):
self.log = logging.getLogger(self.__class__.__name__)
Expand Down Expand Up @@ -144,7 +144,7 @@ def lambda_xi(self, value: float):
self.hyperparams["log_lambda_xi"] = np.log(value)

@property
def variances(self) -> NDArray[float]:
def variances(self) -> NDArray[np.float64]:
"""
numpy.ndarray : The variances for each Gaussian process kernel.

Expand All @@ -158,12 +158,12 @@ def variances(self) -> NDArray[float]:
return np.exp(values)

@variances.setter
def variances(self, values: NDArray[float]):
def variances(self, values: NDArray[np.float64]):
for i, value in enumerate(values):
self.hyperparams[f"log_variance:{i}"] = np.log(value)

@property
def lengthscales(self) -> NDArray[float]:
def lengthscales(self) -> NDArray[np.float64]:
"""
numpy.ndarray : The lengthscales for each Gaussian process kernel.

Expand All @@ -177,7 +177,7 @@ def lengthscales(self) -> NDArray[float]:
return np.exp(values).reshape(self.ncomps, -1)

@lengthscales.setter
def lengthscales(self, values: NDArray[float]):
def lengthscales(self, values: NDArray[np.float64]):
for i, value in enumerate(values):
for j, ls in enumerate(value):
self.hyperparams[f"log_lengthscale:{i}:{j}"] = np.log(ls)
Expand Down Expand Up @@ -332,7 +332,7 @@ def __call__(
params: Sequence[float],
full_cov: bool = True,
reinterpret_batch: bool = False,
) -> Tuple[NDArray[float], NDArray[float]]:
) -> Tuple[NDArray[np.float64], NDArray[np.float64]]:
"""
Gets the mu and cov matrix for a given set of params

Expand Down Expand Up @@ -394,16 +394,16 @@ def __call__(
return mu, cov

@property
def bulk_fluxes(self) -> NDArray[float]:
def bulk_fluxes(self) -> NDArray[np.float64]:
"""
numpy.ndarray: A vertically concatenated vector of the eigenspectra, flux_mean,
and flux_std (in that order). Used for bulk processing with the emulator.
"""
return np.vstack([self.eigenspectra, self.flux_mean, self.flux_std])

def load_flux(
self, params: Union[Sequence[float], NDArray[float]], norm=False
) -> NDArray[float]:
self, params: Union[Sequence[float], NDArray[np.float64]], norm=False
) -> NDArray[np.float64]:
"""
Interpolate a model given any parameters within the grid's parameter range
using eigenspectrum reconstruction
Expand All @@ -426,7 +426,7 @@ def load_flux(
flux *= self.norm_factor(params)[:, np.newaxis]
return np.squeeze(flux)

def norm_factor(self, params: Union[Sequence[float], NDArray[float]]) -> float:
def norm_factor(self, params: Union[Sequence[float], NDArray[np.float64]]) -> float:
"""
Return the scaling factor for the absolute flux units in flux-normalized spectra

Expand Down Expand Up @@ -570,7 +570,7 @@ def set_param_dict(self, params: dict):
self.grid_points, self.grid_points, self.variances, self.lengthscales
)

def get_param_vector(self) -> NDArray[float]:
def get_param_vector(self) -> NDArray[np.float64]:
"""
Get a vector of the current trainable parameters of the emulator

Expand All @@ -581,7 +581,7 @@ def get_param_vector(self) -> NDArray[float]:
values = list(self.get_param_dict().values())
return np.array(values)

def set_param_vector(self, params: NDArray[float]):
def set_param_vector(self, params: NDArray[np.float64]):
"""
Set the current trainable parameters given a vector. Must have the same form as
:meth:`get_param_vector`
Expand Down
9 changes: 6 additions & 3 deletions Starfish/emulator/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from matplotlib import gridspec
import numpy as np

plt.style.use("seaborn")
try:
plt.style.use("seaborn-v0_8")
except OSError:
pass


def plot_reconstructed(emulator, grid, folder):
Expand Down Expand Up @@ -90,7 +93,7 @@ def plot_eigenspectra(emulator, params, filename=None):
)
ax = plt.subplot(gs[0])
ax.plot(emulator.wl, reconstructed, lw=1)
ax.set_ylabel("$f_\lambda$ [erg/cm^2/s/A]")
ax.set_ylabel(r"$f_\lambda$ [erg/cm^2/s/A]")
plt.setp(ax.get_xticklabels(), visible=False)
for i in range(emulator.ncomps):
ax = plt.subplot(gs[i + 1], sharex=ax)
Expand Down Expand Up @@ -149,6 +152,6 @@ def plot_emulator(emulator):
axes[i].fill_between(Ttest, m - 2 * s, m + 2 * s, color="C1", alpha=0.4)
axes[-1].set_xlabel("T (K)")
plt.suptitle(
f"Weights for fixed $\log g={logg[0]:.2f}$, $[Fe/H]={Z[0]:.2f}$", fontsize=20
rf"Weights for fixed $\log g={logg[0]:.2f}$, $[Fe/H]={Z[0]:.2f}$", fontsize=20
)
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
9 changes: 5 additions & 4 deletions Starfish/grid_tools/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from astropy.io import fits, ascii
from scipy.integrate import trapezoid
from scipy.interpolate import InterpolatedUnivariateSpline

import Starfish.constants as C
Expand Down Expand Up @@ -138,7 +139,7 @@ def load_flux(self, parameters, header=False, norm=True):
# If we want to normalize the spectra, we must do it now since later we won't have the full EM range
if norm:
flux *= 1e-8 # convert from erg/cm^2/s/cm to erg/cm^2/s/A
F_bol = np.trapz(flux, self.wl_full)
F_bol = trapezoid(flux, self.wl_full)
# bolometric luminosity is always 1 L_sun
flux *= C.F_sun / F_bol

Expand Down Expand Up @@ -393,7 +394,7 @@ def load_flux(self, parameters, norm=True):
fl = fl[ind]

if norm:
F_bol = np.trapz(fl, wl)
F_bol = trapezoid(fl, wl)
fl = fl * (C.F_sun / F_bol)
# the bolometric luminosity is always 1 L_sun

Expand Down Expand Up @@ -487,7 +488,7 @@ def load_flux(self, parameters, header=False, norm=True):
fl = fl[ind]

if norm:
F_bol = np.trapz(fl, wl)
F_bol = trapezoid(fl, wl)
fl = fl * (C.F_sun / F_bol)
# the bolometric luminosity is always 1 L_sun

Expand Down Expand Up @@ -538,7 +539,7 @@ def load_BTSettl(T, logg, Z, norm=False, trunc=False, air=False):
fl = 10 ** (fl - 8.0) # now in ergs/cm^2/s/A

if norm:
F_bol = np.trapz(fl, wl)
F_bol = trapezoid(fl, wl)
fl = fl * (C.F_sun / F_bol)
# this also means that the bolometric luminosity is always 1 L_sun

Expand Down
6 changes: 3 additions & 3 deletions Starfish/models/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

import numpy as np
from nptyping import NDArray
from numpy.typing import NDArray
from scipy.optimize import minimize
import scipy.stats as st

Expand Down Expand Up @@ -105,7 +105,7 @@ def chi2(P, wave, resid, sigma):
_amp = np.exp(log_amp)
_sigma = np.exp(log_sigma)
if _amp == 0 or _sigma == 0:
return np.Inf
return np.inf
# Logistic prior for the widths out to 2sigma
prior = st.uniform.logpdf(_sigma, 0, 2 * sigma0)
# Put prior on widths and heights such that the integrated area should be less
Expand Down Expand Up @@ -151,7 +151,7 @@ def chi2(P, wave, resid, sigma):
log = logging.getLogger(__name__)


def covariance_debugger(cov: NDArray[float]):
def covariance_debugger(cov: NDArray[np.float64]):
"""
Special debugging information for the covariance matrix decomposition.
"""
Expand Down
10 changes: 5 additions & 5 deletions Starfish/spectrum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import h5py
import numpy as np
from dataclasses import dataclass
from nptyping import NDArray
from numpy.typing import NDArray
from typing import Optional


Expand All @@ -26,10 +26,10 @@ class Order:
name : str
"""

_wave: NDArray[float]
_flux: NDArray[float]
_sigma: Optional[NDArray[float]] = None
mask: Optional[NDArray[bool]] = None
_wave: NDArray[np.float64]
_flux: NDArray[np.float64]
_sigma: Optional[NDArray[np.float64]] = None
mask: Optional[NDArray[np.bool_]] = None

def __post_init__(self):
if self._sigma is None:
Expand Down
Loading
Loading