Skip to content

Commit 6319df7

Browse files
authored
fix: check spectrum input and shape of outputs
fix: check spectrum input and shape of outputs
2 parents 087851b + cf85b88 commit 6319df7

File tree

5 files changed

+67
-19
lines changed

5 files changed

+67
-19
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name: spotter/ci
22

33
on:
4-
merge_group:
5-
workflow_dispatch:
6-
pull_request:
7-
release:
8-
types: [published]
4+
push:
95
branches:
106
- main
117
tags:
128
- "*"
9+
pull_request:
10+
merge_group:
11+
release:
12+
types: [published]
1313

1414
jobs:
1515
tests:
@@ -70,7 +70,7 @@ jobs:
7070
publish:
7171
environment:
7272
name: pypi
73-
url: https://pypi.org/p/spotter
73+
url: https://pypi.org/p/fitsm
7474
permissions:
7575
id-token: write
7676
needs: [tests, build]
@@ -79,6 +79,6 @@ jobs:
7979
steps:
8080
- uses: actions/download-artifact@v4
8181
with:
82-
name: artifact
82+
name: dist
8383
path: dist
84-
- uses: pypa/gh-action-pypi-publish@v1.8.11
84+
- uses: pypa/gh-action-pypi-publish@v1.12.4

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "spotter"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
description = "Approximate forward models of fluxes and spectra time-series of non-uniform stars."
55
authors = [{ name = "Lionel Garcia" }, { name = "Benjamin Rackham" }]
66
license = "MIT"

spotter/core.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ def shifted_spectra(spectra, shift):
533533
return jnp.real(shifted)
534534

535535

536-
def integrated_spectrum(N, theta, phi, period, radius, wv, spectra, phase, inc, normalize = True):
536+
def integrated_spectrum(
537+
N, theta, phi, period, radius, wv, spectra, phase, inc, normalize=True
538+
):
537539
"""
538540
Compute the integrated spectrum of a rotating star.
539541
@@ -565,17 +567,23 @@ def integrated_spectrum(N, theta, phi, period, radius, wv, spectra, phase, inc,
565567
"""
566568
spectra = jnp.atleast_2d(spectra)
567569
if period is None:
568-
spectra_shifted = spectra
570+
mask, projected, limb = mask_projected_limb(vec(N), 0.0, inc=inc)
571+
limb_geometry = projected * mask * limb
572+
spectra_shifted = spectra.T
573+
569574
else:
570575
mask, projected, limb = mask_projected_limb(vec(N), phase, inc=inc)
571576
w_shift = doppler_shift(theta, phi, period, radius, phase)
572577
dw = wv[1] - wv[0]
573578
shift = w_shift[:, None] * wv / dw
574579
limb_geometry = projected * mask * limb
575580
spectra_shifted = shifted_spectra(spectra.T, shift)
576-
577-
if normalize:
578-
integrated_spec = jnp.sum(spectra_shifted * limb_geometry[:, None], 0) / jnp.sum(limb_geometry[:, None] * spectra.T)
579-
else:
580-
integrated_spec = jnp.sum(spectra_shifted * limb_geometry[:, None], 0)
581-
return integrated_spec
581+
582+
if normalize:
583+
integrated_spec = jnp.sum(
584+
spectra_shifted * limb_geometry[:, None], 0
585+
) / jnp.sum(limb_geometry[:, None] * spectra.T)
586+
else:
587+
integrated_spec = jnp.sum(spectra_shifted * limb_geometry[:, None], 0)
588+
589+
return integrated_spec

spotter/doppler.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ def spectrum(star: Star, time: float, normalize: bool = True) -> ArrayLike:
3333
spectrum : ndarray
3434
Integrated spectrum.
3535
"""
36+
if star.wv is None:
37+
raise ValueError("Star.wv must be set.")
38+
39+
if star.wv.shape[0] != star.y.shape[0]:
40+
raise ValueError(
41+
"The star spectrum (Star.y) must have the same number of wavelength as the "
42+
f"wavelengths provided (Star.wv).\nFound Star.wv.shape[0] = {star.wv.shape[0]} "
43+
f"and Star.y.shape[0] = {star.y.shape[0]}"
44+
)
45+
3646
phi, theta = hp.pix2ang(star.sides, range(hp.nside2npix(star.sides)))
37-
47+
3848
def impl(star, time):
3949
return core.integrated_spectrum(
4050
star.sides,
@@ -52,7 +62,6 @@ def impl(star, time):
5262
return jnp.vectorize(impl, excluded=(0,), signature="()->(n)")(star, time)
5363

5464

55-
5665
def rv_design_matrix(star: Star, time: float) -> ArrayLike:
5766
"""
5867
Compute the radial velocity design matrix for a Star.

tests/test_spectrum.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from spotter import Star, doppler
2+
import numpy as np
3+
import pytest
4+
5+
6+
def test_star_inputs():
7+
wv = np.linspace(0, 1, 10)
8+
star = Star.from_sides(10, wv=wv, period=1.0)
9+
with pytest.raises(ValueError):
10+
doppler.spectrum(star, [0])
11+
12+
star = Star.from_sides(10)
13+
with pytest.raises(ValueError):
14+
doppler.spectrum(star, [0])
15+
16+
17+
def test_spectrum():
18+
wv = np.linspace(0, 1, 10)
19+
star = Star.from_sides(10, wv=wv, period=1.0)
20+
spectra = np.random.rand(len(wv), star.size)
21+
star = star.set(y=spectra)
22+
assert doppler.spectrum(star, [0]).shape == (1, len(wv))
23+
assert doppler.spectrum(star, [0, 1, 2]).shape == (3, len(wv))
24+
25+
26+
def test_no_period():
27+
wv = np.linspace(0, 1, 10)
28+
star = Star.from_sides(10, wv=wv)
29+
spectra = np.random.rand(len(wv), star.size)
30+
star = star.set(y=spectra)
31+
assert doppler.spectrum(star, [0]).shape == (1, len(wv))

0 commit comments

Comments
 (0)