示例#1
0
def test_variance():

    sp = StarryProcess(normalized=False)
    cov = sp.cov([0.0, 0.1]).eval()
    var = sp.cov([0.0]).eval()

    assert np.allclose(cov[0, 0], var)
def test_inclination(nsamples=10000, plot=False, rtol=1e-4, ftol=0.25):
    """
    Test the inclination marginalization algorithm.

    """
    # Time array
    t = np.linspace(0, 1, 1000)

    # Compute the analytic moments
    sp = StarryProcess(normalized=False, marginalize_over_inclination=True)
    mean = sp.mean(t).eval()
    cov = sp.cov(t).eval()

    # Compute the numerical moments
    np.random.seed(0)
    mean_num, cov_num = get_numerical_mean_and_cov(t, nsamples=nsamples)

    # Visualize
    if plot:

        # The radial kernel
        plt.figure()
        plt.plot(cov[0])
        plt.plot(cov_num[0])

        # The full covariance
        fig, ax = plt.subplots(1, 3)
        vmin = np.min(cov)
        vmax = np.max(cov)
        im = ax[0].imshow(cov, vmin=vmin, vmax=vmax)
        plt.colorbar(im, ax=ax[0])
        im = ax[1].imshow(cov_num, vmin=vmin, vmax=vmax)
        plt.colorbar(im, ax=ax[1])
        im = ax[2].imshow(np.log10(np.abs((cov - cov_num) / cov)))
        plt.colorbar(im, ax=ax[2])
        plt.show()

    # Check
    rerr = np.abs(cov[0] - cov_num[0])
    assert np.max(rerr) < rtol, "relative error too large"

    ferr = np.abs((cov[0] - cov_num[0]) / cov[0, 0])
    assert np.max(ferr) < ftol, "fractional error too large"
示例#3
0
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from starry_process import StarryProcess, gauss2beta
import os

# GP settings
r = 15  # spot radius in degrees
mu, sig = 30, 5  # spot latitude and std. dev. in degrees
c = 0.05  # spot contrast
n = 20  # number of spots
t = np.linspace(0, 1.5, 1000)
a, b = gauss2beta(mu, sig)

# Covariance of the original process
sp = StarryProcess(r=r, a=a, b=b, c=c, n=n, normalized=False)
Sigma = sp.cov(t).eval()

# Covariance of the normalized process
sp_norm = StarryProcess(r=r, a=a, b=b, c=c, n=n, normalized=True)
Sigma_norm = sp_norm.cov(t).eval()

# Figure setup
fig, ax = plt.subplots(1, 2, figsize=(12, 6))
vmin = Sigma_norm.min()
vmax = Sigma_norm.max()

# Original
im = ax[0].imshow(Sigma, cmap="viridis", vmin=vmin, vmax=vmax)
divider = make_axes_locatable(ax[0])
cax = divider.append_axes("right", size="5%", pad=0.1)
cbar = plt.colorbar(im, cax=cax)