Exemple #1
0
def lnlike(theta, fit_params, flux, err):
    fit_params[3] = theta[0]
    planetx, planety, z, rp, r, f, spotx, spoty, spotradius, spotcontrast = fit_params
    fit = spotrod.integratetransit(
        planetx, planety, z, rp, r, f, np.array([spotx]), np.array([spoty]),
        np.array([spotradius]), np.array([spotcontrast]),
        np.array(
            [spotrod.circleangle(r, rp, z[i]) for i in xrange(z.shape[0])]))
    residuals = flux - fit
    return -0.5 * (np.nansum((residuals / err)**2.))
Exemple #2
0
def lightcurve(t0,per,rp,inc,c1,c2):
    f=2.0*quadraticlimbdarkening(r,c1,c2)
    t_f=t-t0
    smacm=(((per*24.*60.*60.)**2.*Grav*Ms)/(4*np.pi**2.))**(1./3.)
    sma=smacm/Rs
    MA=(2*np.pi/per)*t_f
    eta=sma*np.cos(MA)
    xi=sma*np.sin(MA)
    b=sma*np.cos(inc*np.pi/180.)
    planetx=b*eta/sma
    planety=-xi
    z=np.sqrt(planetx**2.+planety**2.)
    planetangle=np.array([spotrod.circleangle(r,rp,z[i]) for i in xrange(z.shape[0])])
    fitlightcurve=spotrod.integratetransit(planetx,planety,z,rp,r,f,np.array([spotx]),np.array([spoty]),np.array([spotradius]),np.array([spotcontrast]),planetangle)
    return fitlightcurve
Exemple #3
0
def lightcurve(fitparams, period, sma):
    # Calculate orbital elements.
    f, rp = fit_params
    #    eta, xi = spotrod.elements(t, period, semimajoraxis, k, h)
    #    if not np.isfinite(np.mean(eta)):
    Mean_Anomaly = (2 * np.pi / period) * t
    eta = semimajoraxis * np.cos(Mean_Anomaly)
    xi = semimajoraxis * np.sin(Mean_Anomaly)
    impactparam = semimajoraxis * np.cos(85.35 * np.pi / 180.)
    planetx = impactparam * eta / semimajoraxis
    planety = -xi
    z = np.sqrt(np.power(planetx, 2) + np.power(planety, 2))
    # Calculate planetangle array.
    planetangle = np.array(
        [spotrod.circleangle(r, rp, z[i]) for i in xrange(z.shape[0])])
    fitlightcurve = spotrod.integratetransit(
        planetx, planety, z, rp, r, f, np.array([spotx1, spotx2]),
        np.array([spoty1, spoty2]), np.array([spotradius1, spotradius2]),
        np.array([spotcontrast1, spotcontrast2]), planetangle)
    return fitlightcurve
Exemple #4
0
spoty=0.0
spotradius=0.0
spotcontrast=1.0

t_f=t-t0
f=2.0*quadraticlimbdarkening(r,u1,u2)
smacm=(((per*24.*60.*60.)**2.*Grav*Ms)/(4*np.pi**2.))**(1./3.)
sma=smacm/Rs
MA=(2*np.pi/per)*t_f
eta=sma*np.cos(MA)
xi=sma*np.sin(MA)
b=sma*np.cos(inc*np.pi/180.)
planetx=b*eta/sma
planety=-xi
z=np.sqrt(planetx**2.+planety**2.)
planetangle=np.array([spotrod.circleangle(r,rp,z[i]) for i in xrange(z.shape[0])])

def lightcurve(spotx,spoty,spotradius,spotcontrast):
    fitlightcurve=spotrod.integratetransit(planetx,planety,z,rp,r,f,np.array([spotx]),np.array([spoty]),np.array([spotradius]),np.array([spotcontrast]),planetangle)
    return fitlightcurve


####################################################
#     Prior, Likelihood, Posterior Functions       #
####################################################
def loggaus(mean,sig,param):
    return -np.log(np.sqrt(2*np.pi*sig**2.))-((param-mean)**2.)/(2*sig**2.)

def lnprior(theta):
    spotx,spoty,spotradius,spotcontrast=theta
    if spotx<=1.0 and spotx>=-1.0 and spoty<=1.0 and spoty>-1.0 and spotx**2.+spoty**2.<1.0 and spotcontrast<=1.0 and spotcontrast>=0.0 and spotradius<=1.0 and spotradius>=0.0:
Exemple #5
0
def lightcurve(rp,c1,c2,spotcontrast):
    f=2.0*quadraticlimbdarkening(r,c1,c2)
    planetangle=np.array([spotrod.circleangle(r,rp,z[i]) for i in xrange(z.shape[0])])
    fitlightcurve=spotrod.integratetransit(planetx,planety,z,rp,r,f,np.array([spotx]),np.array([spoty]),np.array([spotradius]),np.array([spotcontrast]),planetangle)
    return fitlightcurve
Exemple #6
0
# Weights: 2.0 times limb darkening times width of integration annulii.
f = 2.0 * quadraticlimbdarkening(r, u1, u2) / n;

# Alternative: trapeziod rule.
#r = numpy.linspace(0.0, 1.0, n);
#f = 2.0 * quadraticlimbdarkening(r, u1, u2) * numpy.append(numpy.append([0.5], numpy.repeat(1.0, n-2)), [0.5]) / (n-1);

# Calculate orbital elements.
eta, xi = spotrod.elements(timebkjd-midtransit, period, semimajoraxis, k, h);
# Planet coordinates in sky plane, in Rstar units.
planetx = impactparam*eta/semimajoraxis;
planety = -xi;
# Distance from center, same as $z$ in Mandel, Agol 2002.
z = numpy.sqrt(numpy.power(planetx,2) + numpy.power(planety,2));
# Calculate planetangle array.
planetangle = numpy.array([spotrod.circleangle(r, rp, z[i]) for i in xrange(z.shape[0])]);

# Prior for spot parameters: isotropic on the surface of the sphere.
logp = lambda p: -0.5 * numpy.sum(numpy.log((1.0 - numpy.power(p[0::4], 2.0) - numpy.power(p[1::4], 2.0))));

# Likelihood for spot parameters.
logl = lambda p: numpy.sum(numpy.power(spotrod.integratetransit(planetx, planety, z, rp, r, f, p[0::4], p[1::4], p[2::4], p[3::4], planetangle) - flux, 2.0) * minusoneovertwofluxerrsquared);

# We have one spot, therefore phase space is 4D.
ndim = 4;
# Number of temperatures.
ntemps = 10;
# Number of parallel walkers at each temperature.
nwalkers = 100;
# Number of iterations.
niter = 1000;
Exemple #7
0
def spot_model(t, cube, nspot, texp=0.01881944, RESAMPLE=False, NRESAMPLE=20):
    if RESAMPLE:
        tin = np.array([])
        for i in range(len(t)):
            for j in range(NRESAMPLE):
                jj = j + 1
                tin = np.append(
                    tin,
                    t[i] + (jj - (NRESAMPLE + 1) / 2.) * (texp / NRESAMPLE))
    else:
        tin = t
    # Extract parameters:
    if nspot == 0:
        rp, aR, inc, t0, q1, q2 = cube[0], cube[1], cube[2], cube[3], cube[
            4], cube[5]
    elif nspot == 1:
        rp,aR,inc,t0,q1,q2,spotx,spoty,spotradius,spotcontrast = cube[0],cube[1],\
                   cube[2],cube[3],cube[4],cube[5],cube[6],cube[7],cube[8],cube[9]
    elif nspot == 2:
        rp,aR,inc,t0,q1,q2,spotx,spoty,spotradius,spotcontrast,spotx2,spoty2,spotradius2,\
        spotcontrast2 = cube[0],cube[1],cube[2],cube[3],cube[4],cube[5],cube[6],cube[7],cube[8],\
                        cube[9],cube[10],cube[11],cube[12],cube[13]
    # Generate model:
    impactparam = aR * np.cos(inc * deg_to_rad)
    phase = np.mod((tin - t0) / P + 0.5, 1.0) - 0.5
    s1, s2 = reverse_ld_coeffs(ld_law, q1, q2)
    # Initialize spotrod. Number of intergration rings:
    n = 1500
    # Integration annulii radii.
    r = np.linspace(1.0 / (2 * n), 1.0 - 1.0 / (2 * n), n)
    # Weights: 2.0 times limb darkening times width of integration annulii.
    f = 2.0 * quadraticlimbdarkening(r, s1, s2) / n
    # Calculate orbital elements.
    if k == 0. and h == 0.:
        # spotrod.elements (which uses the general equations of Pal, 2009MNRAS.396.1737P)
        # fail to extract proper eta and xi for the case of circular orbits. It is however
        # easy to obtain these following the paper (eqs. 6 and 7 on eqs 2 and 3):
        M = (tin - t0) * (2 * np.pi) / P
        lam = M + omega * deg_to_rad
        eta0, xi0 = aR * np.cos(lam), aR * np.sin(lam)
        eta,xi = eta0*np.cos(omega*deg_to_rad) - xi0*np.sin(omega*deg_to_rad),\
                 eta0*np.sin(omega*deg_to_rad) + xi0*np.cos(omega*deg_to_rad)
    else:
        eta, xi = spotrod.elements(tin - t0, P, aR, k, h)
    planetx = impactparam * eta / aR
    planety = -xi
    z = np.sqrt(np.power(planetx, 2) + np.power(planety, 2))
    planetangle = np.array(
        [spotrod.circleangle(r, rp, z[i]) for i in xrange(z.shape[0])])

    if nspot == 0:
        spotx, spoty, spotradius, spotcontrast = 0., 0., 0., 1.
        model = spotrod.integratetransit(planetx, planety, z, rp, r, f, np.array([spotx]),\
                np.array([spoty]), np.array([spotradius]), np.array([spotcontrast]), planetangle)
    elif nspot == 1:
        model = spotrod.integratetransit(planetx, planety, z, rp, r, f, np.array([spotx]),\
                np.array([spoty]), np.array([spotradius]), np.array([spotcontrast]), planetangle)
    elif nspot == 2:
        model = spotrod.integratetransit(planetx, planety, z, rp, r, f, np.array([spotx,spotx2]),\
                np.array([spoty,spoty2]), np.array([spotradius,spotradius2]), np.array([spotcontrast,spotcontrast2]), planetangle)
    if RESAMPLE:
        model_out = np.zeros(len(t))
        for i in range(len(t)):
            model_out[i] = np.mean(model[i * NRESAMPLE:NRESAMPLE * (i + 1)])
        return model_out
    return model
Exemple #8
0
r = numpy.linspace(1.0 / (2 * n), 1.0 - 1.0 / (2 * n), n)
# Weights: 2.0 times limb darkening times width of integration annulii.
f = 2.0 * quadraticlimbdarkening(r, u1, u2) / n

# Alternative: trapeziod rule.
#r = numpy.linspace(0.0, 1.0, n);
#f = 2.0 * quadraticlimbdarkening(r, u1, u2) * numpy.append(numpy.append([0.5], numpy.repeat(1.0, n-2)), [0.5]) / (n-1);

# Calculate orbital elements.
eta, xi = spotrod.elements(timebkjd - midtransit, period, semimajoraxis, k, h)
planetx = impactparam * eta / semimajoraxis
planety = -xi
z = numpy.sqrt(numpy.power(planetx, 2) + numpy.power(planety, 2))
# Calculate planetangle array.
planetangle = numpy.array(
    [spotrod.circleangle(r, rp, z[i]) for i in xrange(z.shape[0])])

spotx = 0.204
spoty = 0.376
spotradius = 0.096
spotcontrast = 0.524

fitlightcurve = spotrod.integratetransit(planetx, planety, z, rp, r, f,
                                         numpy.array([spotx]),
                                         numpy.array([spoty]),
                                         numpy.array([spotradius]),
                                         numpy.array([spotcontrast]),
                                         planetangle)

pyplot.plot(phase, flux, "b.")
pyplot.plot(phase, fitlightcurve, "k-")