Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Bad oversample factor
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, sec, oversample=-1)
# Bad integration order
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, sec, order=99)
# Bad primary
with pytest.raises(AssertionError) as e:
sys = starry.System(sec, sec)
# Reflected light primary
with pytest.raises(AssertionError) as e:
sys = starry.System(starry.Primary(starry.Map(reflected=True)), sec)
# Bad secondary
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, pri)
# No secondaries
with pytest.raises(AssertionError) as e:
sys = starry.System(pri)
# Different number of wavelength bins
with pytest.raises(AssertionError) as e:
sys = starry.System(
pri, starry.Secondary(starry.Map(ydeg=1, nw=2), porb=1.0)
)
# RV for secondary, but not primary
def test_system_show(mp4=False):
pri = starry.Primary(starry.Map())
sec = starry.Secondary(starry.Map(), porb=1.0)
sys = starry.System(pri, sec)
sys.show(0.1, file="tmp.pdf")
os.remove("tmp.pdf")
if mp4:
sys.show([0.1, 0.2], file="tmp.mp4")
os.remove("tmp.mp4")
sys.show([0.1, 0.2], file="tmp.gif")
os.remove("tmp.gif")
def test_reflected_light():
pri = starry.Primary(starry.Map(amp=0), r=1)
sec = starry.Secondary(starry.Map(reflected=True), porb=1.0, r=1)
sys = starry.System(pri, sec)
t = np.concatenate((np.linspace(0.1, 0.4, 50), np.linspace(0.6, 0.9, 50)))
flux = sys.flux(t)
def test_default_body_units():
body = starry.Primary(starry.Map())
assert body.length_unit == u.Rsun
assert body.mass_unit == u.Msun
assert body.angle_unit == u.degree
assert body.time_unit == u.day
assert body.map.angle_unit == u.degree
def test_bad_sys_settings():
pri = starry.Primary(starry.Map())
sec = starry.Secondary(starry.Map(), porb=1.0)
# Bad exposure time
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, sec, texp=-1.0)
# Bad oversample factor
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, sec, oversample=-1)
# Bad integration order
with pytest.raises(AssertionError) as e:
sys = starry.System(pri, sec, order=99)
# Bad primary
with pytest.raises(AssertionError) as e:
def test_orientation(Omega=45, inc=35):
# Instantiate
pri = starry.Primary(starry.Map(amp=0))
sec = starry.Secondary(
starry.Map(ydeg=1, amp=1),
porb=1.0,
r=0,
m=0,
inc=inc,
Omega=Omega,
prot=1.0,
theta0=180.0,
)
sec.map[1, 0] = 1.0
sys = starry.System(pri, sec)
# Align the rotational axis with the orbital axis
sec.map.inc = sec.inc
sec.map.obl = sec.Omega
def test_system_rv_show(mp4=False):
pri = starry.Primary(starry.Map(rv=True))
sec = starry.Secondary(starry.Map(rv=True), porb=1.0)
sys = starry.System(pri, sec)
sys.show(0.1, file="tmp.pdf")
os.remove("tmp.pdf")
if mp4:
sys.show([0.1, 0.2], file="tmp.mp4")
os.remove("tmp.mp4")
def test_compare_to_exoplanet():
"""Ensure we get the same result with `starry` and `exoplanet`.
"""
# Define the star
A = starry.Primary(
starry.Map(rv=True, veq=0),
r=1.0,
m=1.0,
prot=0,
length_unit=u.Rsun,
mass_unit=u.Msun,
)
# Define the planet
b = starry.Secondary(
starry.Map(rv=True, veq=0),
r=0.1,
porb=1.0,
m=0.01,
t0=0.0,
inc=86.0,
def test_normalization(d=10, r=1):
"""Test the normalization of the flux."""
# Instantiate a system. Planet has radius `r` and is at
# distance `d` from a point illumination source.
planet = starry.Secondary(starry.Map(reflected=True), a=d, r=r)
star = starry.Primary(starry.Map(), r=0)
sys = starry.System(star, planet)
# Get the star & planet flux when it's at full phase
t_full = 0.5 * sys._get_periods()[0]
f_star, f_planet = sys.flux(t=t_full, total=False)
# Star should have unit flux
assert np.allclose(f_star, 1.0)
# Planet should have flux equal to (2 / 3) r^2 / d^2
assert np.allclose(f_planet, (2.0 / 3.0) * r ** 2 / d ** 2)