def ret_sum_ln(params, time, flux, yerr):
    (period, T0, rprs, impact, alb, occ, ell, ecosw, esinw, lnnoiseA1,
     lnnoiseW1, lnnoiseA2, lnnoiseW2) = params
    M = LCModel()
    M.add_star(rho=0.0073, ld1=0.5, ld2=0.4)
    M.add_planet(T0=T0,
                 period=period,
                 impact=impact,
                 rprs=rprs,
                 alb=alb,
                 occ=occ,
                 ell=ell,
                 ecosw=ecosw,
                 esinw=esinw)
    M.add_data(time=time)
    resid = flux - M.transitmodel
    kernel = ((np.exp(lnnoiseA1)**2 * RBFKernel(np.exp(lnnoiseW1))) +
              (np.exp(lnnoiseA2)**2 * RBFKernel(np.exp(lnnoiseW2))))
    gp = george.GaussianProcess(kernel)
    lnlike = 0.
    for i in np.arange(len(time) // 1000)[0:10]:
        section = np.arange(i * 1000, i * 1000 + 1000)
        gp.compute(time[section], yerr[section])
        lnlike += gp.lnlikelihood(resid[section])
    return -lnlike
示例#2
0
def get_sample(chain_vals, time, flux, ferr, rvtime):
    M = LCModel()
    M.add_star(rho=chain_vals[0],
               zpt=chain_vals[1],
               ld1=chain_vals[2],
               ld2=chain_vals[3],
               veloffset=chain_vals[4])
    M.add_planet(T0=chain_vals[7],
                 period=chain_vals[8],
                 impact=chain_vals[9],
                 rprs=chain_vals[10],
                 ecosw=chain_vals[11],
                 esinw=chain_vals[12],
                 rvamp=chain_vals[13],
                 occ=chain_vals[14],
                 ell=chain_vals[15],
                 alb=chain_vals[16])
    M.add_data(time=time)
    M.add_rv(rvtime=rvtime)

    #kernel = ((chain_vals[5]**2 * RBFKernel(chain_vals[6])) +
    #        (chain_vals[7]**2 * RBFKernel(chain_vals[8])))
    #kernel = ((chain_vals[5]**2 * ExpKernel(chain_vals[6])) +
    #        (chain_vals[7]**2 * RBFKernel(chain_vals[8])))
    kernel = chain_vals[5]**2 * RBFKernel(chain_vals[6])
    gp = george.GaussianProcess(kernel)

    sample = np.array([])
    for i in np.arange(len(time) // 1000):
        section = np.arange(i * 1000, i * 1000 + 1000)
        gp.compute(time[section], ferr[:][section])
        sample = np.r_[sample,
                       gp.predict(flux[:][section] -
                                  M.transitmodel[section], time[section])[0]]
    return sample, M.transitmodel
示例#3
0
def get_sample(gp1, gp2, time, resid, ferr):
    kernel = gp1**2 * RBFKernel(gp2)
    gp = george.GaussianProcess(kernel)

    slist = np.arange(len(time) // 1000)
    sample = np.zeros(len(slist) * 1000)
    for i in slist:
        section = np.arange(i * 1000, i * 1000 + 1000)
        gp.compute(time[section], ferr[:][section])
        sample[section] = gp.predict(resid[section], time[section])[0]
    return sample
示例#4
0
def get_many_samples(gp1, gp2, time, resid, ferr, nsamples=300):
    kernel = gp1**2 * RBFKernel(gp2)
    gp = george.GaussianProcess(kernel)

    slist = np.arange(len(time) // 1000)
    samples = np.zeros([nsamples, len(slist) * 1000])
    for i in slist:
        section = np.arange(i * 1000, i * 1000 + 1000)
        gp.compute(time[section], ferr[:][section])
        samples[:, section] = gp.sample_conditional(resid[section],
                                                    time[section],
                                                    size=nsamples)
    return samples
示例#5
0
def get_many_samples(chain_vals, time, flux, ferr, rvtime, nsamples=300):
    M = LCModel()
    M.add_star(rho=chain_vals[0],
               zpt=chain_vals[1],
               ld1=chain_vals[2],
               ld2=chain_vals[3],
               veloffset=chain_vals[4])
    M.add_planet(T0=chain_vals[7],
                 period=chain_vals[8],
                 impact=chain_vals[9],
                 rprs=chain_vals[10],
                 ecosw=chain_vals[11],
                 esinw=chain_vals[12],
                 rvamp=chain_vals[13],
                 occ=chain_vals[14],
                 ell=chain_vals[15],
                 alb=chain_vals[16])
    M.add_data(time=time)
    M.add_rv(rvtime=rvtime)

    #kernel = ((chain_vals[5]**2 * RBFKernel(chain_vals[6])) +
    #        (chain_vals[7]**2 * RBFKernel(chain_vals[8])))
    #kernel = ((chain_vals[5]**2 * ExpKernel(chain_vals[6])) +
    #        (chain_vals[7]**2 * RBFKernel(chain_vals[8])))
    kernel = chain_vals[5]**2 * RBFKernel(chain_vals[6])
    gp = george.GaussianProcess(kernel)

    slist = np.arange(len(time) // 1000)
    samples = np.zeros([nsamples, len(slist) * 1000])
    for i in slist:
        section = np.arange(i * 1000, i * 1000 + 1000)
        gp.compute(time[section], ferr[:][section])
        samples[:, section] = gp.sample_conditional(flux[:][section] -
                                                    M.transitmodel[section],
                                                    time[section],
                                                    size=nsamples)
    return samples, M.transitmodel
def ret_simplest(params, time, flux, yerr, fixed):
    (period, T0, rprs, impact, alb, occ, ell, ecosw, esinw) = fixed
    (noiseA1, noiseW1) = params
    M = LCModel()
    M.add_star(rho=0.0073, ld1=0.5, ld2=0.4)
    M.add_planet(T0=T0,
                 period=period,
                 impact=impact,
                 rprs=rprs,
                 alb=alb,
                 occ=occ,
                 ell=ell,
                 ecosw=ecosw,
                 esinw=esinw)
    M.add_data(time=time)
    resid = flux - M.transitmodel
    kernel = (noiseA1**2 * RBFKernel(noiseW1))
    gp = george.GaussianProcess(kernel)
    lnlike = 0.
    for i in np.arange(len(time) // 300):
        section = np.arange(i * 300, i * 300 + 300)
        gp.compute(time[section], yerr[section])
        lnlike += gp.lnlikelihood(resid[section])
    return -lnlike
                  (None, None), (None, None), (None, None), (None, None),
                  (None, None), (None, None), (None, None), (None, None),
                  (None, None))
        guess = (6.24658, 136.3966, 0.02255, 0.8, 30., 30., 60., 0.0, 0.0,
                 np.log(5.E-4), np.log(0.07), np.log(2.E-4), np.log(3.0))
        lsqout = optimize.fmin_l_bfgs_b(ret_sum_ln,
                                        guess,
                                        args=(time, flux, ferr),
                                        approx_grad=True,
                                        bounds=bounds,
                                        m=300,
                                        factr=1.E7)

        (period, T0, rprs, impact, alb, occ, ell, ecosw, esinw, lnnoiseA1,
         lnnoiseW1, lnnoiseA2, lnnoiseW2) = lsqout[0]
        kernel = ((np.exp(lnnoiseA1)**2 * RBFKernel(np.exp(lnnoiseW1))) +
                  (np.exp(lnnoiseA2)**2 * RBFKernel(np.exp(lnnoiseW2))))
        gp = george.GaussianProcess(kernel)

    elif simple:
        bounds = ((None, None), (None, None), (0.01, 0.03), (0.00001, 0.999),
                  (None, None), (None, None), (None, None), (None, None),
                  (None, None), (None, None), (None, None))
        guess = (6.2465796, 136.39661, 0.02255, 0.4, 30., 30., 60., 0.0, 0.0,
                 5.E-4, 0.07)
        lsqout = optimize.fmin_l_bfgs_b(ret_simple,
                                        guess,
                                        args=(time, flux, ferr),
                                        approx_grad=True,
                                        bounds=bounds,
                                        m=300,
def logchi2_rv_phaseGP_noHP(fitsol,nplanets,rho_0,rho_0_unc,rho_prior,
    ld1_0,ld1_0_unc,ld2_0,ld2_0_unc,ldp_prior,
    flux,err,fixed_sol,time,itime,ntt,tobs,omc,datatype,
    rvtime,rvval,rverr,rvitime,
    n_ldparams=2,ldfileloc='/Users/tom/svn_code/tom_code/',
    onlytransits=False,tregion=0.0):

    """
    fitsol should have the format
    rho_0,zpt_0,ld1,ld2,veloffset
    plus for each planet
    T0_0,per_0,b_0,rprs_0,ecosw_0,esinw_0,rvamp_0,occ_0,ell_0,alb_0

    fixed_sol should have
    dil

    """
    minf = -np.inf

    rho = fitsol[0]
    if rho < 1.E-8 or rho > 100.:
        return minf

    zpt = fitsol[1]
    if np.abs(zpt) > 1.E-2:
        return minf


    ld1 = fitsol[2]
    ld2 = fitsol[3]
    #some lind darkening constraints
    #from Burke et al. 2008 (XO-2b)
    if ld1 < 0.0:
        return minf
    if ld1 + ld2 > 1.0:
        return minf
    if ld1 + 2.*ld2 < 0.0:
        return minf
    if ld2 < -0.8:
        return minf

    if n_ldparams == 2:
        ld3, ld4 = 0.0,0.0

    ## GP params 5,6,7,8
    ## I am a bad person
    ## Hard code GP hyperparameters
    GP1 = #!!!!!!!!!!!!!!!!!!!!!!!!!!
    GP2 =
    #GP3 = fitsol[7]
    #GP4 = fitsol[8]
    if GP1 < 0.0:
        return minf
    if GP2 < 0.0:
        return minf
    #if GP3 < 0.0:
    #    return minf
    #if GP4 < 0.0:
    #    return minf


    #T0, period, b, rprs, ecosw, esinw

    rprs = fitsol[np.arange(nplanets)*7 + 8]
    if np.any(rprs < 0.) or np.any(rprs > 0.5):
        return minf

    ecosw = fitsol[np.arange(nplanets)*7 + 9]
    if np.any(ecosw < -1.0) or np.any(ecosw > 1.0):
        return minf

    esinw = fitsol[np.arange(nplanets)*7 + 10]
    if np.any(esinw < -1.0) or np.any(esinw > 1.0):
        return minf

    #avoid parabolic orbits
    ecc = np.sqrt(esinw**2 + ecosw**2)
    if np.any(ecc > 1.0):
        return minf

    #avoid orbits where the planet enters the star
    per = fitsol[np.arange(nplanets)*7 + 6]
    ar = get_ar(rho,per)
    if np.any(ecc > (1.-(1./ar))):
        return minf

    b = fitsol[np.arange(nplanets)*7 + 7]
    if np.any(b < 0.) or np.any(b > 1.0 + rprs):
        return minf

    if onlytransits:
        T0 = fitsol[np.arange(nplanets)*7 + 5]
        if np.any(T0 < T0 - tregion) or np.any(T0 > T0 + tregion):
            return minf


    ## extra priors for KOI-2133 !!!!
    ## !!!!!!!!!!!!!!!!!!!!!
    ## this code will fail if there are multiple planets
    jitter_lc = fitsol[-2]
    jitter_rv = fitsol[-1]

    if jitter_rv > 25:
        return minf

    veloffset = fitsol[4]
    if np.abs(veloffset) > 50:
        return minf

    rvamp = fitsol[np.arange(nplanets)*7 + 11]
    occ = fitsol[np.arange(nplanets)*7 + 12]
    ell = fitsol[np.arange(nplanets)*7 + 13]
    alb = fitsol[np.arange(nplanets)*7 + 14]

    if np.abs(rvamp) > 300:
        return minf
    if np.abs(occ) > 300 or occ < 0.:
        return minf
    if np.abs(ell) > 500 or ell < 00.:
        return minf
    if np.abs(alb) > 500 or alb < 0.:
        return minf
    if ecc > 0.6:
        return minf


    if jitter_lc < 0.0:
        return minf
    err_jit = np.sqrt(err**2 + jitter_lc**2)
    err_jit2 = err**2 + jitter_lc**2


    if jitter_rv < 0.0:
        return minf
    rverr_jit = np.sqrt(rverr**2 + jitter_rv**2)
    rverr_jit2 = rverr**2 + jitter_rv**2

    lds = np.array([ld1,ld2,ld3,ld4])

    #need to do some funky stuff
    #so I can use the same calc_model as
    #the other transitemcee routines

    fitsol_model_calc = np.r_[fitsol[0:2],fitsol[4:]] #cut out limb darkening
    fixed_sol_model_calc = np.r_[lds,fixed_sol]

    time_model_calc = np.r_[time,rvtime]
    itime_model_calc = np.r_[itime,rvitime]
    datatype_model_calc  = np.r_[datatype,np.ones_like(rvtime)]

    model_lcrv = calc_model_phase(fitsol_model_calc,
        nplanets,fixed_sol_model_calc,
        time_model_calc,itime_model_calc,ntt,tobs,omc,datatype_model_calc)

    model_lc = model_lcrv[datatype_model_calc == 0] - 1.
    model_rv = model_lcrv[datatype_model_calc == 1]


    ecc[ecc == 0.0] = 1.E-10

    npt_lc = len(err_jit)
    npt_rv = len(rverr_jit)

    #do the GP stuff
    resid = flux - model_lc
    kernel = (GP1**2 * RBFKernel(GP2))
    gp = george.GaussianProcess(kernel)
    lnlike = 0.

    for i in np.arange(len(time) // 1000):
        section = np.arange(i*1000,i*1000 + 1000)
        gp.compute(time[section], err_jit[section])
        lnlike += gp.lnlikelihood(resid[section])

#    loglc = (
#        - (npt_lc/2.)*np.log(2.*np.pi)
#        - 0.5 * np.sum(np.log(err_jit2))
#        - 0.5 * np.sum((res)**2 / err_jit2)
#        )
    loglc = lnlike

    logrv = (
        - (npt_rv/2.)*np.log(2.*np.pi)
        - 0.5 * np.sum(np.log(rverr_jit2))
        - 0.5 * np.sum((model_rv - rvval)**2 / rverr_jit2)
        )

    if rho_prior:
        logrho = (
            - 0.5 * np.log(2.*np.pi)
            - 0.5 * np.log(rho_0_unc)
            - 0.5 * (rho_0 - rho)**2 / rho_0_unc**2
            )
    else:
        rho_prior = 0.0

    if ldp_prior:
        logld1 = (
            - 0.5 * np.log(2.*np.pi)
            - 0.5 * np.log(ld1_0_unc)
            - 0.5 * (ld1_0 - ld1)**2 / ld1_0_unc**2
            )

        logld2 = (
            - 0.5 * np.log(2.*np.pi)
            - 0.5 * np.log(ld2_0_unc)
            - 0.5 * (ld2_0 - ld2)**2 / ld2_0_unc**2
            )

        logldp = logld1 + logld2
    else:
        logldp = 0.0

    logecc = - np.sum(np.log(ecc))

    logLtot = loglc + logrv + logrho + logldp + logecc

    return logLtot
示例#9
0
    model_lcrv = calc_model_phase(fitsol_model_calc,
        nplanets,fixed_sol_model_calc,
        time_model_calc,itime_model_calc,ntt,tobs,omc,datatype_model_calc)

    model_lc = model_lcrv[datatype_model_calc == 0] - 1.
    model_rv = model_lcrv[datatype_model_calc == 1]


    ecc[ecc == 0.0] = 1.E-10

    npt_lc = len(err_jit)
    npt_rv = len(rverr_jit)

    #do the GP stuff
    resid = flux - model_lc
    kernel = ((GP1**2 * RBFKernel(GP2)) + (GP3**2 * RBFKernel(GP4)))
    gp = george.GaussianProcess(kernel)
    lnlike = 0.

    for i in np.arange(len(time) // 1000):
        section = np.arange(i*1000,i*1000 + 1000)
        gp.compute(time[section], err_jit[section])
        lnlike += gp.lnlikelihood(resid[section])

#    loglc = (
#        - (npt_lc/2.)*np.log(2.*np.pi)
#        - 0.5 * np.sum(np.log(err_jit2))
#        - 0.5 * np.sum((res)**2 / err_jit2)
#        )
    loglc = lnlike