Ejemplo n.º 1
0
def test_occultations():
    """Test occultation light curves."""
    # Let's do the l = 3 Earth
    map = Map(3)
    map.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
    map.axis = axis
    sF = np.array(map.flux(theta=theta, xo=xo, yo=yo, ro=ro))
    nF = np.array(map.flux(theta=theta, xo=xo, yo=yo, ro=ro, numerical=True))

    # 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 < 0.03
Ejemplo n.º 2
0
def test_phasecurves():
    """Test transit light curve generation."""
    # Let's do the l = 3 Earth
    map = Map(3)
    map.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)
    map.axis = [ux, uy, uz]
    theta = np.linspace(0, 360, 25, endpoint=False)
    sF = map.flux(theta=theta)

    # Compute the flux numerically
    nF = [NumericalFlux(map, 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
"""Smiley spherical harmonic example."""
from starry import Map
import matplotlib.pyplot as pl
import numpy as np

# Generate a sample starry map
map = Map(5)
map[5, -3] = -2
map[5, 0] = 2
map[5, 4] = 1
map.axis = [0, 1, 0]

# Render it under consecutive rotations
nax = 9
fig, ax = pl.subplots(1, nax, figsize=(3 * nax, 3))
theta = np.linspace(-90, 90, nax, endpoint=True)
x = np.linspace(-1, 1, 300)
y = np.linspace(-1, 1, 300)
x, y = np.meshgrid(x, y)
for i in range(nax):
    I = [map(theta=theta[i], x=x[j], y=y[j]) for j in range(300)]
    ax[i].imshow(I, origin="lower", interpolation="none", cmap='plasma')
    ax[i].axis('off')

# Save
pl.savefig('smiley.pdf', bbox_inches='tight')
Ejemplo n.º 5
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.axis = [0, 1, 0]
m.rotate(-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(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.º 6
0
    ax[-1, j].set_xlabel(r"$m = %d$" % m, labelpad=30, fontsize=12)

# Rotate about this vector
ux = np.array([1., 0., 0.])
uy = np.array([0., 1., 0.])
map = Map(lmax)
theta = np.linspace(0, 360, nt, endpoint=False)
thetan = np.linspace(0, 360, nn, endpoint=False)
for i, l in enumerate(range(lmax + 1)):
    for j, m in enumerate(range(l + 1)):
        nnull = 0
        for axis, zorder, color in zip([ux, uy], [1, 0], ['C0', 'C1']):
            map.reset()
            map[0, 0] = 0
            map[l, m] = 1
            map.axis = axis
            flux = map.flux(theta=theta)
            ax[i, j].plot(theta, flux, lw=1, zorder=zorder, color=color)
            fluxn = map.flux(theta=thetan, numerical=True)
            ax[i, j].plot(thetan, fluxn, '.', ms=2, zorder=zorder, color=color)
            if np.max(np.abs(flux)) < 1e-10:
                nnull += 1
        # If there's no light curve, make sure our plot range
        # isn't too tight, as it will zoom in on floating point error
        if nnull == 2:
            ax[i, j].set_ylim(-1, 1)
# Force the scale for the constant map
ax[0, 0].set_ylim(0.886 + 1, 0.886 - 1)

# Hack a legend
axleg = pl.axes([0.7, 0.7, 0.15, 0.15])