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 = 0.0 #!!!!!!!!!!!!!!!!!!!!!!!!!! GP2 = 0.0 #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
def logchi2_rv_phaseGP2(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, use_hodlr=False): """ 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 # time to anti-log things expGP1 = fitsol[5] expGP2 = fitsol[6] GP1 = np.exp(fitsol[5]) GP2 = np.exp(fitsol[6]) rvamp = np.exp(fitsol[np.arange(nplanets) * 7 + 13]) occ = np.exp(fitsol[np.arange(nplanets) * 7 + 14]) ell = np.exp(fitsol[np.arange(nplanets) * 7 + 15]) alb = np.exp(fitsol[np.arange(nplanets) * 7 + 16]) jitter_lc = np.exp(fitsol[-2]) jitter_rv = np.exp(fitsol[-1]) if GP1 < 0.0 or GP1 > 10.0: # print('should never execute, GP1<0.0') return minf if GP2 < 0.0 or GP2 > 10.0: # print('should never execute, GP2<0.0') return minf if expGP1 < -11. or expGP1 > -6.: # print('expGP1 == {}'.format(expGP1)) return minf if expGP2 < -8. or expGP2 > -4.: # print('expGP2 == {}'.format(expGP2)) return minf #T0, period, b, rprs, ecosw, esinw rprs = fitsol[np.arange(nplanets) * 7 + 10] if np.any(rprs < 0.) or np.any(rprs > 0.5): return minf ecosw = fitsol[np.arange(nplanets) * 7 + 11] if np.any(ecosw < -1.0) or np.any(ecosw > 1.0): return minf esinw = fitsol[np.arange(nplanets) * 7 + 12] 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 + 8] ar = get_ar(rho, per) if np.any(ecc > (1. - (1. / ar))): return minf b = fitsol[np.arange(nplanets) * 7 + 9] if np.any(b < 0.) or np.any(b > 1.0 + rprs): return minf if onlytransits: T0 = fitsol[np.arange(nplanets) * 7 + 7] if np.any(T0 < T0 - tregion) or np.any(T0 > T0 + tregion): return minf if np.abs(jitter_rv > 500): return minf veloffset = fitsol[4] if np.abs(veloffset) > 200: return minf if np.abs(rvamp) > 1.E6 or rvamp < 0.0: # print('should rarely execute, rvamp == {}'.format(rvamp)) return minf if np.abs(occ) > 1.E6 or occ < 0.: # print('should rarely execute, occ == {}'.format(occ)) return minf if np.abs(ell) > 1.E6 or ell < 0.: # print('should rarely execute, ell == {}'.format(ell)) return minf if np.abs(alb) > 1.E6 or alb < 0.: # print('should rarely execute, alb == {}'.format(alb)) return minf if ecc > 0.6: return minf if jitter_lc < 0.0 or jitter_lc > 0.7: # print('should rarely execute, lcjutter == {}'.format(jitter_lc)) return minf err_jit = np.sqrt(err**2 + jitter_lc**2) err_jit2 = err**2 + jitter_lc**2 if jitter_rv < 0.0 or jitter_rv > 500.: # print('should never execute, rv jitter<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], fitsol[7:]] #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 * ExpSquaredKernel(GP2)) if use_hodlr: gp = george.GP(kernel, solver=george.HODLRSolver) else: gp = george.GP(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]) gp.compute(time, err_jit) lnlike += gp.lnlikelihood(resid) # 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
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
def logchi2_rv_phaseGP2(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 GP1 = fitsol[5] GP2 = fitsol[6] #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 + 10] if np.any(rprs < 0.) or np.any(rprs > 0.5): return minf ecosw = fitsol[np.arange(nplanets)*7 + 11] if np.any(ecosw < -1.0) or np.any(ecosw > 1.0): return minf esinw = fitsol[np.arange(nplanets)*7 + 12] 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 + 8] ar = get_ar(rho,per) if np.any(ecc > (1.-(1./ar))): return minf b = fitsol[np.arange(nplanets)*7 + 9] if np.any(b < 0.) or np.any(b > 1.0 + rprs): return minf if onlytransits: T0 = fitsol[np.arange(nplanets)*7 + 7] 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 > 5: return minf veloffset = fitsol[4] if np.abs(veloffset) > 100: return minf rvamp = fitsol[np.arange(nplanets)*7 + 13] occ = fitsol[np.arange(nplanets)*7 + 14] ell = fitsol[np.arange(nplanets)*7 + 15] alb = fitsol[np.arange(nplanets)*7 + 16] if np.abs(rvamp) > 500: return minf if np.abs(occ) > 300: return minf if np.abs(ell) > 500: return minf if np.abs(alb) > 500: return minf if ecc > 0.6: return minf # with log unc there are no negatives # if jitter_lc < 0.0: # return minf err_jit = np.sqrt(err**2 + np.exp(jitter_lc)**2) err_jit2 = err**2 + np.exp(jitter_lc)**2 # with log unc there are no negatives # if jitter_rv < 0.0: # return minf rverr_jit = np.sqrt(rverr**2 + np.exp(jitter_rv)**2) rverr_jit2 = rverr**2 + np.exp(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],fitsol[7:]] #cut out limb da
def logchi2_rv_hetero(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 fixed_sol should have dil,occ,ell,alb """ minf = -np.inf rho = fitsol[0] if rho < 1.E-8 or rho > 100.: 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 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 jitter_lc = fitsol[(nplanets-1)*7 + 12] if jitter_lc < 0.0: return minf err_jit = np.sqrt(err**2 + jitter_lc**2) err_jit2 = err**2 + jitter_lc**2 jitter_rv = fitsol[(nplanets-1)*7 + 13:] if np.any(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(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] ### old likelihood # if rho_prior: # rhoprior = (rho_0 - rho)**2 / rho_0_unc**2 # else: # rhoprior = 0.0 # if ldp_prior: # ldprior1 = (ld1_0 - ld1)*(ld1_0 - ld1) / ld1_0_unc**2 # ldprior2 = (ld2_0 - ld2)*(ld2_0 - ld2) / ld2_0_unc**2 # ldprior = ldprior1 + ldprior2 # else: # ldprior = 0.0 # chi2prior = -0.5*(rhoprior+ldprior) ecc[ecc == 0.0] = 1.E-10 #chi2ecc = np.log(ecc) # chi2lc = -0.5*np.sum(((model_lc - flux)* (model_lc - flux)) # / (err_jit*err_jit)) # chi2rv = -0.5*np.sum(((model_rv - rvval) * (model_rv - rvval)) # / (rverr_jit*rverr_jit)) # chi2const = -1.0*(np.sum(np.log(err_jit)) + np.sum(np.log(rverr_jit))) # chi2tot = chi2const + chi2lc + chi2rv + chi2prior # logp = chi2tot - np.sum(chi2ecc) ### ###new go at the log-likelihood ### # tpcon = 1. / (np.sqrt(2.*np.pi)) # chi2lc = np.sum( # -np.log(tpcon * (1./err_jit)) + # (model_lc - flux)**2 * (1./err_jit**2)) # chi2rv = np.sum( # -np.log(tpcon * (1./rverr_jit)) + # (model_rv - rvval)**2 * (1./rverr_jit**2)) # chi2ecc = np.sum(np.log(1./ecc)) # if rho_prior: # chi2rho = (-np.log(tpcon * (1./rho_0_unc)) + # (rho_0 - rho)**2 * (1./rho_0_unc)**2) # else: # chi2rho = 0.0 # if ldp_prior: # chi2ld1 = (-np.log(tpcon * (1./ld1_0_unc)) + # (ld1_0 - ld1)**2 * (1./ld1_0_unc)**2) # chi2ld2 = (-np.log(tpcon * (1./ld2_0_unc)) + # (ld2_0 - ld2)**2 * (1./ld2_0_unc)**2) # chi2ld = chi2ld1 + chi2ld2 # else: # chi2ld = 0.0 # chi2tot = -0.5*(chi2rv + chi2lc + chi2rho + chi2ld) + chi2ecc # return chi2tot npt_lc = len(err_jit) npt_rv = len(rverr_jit) loglc = ( - (npt_lc/2.)*np.log(2.*np.pi) - 0.5 * np.sum(np.log(err_jit2)) - 0.5 * np.sum((model_lc - flux)**2 / err_jit2) ) 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**2) - 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**2) - 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**2) - 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
def logchi2_rv_nontransitfudge(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): """ this is a dirty fudge to get the second planet not to transit 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 fixed_sol should have dil,occ,ell,alb """ minf = -np.inf rho = fitsol[0] if rho < 1.E-8 or rho > 100.: 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 rprs = fitsol[np.arange(nplanets)*7 + 8] b = fitsol[np.arange(nplanets)*7 + 7] ## fudgey part !! rprs[1] = 0.0 b[1] = 0.0 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 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 jitter_lc = fitsol[-2] if jitter_lc < 0.0: return minf err_jit = np.sqrt(err**2 + jitter_lc**2) err_jit2 = err**2 + jitter_lc**2 jitter_rv = fitsol[-1] 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(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) loglc = ( - (npt_lc/2.)*np.log(2.*np.pi) - 0.5 * np.sum(np.log(err_jit2)) - 0.5 * np.sum((model_lc - flux)**2 / err_jit2) ) 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