Ejemplo n.º 1
0
def test_rotations():
    """Test some elementary rotations."""
    # Instantiate
    m = Map(1)
    m.set_coeff(1, 0, 1)
    assert np.allclose(m.y, np.array([0, 0, 1, 0]))

    # Rotations and evaluations
    m.rotate([1, 0, 0], -90)
    assert np.allclose(m.y, np.array([0, 1, 0, 0]))
    assert np.allclose(m.p, np.array([0, 0, 0, np.sqrt(3 / (4 * np.pi))]))

    m.rotate([0, 0, 1], -90)
    assert np.allclose(m.y, np.array([0, 0, 0, 1]))
    assert np.allclose(m.p, np.array([0, np.sqrt(3 / (4 * np.pi)), 0, 0]))

    m.rotate([0, 1, 0], -90)
    assert np.allclose(m.y, np.array([0, 0, 1, 0]))
    assert np.allclose(m.p, np.array([0, 0, np.sqrt(3 / (4 * np.pi)), 0]))
Ejemplo n.º 2
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.º 3
0
# 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)
ax.plot(thetanum - 180, totalnum, 'k.')
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.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')