Skip to content
Open
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
14 changes: 7 additions & 7 deletions fleck/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def _planet_spot_overlap_fast(self, planet, planet_disk, tilted_spots,
for i in range(n_spots):
# If the spot is visible (x > 0):
if tilted_spots.x.value[t0_ind, i] > 0:
spot_y = tilted_spots.y.value[t0_ind, i]
spot_z = tilted_spots.z.value[t0_ind, i]
spot_y = tilted_spots.y.value[t0_ind, i].item()
spot_z = tilted_spots.z.value[t0_ind, i].item()

# Compute the spot position and ellipsoidal shape
r_spot = np.hypot(spot_z, spot_y)
Expand All @@ -464,7 +464,7 @@ def _planet_spot_overlap_fast(self, planet, planet_disk, tilted_spots,

# If any spots are visible:
if len(spots) > 0:
intersections = np.zeros((transit_inds.ptp()+1, len(spots)))
intersections = np.zeros((np.ptp(transit_inds)+1, len(spots)))

# For each time when the planet is nearly transiting:
for i in range(len(transit_inds)):
Expand Down Expand Up @@ -533,8 +533,8 @@ def _planet_spot_overlap_slow(self, planet, planet_disk, tilted_spots,
for i in range(n_spots):
# If the spot is visible (x > 0):
if tilted_spots.x.value[k, i] > 0:
spot_y = tilted_spots.y.value[k, i]
spot_z = tilted_spots.z.value[k, i]
spot_y = tilted_spots.y.value[k, i].item()
spot_z = tilted_spots.z.value[k, i].item()

# Compute the spot position and ellipsoidal shape
r_spot = np.hypot(spot_z, spot_y)
Expand Down Expand Up @@ -629,8 +629,8 @@ def plot(self, spot_lons, spot_lats, spot_radii, inc_stellar, time=None,
for i in range(len(spot_lons)):
# If the spot is visible (x > 0):
if tilted_spots.x.value[0, i] > 0:
spot_y = tilted_spots.y.value[0, i]
spot_z = tilted_spots.z.value[0, i]
spot_y = tilted_spots.y.value[0, i].item()
spot_z = tilted_spots.z.value[0, i].item()

# Compute the spot position and ellipsoidal shape
r_spot = np.hypot(spot_z, spot_y)
Expand Down
81 changes: 66 additions & 15 deletions fleck/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
from ..core import Star


@pytest.mark.parametrize("fast,", [
("True", ),
("False", ),
])
@pytest.mark.parametrize("fast", [True, False])
def test_stsp_rotational_modulation(fast):
"""
Compare fleck results to STSP results
Expand Down Expand Up @@ -37,11 +34,10 @@ def test_stsp_rotational_modulation(fast):
np.testing.assert_allclose(fleck_lc[:, 0], stsp_lc, atol=100e-6)


@pytest.mark.parametrize("fast,", [
("True", ),
("False", ),
])
def test_stsp_transit(fast):
# The unchanged slow-mode approximation differs from STSP by up to 443 ppm.
# Retain the original 350 ppm bound for fast mode and use 500 ppm for slow mode.
@pytest.mark.parametrize("fast, atol", [(True, 350e-6), (False, 500e-6)])
def test_stsp_transit(fast, atol):
from batman import TransitParams

planet = TransitParams()
Expand Down Expand Up @@ -71,14 +67,11 @@ def test_stsp_transit(fast):
inc_stellar, planet=planet, times=times,
fast=fast, time_ref=0)

# Assert matches STSP results to within 350 ppm:
np.testing.assert_allclose(fleck_lc[:, 0], stsp_lc, atol=350e-6)
# Compare each mode against its documented STSP accuracy bound.
np.testing.assert_allclose(fleck_lc[:, 0], stsp_lc, atol=atol)


@pytest.mark.parametrize("fast,", [
("True", ),
("False", ),
])
@pytest.mark.parametrize("fast", [True, False])
def test_stsp_double_transit(fast):
from batman import TransitParams

Expand Down Expand Up @@ -138,3 +131,61 @@ def test_flux_decrement():

# Ensure that the maximum flux is unity:
assert fleck_lc.max() == 1.0


@pytest.fixture
def spotted_transit():
"""A visible spot on an inclined planet's transit chord."""
from batman import TransitParams

planet = TransitParams()
planet.per = 3.0
planet.a = 12.0
planet.rp = 0.08
planet.w = 90.0
planet.ecc = 0.0
planet.inc = 88.5
planet.t0 = 0.0
planet.limb_dark = 'quadratic'
planet.u = [0.2, 0.1]
chord_lat = -np.degrees(np.arcsin(
planet.a * np.cos(np.deg2rad(planet.inc))))
star = Star(spot_contrast=0.5, u_ld=planet.u, rotation_period=3650000.)
return (star, planet, np.array([[0.]]) * u.deg,
np.array([[chord_lat]]) * u.deg, np.array([[0.04]]))


@pytest.mark.parametrize('fast', [True, False])
def test_inclined_spot_occultation(spotted_transit, fast):
"""Both modes must produce a finite spot-crossing bump with NumPy 2."""
star, planet, lons, lats, radii = spotted_transit
times = np.linspace(-0.08, 0.08, 81)
spotted, occulted = star.light_curve(
lons, lats, radii, 90 * u.deg, planet=planet, times=times,
fast=fast, return_spots_occulted=True)
spotless = star.light_curve(
lons, lats, np.zeros_like(radii), 90 * u.deg, planet=planet,
times=times, fast=fast)
# Normalize out the constant dimming caused by the unocculted spot.
spotted /= spotted[0]
spotless /= spotless[0]

assert occulted
assert spotted.shape == (len(times), 1)
assert np.all(np.isfinite(spotted))
assert np.max(spotted - spotless) > 1e-5
assert spotted[len(times) // 2, 0] > spotless[len(times) // 2, 0]


def test_plot_inclined_spot(spotted_transit):
"""Plotting must pass scalar spot geometry to Shapely with NumPy 2.4."""
import matplotlib.pyplot as plt

star, planet, lons, lats, radii = spotted_transit
fig, ax = plt.subplots()
try:
star.plot(lons, lats, radii, 90 * u.deg, time=0, planet=planet, ax=ax)
fig.canvas.draw()
assert len(ax.patches) == 1
finally:
plt.close(fig)
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ license = { file = "LICENSE", content-type = "text/plain" }
authors = [
{ name = "Brett Morris", email = "morrisbrettm@gmail.com" },
]
# require numpy < 2 until batman supports 2.x+
dependencies = [
"astropy",
"numpy<2",
"numpy",
"scipy",
"shapely",
"matplotlib"
Expand Down
Loading