Ejemplo n.º 1
0
def test_occultations():
    """Test occultation light curves."""
    # Let's do the l = 3 Earth
    m = Map(3)
    m.load_image('earth')

    # Rotate the map about a random axis
    ux = np.random.random()
    uy = np.random.random() * (1 - ux)
    uz = np.sqrt(1 - ux ** 2 - uy ** 2)
    axis = [ux, uy, uz]
    npts = 30
    theta = np.linspace(0, 360, npts, endpoint=False)

    # Small occultor
    ro = 0.3
    xo = np.linspace(-1 - ro - 0.1, 1 + ro + 0.1, npts)
    yo = 0

    # Analytical and numerical fluxes
    sF = np.array(m.flux(axis=axis, theta=theta, xo=xo, yo=yo, ro=ro))
    nF = np.array(m._flux_numerical(axis=axis, theta=theta, xo=xo, yo=yo,
                                    ro=ro, tol=1e-6))

    # Compute the (relative) error
    error = np.max(np.abs(sF - nF))

    # Our numerical integration scheme isn't the most accurate,
    # so let's be lenient here!
    assert error < 1e-2
Ejemplo n.º 2
0
def test_phasecurves():
    """Test transit light curve generation."""
    # Let's do the l = 3 Earth
    m = Map(3)
    m.load_image('earth')

    # Compute the starry phase curve about a random axis
    ux = np.random.random()
    uy = np.random.random() * (1 - ux)
    uz = np.sqrt(1 - ux**2 - uy**2)
    axis = [ux, uy, uz]
    theta = np.linspace(0, 360, 25, endpoint=False)
    sF = m.flux(axis=axis, theta=theta)

    # Compute the flux numerically
    nF = [NumericalFlux(m, axis, t) for t in theta]

    # Compute the error
    error = np.max(np.abs((sF - nF) / sF))

    # We're computing the numerical integral at very low precision
    # so that this test doesn't take forever, so let's be lenient here!
    assert error < 1e-4
Ejemplo n.º 3
0
def test_small(benchmark=0.1):
    """Small occultor."""
    # Let's do the l = 5 Earth
    map = Map(5)
    map.load_image('earth')

    # Occultation properties
    npts = 10550
    ro = 0.1
    xo = np.linspace(-1 - ro, 1 + ro, npts)
    yo = np.linspace(-0.1, 0.1, npts)
    theta = np.linspace(0, 90, npts)
    map.axis = [1, 1, 1] / np.sqrt(3)

    # Analytical and numerical fluxes
    t = np.zeros(10)
    for i in range(10):
        tstart = time.time()
        map.flux(theta=theta, xo=xo, yo=yo, ro=ro)
        t[i] = time.time() - tstart
    t = np.mean(t)

    # Print
    print("Time [Benchmark]: %.3f [%.3f]" % (t, benchmark))
Ejemplo n.º 4
0
"""Earth spherical harmonic example."""
from starry import Map
import matplotlib.pyplot as pl
import numpy as np

# Generate a sample starry map
m = Map(10)
m.load_image('earth')

# Start centered at longitude 180 W
m.rotate([0, 1, 0], -180)

# Render it under consecutive rotations
nax = 8
res = 300
fig, ax = pl.subplots(1, nax, figsize=(3 * nax, 3))
theta = np.linspace(0, 360, nax, endpoint=False)
x, y = np.meshgrid(np.linspace(-1, 1, res), np.linspace(-1, 1, res))
for i in range(nax):
    # starry functions accept vector arguments, but not matrix arguments,
    # so we need to iterate below:
    I = [
        m.evaluate(axis=[0, 1, 0], theta=-theta[i], x=x[j], y=y[j])
        for j in range(res)
    ]
    ax[i].imshow(I, origin="lower", interpolation="none", cmap='plasma')
    ax[i].axis('off')

# Save
pl.savefig('earth.pdf', bbox_inches='tight')
Ejemplo n.º 5
0
total = np.zeros(npts, dtype=float)

# Compute the phase curves for each continent
base = 0.65
continents = [
    'asia.jpg', 'africa.jpg', 'southamerica.jpg', 'northamerica.jpg',
    'oceania.jpg', 'europe.jpg', 'antarctica.jpg'
]
labels = [
    'Asia', 'Africa', 'S. America', 'N. America', 'Oceania', 'Europe',
    'Antarctica'
]
map = Map(10)
map.axis = [0, 1, 0]
for continent, label in zip(continents, labels):
    map.load_image(continent)
    map.rotate(-180)
    F = map.flux(theta=theta)
    F -= np.nanmin(F)
    ax.plot(theta - 180, F, label=label)

# Compute and plot the total phase curve
map.load_image('earth.jpg')
map.rotate(-180)
total = map.flux(theta=theta)
total /= np.max(total)
ax.plot(theta - 180, total, 'k-', label='Total')

# Compute and plot the total phase curve (numerical)
totalnum = map.flux(theta=thetanum, numerical=True)
totalnum /= np.max(totalnum)
Ejemplo n.º 6
0
from starry import Map
import matplotlib.pyplot as pl
import numpy as np

# Set up the plot
nim = 12
npts = 100
nptsnum = 10
res = 300
fig = pl.figure(figsize=(12, 5))
ax_im = [pl.subplot2grid((4, nim), (0, n)) for n in range(nim)]
ax_lc = pl.subplot2grid((4, nim), (1, 0), colspan=nim, rowspan=3)

# Instantiate the earth
map = Map(10)
map.load_image('earth')
map.axis = [0, 1, 0]

# Moon params
ro = 0.273
yo = np.linspace(-0.5, 0.5, npts)
yonum = np.linspace(-0.5, 0.5, nptsnum)
xo = np.linspace(-1.5, 1.5, npts)
xonum = np.linspace(-1.5, 1.5, nptsnum)

# Say the occultation occurs over ~1 radian of the Earth's rotation
# That's equal to 24 / (2 * pi) hours
# (Remember, though, that `starry` accepts **DEGREES** as input!)
time = np.linspace(0, 24 / (2 * np.pi), npts)
timenum = np.linspace(0, 24 / (2 * np.pi), nptsnum)
theta0 = 0