In [1]:
import batman
import numpy as np
import matplotlib.pyplot as plt
% matplotlib inline
import scipy.optimize as spicy

In [2]:
import astropy.io.ascii
table = astropy.io.ascii.read('kepler1b.txt')
time = table['time']
flux = table['flux']
nflux = flux/np.median(flux)
uncertainty = table['uncertainty']
plt.plot(time, nflux)


Out[2]:
[<matplotlib.lines.Line2D at 0x7f8d8db1b150>]

In [13]:
def batmanCurveFit(xdata, t0, rp0):
    params = batman.TransitParams()
    params.t0 = t0                     #time of inferior conjunction
    params.per = 2.47061317              #orbital period
    params.rp = rp0                  #planet radius (in units of stellar radii)
    params.a = 7.903                     #semi-major axis (in units of stellar radii)
    params.inc = 83.872                  #orbital inclination (in degrees)
    params.ecc = 0.0                     #eccentricity
    params.w = 0.0                       #longitude of periastron (in degrees)
    params.u = [0.1, 0.3]                #limb darkening coefficients
    params.limb_dark = "quadratic"       #limb darkening model


    m = batman.TransitModel(params, xdata)
    flux = m.light_curve(params)
    return flux

In [14]:
fitThis = spicy.curve_fit(f =batmanCurveFit, xdata = time, ydata = nflux, sigma = uncertainty)
xbest, ybest = fitThis[0]
plt.plot(time, nflux)
plt.plot(time, batmanCurveFit(time, xbest, ybest), color = 'red')
#plt.xlim(122, 124)
plt.ylim(0.98, 1.01)


Out[14]:
(0.98, 1.01)

In [15]:
print uncertainty


uncertainty
-----------
    91.5245
    91.5119
    91.5345
    91.5173
    91.5306
    91.5475
    91.5207
    91.5474
     91.508
    91.5281
        ...
    91.5747
    91.5607
    91.5275
    91.5643
     91.567
     91.552
    91.5423
    91.5443
    91.5433
    91.5461
    91.5596
Length = 14237 rows

In [ ]: