def create_testcase04(): bjd0 = bjd_obs - Tref y_pla = instrument['RV_offset1'] + \ kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) + \ kp.kepler_RV_T0P(bjd0, planet_c['f'], planet_c['P'], planet_c['K'], planet_c['e'], planet_c['o']) mod_pl = np.random.normal(y_pla, instrument['RV_precision']) #Tcent_b = kp.kepler_Tcent_T0P(planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref Tcent_b = np.random.normal( np.arange(0, 10) * planet_b['P'] + kp.kepler_Tcent_T0P( planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref, instrument['T0_precision']) Tcent_c = np.random.normal( np.arange(0, 10) * planet_c['P'] + kp.kepler_Tcent_T0P( planet_c['P'], planet_c['f'], planet_c['e'], planet_c['o']) + Tref, instrument['T0_precision']) fileout = open('TestCase04_RV.dat', 'w') for b, r in zip(bjd_obs, mod_pl): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format( b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close() fileout = open('TestCase04_Tcent_b.dat', 'w') for i_Tc, v_Tc in enumerate(Tcent_b): fileout.write('{0:d} {1:.4f} {2:.4f} {3:d}\n'.format( i_Tc, v_Tc, instrument['T0_precision'], 0)) fileout.close() fileout = open('TestCase04_Tcent_c.dat', 'w') for i_Tc, v_Tc in enumerate(Tcent_c): fileout.write('{0:d} {1:.4f} {2:.4f} {3:d}\n'.format( i_Tc, v_Tc, instrument['T0_precision'], 0)) fileout.close()
def create_testcase08(): bjd0 = bjd_obs - Tref y_pla = kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) \ + instrument['RV_offset1'] \ + polynomial_trend['c1']*bjd0 + polynomial_trend['c2']*bjd0*bjd0 mod_pl = np.random.normal(y_pla, instrument['RV_precision']) Tcent_b = np.random.normal( np.arange(0, 5)*planet_b['P'] + kp.kepler_Tcent_T0P(planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref, instrument['T0_precision']) fileout = open('TestCase08_RV.dat', 'w') for b, r in zip(bjd_obs, mod_pl): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format(b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close() fileout = open('TestCase08_Tcent_b.dat', 'w') for i_Tc, v_Tc in enumerate(Tcent_b): fileout.write('{0:d} {1:.4f} {2:.4f} {3:d}\n'.format(i_Tc, v_Tc, instrument['T0_precision'], 0)) fileout.close()
def create_testcase03(): bjd0 = bjd_obs - Tref y_pla = instrument['RV_offset1'] + \ kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) + \ kp.kepler_RV_T0P(bjd0, planet_c['f'], planet_c['P'], planet_c['K'], planet_c['e'], planet_c['o']) mod_pl = np.random.normal(y_pla, instrument['RV_precision']) #Tcent_b = kp.kepler_phase2Tc_Tref(planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref Tcent_b = np.random.normal( np.arange(0, 5) * planet_b['P'] + kp.kepler_phase2Tc_Tref( planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref, instrument['T0_precision']) fileout = open('TestCase03_RV.dat', 'w') for b, r in zip(bjd_obs, mod_pl): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format( b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close() #fileout = open('TestCase01_Tcent_b.dat', 'w') #for ii in xrange(0, np.size(Transit_Time)): # fileout.write('{0:d} {1:f} {2:f} {3:d} \n'.format(ii, Tcent_b, 0.01, 0)) #fileout.close() fileout = open('TestCase03_Tcent_b.dat', 'w') for i_Tc, v_Tc in enumerate(Tcent_b): fileout.write('{0:d} {1:.4f} {2:.4f} {3:d}\n'.format( i_Tc, v_Tc, instrument['T0_precision'], 0)) fileout.close()
def create_testcase01(): bjd0 = bjd_obs - Tref y_pla = kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) + instrument['RV_offset1'] mod_pl = np.random.normal(y_pla, instrument['RV_precision']) fileout = open('TestCase01_RV.dat', 'w') for b, r in zip(bjd_obs, mod_pl): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format( b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close()
def create_test2(): x = np.arange(6000, 6100, 1, dtype=np.double) x = np.random.normal(x, 0.4) Tref = np.mean(x, dtype=np.double) x0 = x - Tref print Tref P = 23.4237346 K = 43.47672 phase = 0.34658203 e = 0.13 omega = 0.673434 offset = 45605 y_pla = kp.kepler_RV_T0P(x0, phase, P, K, e, omega) + offset mod_pl = np.random.normal(y_pla, 2) trip = np.arange(10, 3, -1) Transit_Time = kp.kepler_Tcent_T0P(P, phase, e, omega) + Tref - trip * P Transit_Time = kp.kepler_Tcent_T0P(P, phase, e, omega) + Tref print 'Transit Time:', Transit_Time print 'transit Time - Tref', Transit_Time - Tref plt.scatter(x, mod_pl) plt.axvline(Transit_Time) plt.show() fileout = open('test2_RV.dat', 'w') for ii in xrange(0, np.size(x)): fileout.write('{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \n'.format( x[ii], mod_pl[ii], 2., 0, 0, -1)) fileout.close() fileout = open('test2_Tcent_0.dat', 'w') for ii in xrange(0, np.size(Transit_Time)): fileout.write('{0:14f} {1:14f} \n'.format(Transit_Time, 0.01)) fileout.close()
def create_test1(): x = np.arange(6000, 6500, 1, dtype=np.double) Tref = np.mean(x, dtype=np.double) x0 = x - Tref P = 23.4237346 K = 43.47672 phase = 0.34658203 e = 0.13 omega = 0.673434 offset = 45605 y_pla = kp.kepler_RV_T0P(x0, phase, P, K, e, omega) + offset mod_pl = np.random.normal(y_pla, 2) n_periods = 2 n_pha = 4 # Period1 Prot = 9.234 pha = np.zeros([n_periods, n_pha], dtype=np.double) pha[0, :] = [0.452, 0.894, 0.622, 0.344] pha[1, :] = [0.236, 0.522, 0.974, 0.334] off = np.zeros(n_periods, dtype=np.double) off[:] = 0.56424 amp = np.zeros([n_periods, n_pha], dtype=np.double) amp[0, :] = [35.0, 24.0, 17.0, 7.0] amp[1, :] = [30.0, 19.0, 12.0, 8.0] p_mask = np.zeros([n_periods, np.size(x)], dtype=np.bool) p_mask[0, :] = (x > 5000) & (x < 6250) p_mask[1, :] = (x > 6250) & (x < 7000) har = np.arange(1, np.size(amp, axis=1) + 1, 1., dtype=np.double) mod_rv = np.zeros(np.size(x), dtype=np.double) mod_ph1 = np.zeros(np.size(x), dtype=np.double) mod_ind = np.zeros([n_periods, np.size(x)], dtype=np.double) xph = (x0 / Prot) % 1 for ii in xrange(0, n_periods): for jj in xrange(0, n_pha): mod_ind[ii, :] = p_mask[ii, :] * amp[ii, jj] * np.sin( (har[jj] * xph + pha[ii, jj] + off[ii]) * 2. * np.pi) mod_rv += mod_ind[ii, :] # plt.plot(x[p_mask[ii,:]],mod_ind[ii,p_mask[ii,:]]) amp = np.zeros([n_periods, n_pha], dtype=np.double) amp[0, :] = [0.0350, 0.0240, 0.0170, 0.0070] amp[1, :] = [0.0300, 0.0190, 0.0120, 0.0080] for ii in xrange(0, n_periods): for jj in xrange(0, n_pha): mod_ind[ii, :] = p_mask[ii, :] * amp[ii, jj] * np.sin( (har[jj] * xph + pha[ii, jj]) * 2. * np.pi) mod_ph1 += mod_ind[ii, :] # plt.plot(x[p_mask[ii,:]],mod_ind[ii,p_mask[ii,:]]) mod_ph = np.random.normal(mod_ph1, 0.002) fileout = open('example/test1_RV.dat', 'w') for ii in xrange(0, np.size(x)): fileout.write('{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \n'.format( x[ii], mod_rv[ii] + mod_pl[ii], 1., 0, 0, -1)) fileout.close() fileout = open('test1/test1_PH.dat', 'w') for ii in xrange(0, np.size(x)): fileout.write('{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \n'.format( x[ii], mod_ph[ii], 0.002, 0, 0, -1)) fileout.close()
planet['f'] = plsq[0][0] if planet['f'] < 0.00: planet['f'] += 2 * np.pi planet['mA'] = planet['f'] - planet['o'] #for planet_name, planet in planets.items(): for planet_name in config_in['plot_planets']: planet = planets[planet_name] print() print(' *** Planet ', planet_name, ' *** ') single_orbit_bjd = np.arange(-0.5, 1.5, 0.001, dtype=np.double) single_orbit_RV = kp.kepler_RV_T0P(single_orbit_bjd, planet['f'], 1.00000, 1.0000, planet['e'], planet['o']) single_orbit_1period_bjd = np.arange(0.0, 1.0, 0.001, dtype=np.double) single_orbit_1period_RV = kp.kepler_RV_T0P(single_orbit_1period_bjd, planet['f'], 1.00000, 1.0000, planet['e'], planet['o']) #upper_quad = [single_orbit_bjd[np.where(single_orbit_RV > 1.0-planet['quadrature_window'])[0][0]], # single_orbit_bjd[np.where(single_orbit_RV > 1.0-planet['quadrature_window'])[0][-1]]] phase_upper_quadrature = single_orbit_1period_bjd[np.argmax(single_orbit_1period_RV)] upper_quad = [ single_orbit_bjd[np.where(single_orbit_bjd > phase_upper_quadrature-planet['quadrature_window'])[0][0]], single_orbit_bjd[np.where(single_orbit_bjd < phase_upper_quadrature+planet['quadrature_window'])[0][-1]]] print('first upper quadrature since reference time --> ', upper_quad) #lower_quad = [single_orbit_bjd[np.where(single_orbit_RV < planet['quadrature_window']-1.0)[0][0]],
y_kep = np.zeros([np.size(x_kep), 2]) x_pha = np.arange(-1.00,2.00,0.005,dtype=np.double) y_pha = np.zeros([np.size(x_pha), 2]) y_flg = np.ones(random_n, dtype=bool) y_kep_tmp = np.zeros(np.size(x_kep)) y_pha_tmp = np.zeros(np.size(x_pha)) if pams_limits[3,0] < 0.02: pams_limits[3,0]=0.00 for ii in xrange(0,4): y_flg = y_flg & (sample_plan[ii_kep, ii]>=pams_limits[ii,0]) & ( sample_plan[ii_kep, ii]<=pams_limits[ii,1]) y_kep[:,0] = kp.kepler_RV_T0P(x_kep - Tref, orbit_pam[pp,2], orbit_pam[pp,0], orbit_pam[pp,1], orbit_pam[pp,3], orbit_pam[pp,4]) y_kep[:,1] = y_kep[:,0] # value initialization y_pha[:,0] = kp.kepler_RV_T0P(x_pha*orbit_pam[pp,0], orbit_pam[pp,2], orbit_pam[pp,0], orbit_pam[pp,1], orbit_pam[pp,3], orbit_pam[pp,4]) y_pha[:,1] = y_pha[:,0] fig1 =plt.plot(x_kep,y_kep[:,0],c='g') fig2 =plt.plot(x_pha,y_pha[:,0],c='g') print 'Accepted randomizations: ', np.sum(y_flg) for ii in xrange(0, random_n): ir = ii_kep[ii] if (y_flg[ii]): y_kep_tmp = kp.kepler_RV_T0P(x_kep - Tref, sample_plan[ir, 2], sample_plan[ir, 0], sample_plan[ir, 1], sample_plan[ir, 3], sample_plan[ir, 4]) y_pha_tmp = kp.kepler_RV_T0P(x_pha*sample_plan[ir, 0], sample_plan[ir, 2], sample_plan[ir, 0], sample_plan[ir, 1], sample_plan[ir, 3], sample_plan[ir, 4])
import kepler_exo as kp import numpy as np import matplotlib.pyplot as plt xx = np.arange(0, 1.000, 0.001) single_orbit_RV = kp.kepler_RV_T0P(xx, np.pi / 2, 1.00000, 1.0000, 0.00, np.pi / 2) plt.plot(xx, single_orbit_RV) plt.show()
def create_testcase07(): import george bjd0 = bjd_obs - Tref err = bjd0 * 0 + instrument['RV_precision'] gp_pams = np.zeros(4) gp_pams[0] = np.log(activity['Hamp_RV1']) * 2 gp_pams[1] = np.log(activity['Pdec'])*2 gp_pams[2] = 1. / (2*activity['Oamp'] ** 2) gp_pams[3] = np.log(activity['Prot']) kernel = np.exp(gp_pams[0]) * \ george.kernels.ExpSquaredKernel(metric=np.exp(gp_pams[1])) * \ george.kernels.ExpSine2Kernel(gamma=gp_pams[1], log_period=gp_pams[2]) gp = george.GP(kernel) gp.compute(bjd0, err) prediction1 = gp.sample(bjd0) gp_pams[0] = np.log(activity['Hamp_RV2']) * 2 kernel = np.exp(gp_pams[0]) * \ george.kernels.ExpSquaredKernel(metric=np.exp(gp_pams[1])) * \ george.kernels.ExpSine2Kernel(gamma=gp_pams[1], log_period=gp_pams[2]) gp = george.GP(kernel) gp.compute(bjd0, err) prediction2 = gp.sample(bjd0) y_pla = kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) mod_pl1 = np.random.normal(y_pla + prediction1 + instrument['RV_offset1'], instrument['RV_precision']) mod_pl2 = np.random.normal(y_pla + prediction2 + instrument['RV_offset2'], instrument['RV_precision']) Tcent_b = np.random.normal( np.arange(0,1)*planet_b['P'] + kp.kepler_Tcent_T0P(planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref, instrument['T0_precision']) fileout = open('TestCase07_RV_dataset1.dat', 'w') for b, r in zip(bjd_obs, mod_pl1): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format(b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close() fileout = open('TestCase07_RV_dataset2.dat', 'w') for b, r in zip(bjd_obs, mod_pl2): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format(b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close() fileout = open('TestCase07_Tcent_b.dat', 'w') for i_Tc, v_Tc in enumerate(Tcent_b): fileout.write('{0:d} {1:.4f} {2:.4f} {3:d}\n'.format(i_Tc, v_Tc, instrument['T0_precision'], 0)) fileout.close()
def create_testcase06(): import george bjd0 = photometry['phot_bjd'] - Tref err = bjd0 * 0 + photometry['phot_precision'] """ Conversion of the physical parameter to the internally defined parameter to be passed to george """ gp_pams = np.zeros(4) gp_pams[0] = np.log(activity['Hamp_PH']) * 2 gp_pams[1] = np.log(activity['Pdec']) * 2 gp_pams[2] = 1. / (2 * activity['Oamp'] ** 2) gp_pams[3] = np.log(activity['Prot']) kernel = np.exp(gp_pams[0]) * \ george.kernels.ExpSquaredKernel(metric=np.exp(gp_pams[1])) * \ george.kernels.ExpSine2Kernel(gamma=gp_pams[1], log_period=gp_pams[2]) gp = george.GP(kernel) gp.compute(bjd0, err) prediction = gp.sample(bjd0) obs_photometry = np.random.normal(prediction, instrument['RV_precision']) fileout = open('TestCase06_photometry.dat', 'w') for b, p in zip(photometry['phot_bjd'], obs_photometry): fileout.write('{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \n'.format( b, p, photometry['phot_precision'], 0, 0, -1)) fileout.close() bjd0 = bjd_obs - Tref err = bjd0 * 0 + instrument['RV_precision'] gp_pams[0] = np.log(activity['Hamp_RV1']) * 2 kernel = np.exp(gp_pams[0]) * \ george.kernels.ExpSquaredKernel(metric=np.exp(gp_pams[1])) * \ george.kernels.ExpSine2Kernel(gamma=gp_pams[1], log_period=gp_pams[2]) gp = george.GP(kernel) gp.compute(bjd0, err) prediction = gp.sample(bjd0) y_pla = kp.kepler_RV_T0P(bjd0, planet_b['f'], planet_b['P'], planet_b['K'], planet_b['e'], planet_b['o']) + instrument['RV_offset1'] mod_pl = np.random.normal(y_pla + prediction, instrument['RV_precision']) Tcent_b = np.random.normal( np.arange(0,1)*planet_b['P'] + kp.kepler_Tcent_T0P(planet_b['P'], planet_b['f'], planet_b['e'], planet_b['o']) + Tref, instrument['T0_precision']) fileout = open('TestCase06_RV.dat', 'w') for b, r in zip(bjd_obs, mod_pl): fileout.write('{0:f} {1:.2f} {2:.2f} {3:d} {4:d} {5:d}\n'.format(b, r, instrument['RV_precision'], 0, 0, -1)) fileout.close()
def lnlike(theta): ## derived_orb = np.empty(0, dtype=np.double) derived_orb = [] ip = 0 if flag_rv: rv_model = np.zeros(rv_n, dtype=np.double) rv_j_add = np.zeros(rv_n, dtype=np.double) ## Going trough the orbital parameters of each individual planet ## to compute the non-interacting Keplerian RV for pp in xrange(0, n_planets): e = np.asarray(0., dtype=np.double) omega = np.asarray(0., dtype=np.double) ## P and K are converted from their logarithmic value P = 10.0 ** (theta[ip + 0]) k = 10.0 ** (theta[ip + 1]) ## Their values are stored in output to have the chain and correlation plot ## in a readable form derived_orb.append(P) derived_orb.append(k) if (n_orbpams[pp] == 5): ## for non-null eccentricity, sqrt(e)*sin(omega) and sqrt(e)*cos(omega) ## are converted to e and omega, and their value are given in output ## for readable display of chains and triangle diagram # theta[ip + 3] = sqrt(e)*sin(omega) # theta[ip + 4] = sqrt(e)*cos(omega) e = theta[ip + 3] ** 2 + theta[ip + 4] ** 2 omega = np.arctan2(theta[ip + 3], theta[ip + 4]) derived_orb.append(e) derived_orb.append(omega) rv_model += kp.kepler_RV_T0P(rv_x0, theta[ip + 2], P, k, e, omega) ip += n_orbpams[pp] # for ii in xrange(0, n_trends): # rv_model += rv_x0 ** ii * theta[ip + ii] # ip += n_trends for ii in xrange(0, n_rvj): rv_j_add += theta[ip + ii] * rvj_mask[:, ii] ip += n_rvj for ii in xrange(0, n_rvo): rv_model += theta[ip + ii] * rvo_mask[:, ii] ip += n_rvo for ii in xrange(0, n_rvl): rv_model += theta[ip + ii] * rv_x0 * rvl_mask[:, ii] ip += n_rvl if flag_p1: p1_model = np.zeros(p1_n, dtype=np.double) p1_j_add = np.zeros(p1_n, dtype=np.double) for ii in xrange(0, n_p1j): p1_j_add += theta[ip + ii] * p1j_mask[:, ii] ip += n_p1j for ii in xrange(0, n_p1o): p1_model += theta[ip + ii] * p1o_mask[:, ii] ip += n_p1o for ii in xrange(0, n_p1l): p1_model += theta[ip + ii] * p1_x0 * p1l_mask[:, ii] ip += n_p1l if flag_p2: p2_model = np.zeros(p2_n, dtype=np.double) p2_j_add = np.zeros(p2_n, dtype=np.double) for ii in xrange(0, n_p2j): p2_j_add += theta[ip + ii] * p2j_mask[:, ii] ip += n_p2j for ii in xrange(0, n_p2o): p2_model += theta[ip + ii] * p2o_mask[:, ii] ip += n_p2o for ii in xrange(0, n_p2l): p2_model += theta[ip + ii] * p2_x0 * p2l_mask[:, ii] ip += n_p2l if flag_fw: fw_model = np.zeros(fw_n, dtype=np.double) fw_j_add = np.zeros(fw_n, dtype=np.double) for ii in xrange(0, n_fwj): fw_j_add += theta[ip + ii] * fwj_mask[:, ii] ip += n_fwj for ii in xrange(0, n_fwo): fw_model += theta[ip + ii] * fwo_mask[:, ii] ip += n_fwo for ii in xrange(0, n_fwl): fw_model += theta[ip + ii] * fw_x0 * fwl_mask[:, ii] ip += n_fwl if flag_bs: bs_model = np.zeros(bs_n, dtype=np.double) bs_j_add = np.zeros(bs_n, dtype=np.double) for ii in xrange(0, n_bsj): bs_j_add += theta[ip + ii] * bsj_mask[:, ii] ip += n_bsj for ii in xrange(0, n_bso): bs_model += theta[ip + ii] * bso_mask[:, ii] ip += n_bso for ii in xrange(0, n_bsl): bs_model += theta[ip + ii] * bs_x0 * bsl_mask[:, ii] ip += n_bsl ## kind_sin option 1 (SPLINE fit) has been removed from this code if kind_sin > 1: Prot_run = theta[ip] ip += 1 ph_off = np.zeros(n_pof+1, dtype=np.double) if (phase_coherence): ph_off[0] = theta[ip + n_pof] ph_off[1:n_pof+1] = theta[ip:ip + n_pof] if ((not phase_synchro) and (not phase_coherence)): ph_off[1:n_pof+1] = theta[ip:ip + n_pof] ip += n_pof for nk in xrange(0, n_periods): ph_sin = np.zeros(n_pha, dtype=np.double) if (phase_synchro): ph_sin[:] = theta[ip] if ((not phase_synchro) and (not phase_coherence)): ph_sin[:] = theta[ip:ip + n_pha] ip += n_pha ip_pof = 0 if rvp_flag[nk]: rv_xph = (rv_x0 / Prot_run) % 1 for jj in xrange(0, n_rva): for ii in xrange(0, n_amp[jj]): rv_model += rvp_mask[:,nk] * rva_mask[:, jj] * theta[ip + ii] * np.sin( ((ii + 1.) * rv_xph + ph_sin[ii] + ph_off[ip_pof])* 2. * np.pi) ip += n_amp[jj] ip_pof += 1 if p1p_flag[nk]: p1_xph = (p1_x0 / Prot_run) % 1 for ii in range(0,n_pho): p1_model += p1p_mask[:,nk] * theta[ip + ii] * np.sin( ((ii + 1.) * p1_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_pho ip_pof += 1 if p2p_flag[nk]: p2_xph = (p2_x0 / Prot_run) % 1 tp_pof = ip_pof - 1 for ii in range(0, n_pho): p2_model += p2p_mask[:, nk] * theta[ip + ii] * np.sin( ((ii + 1.) * p2_xph + ph_sin[ii] + ph_off[tp_pof]) * 2. * np.pi) ip += n_pho ## ip_pof += 1 if fwp_flag[nk]: fw_xph = (fw_x0 / Prot_run) % 1 for jj in xrange(0, n_fwa): for ii in range(0, n_amp): ## fw_model += fwp_mask[:, nk] * ( fw_model += fwp_mask[:, nk] * fwa_mask[:, jj] * theta[ip + ii] * np.sin( ((ii + 1.) * fw_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_amp ip_pof += 1 if bsp_flag[nk]: bs_xph = (bs_x0 / Prot_run) % 1 for jj in xrange(0, n_bsa): for ii in range(0, n_amp[jj]): ## bs_model += bsp_mask[:, nk] * ( bs_model += bsp_mask[:, nk] * bsa_mask[:, jj] * theta[ip + ii] * np.sin( ((ii + 1.) * bs_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_amp[jj] ip_pof += 1 chi2_OUT = 0. if flag_rv: rve_env = 1.0 / (rv_e ** 2.0 + rv_j_add ** 2.0) chi2_OUT += np.sum((rv_y - rv_model) ** 2 * rve_env - np.log(rve_env)) if flag_p1: p1e_env = 1.0 / (p1_e ** 2.0 + p1_j_add ** 2) chi2_OUT += np.sum((p1_y - p1_model) ** 2 * p1e_env - np.log(p1e_env)) if flag_p2: p2e_env = 1.0 / (p2_e ** 2.0 + p2_j_add ** 2) chi2_OUT += np.sum((p2_y - p2_model) ** 2 * p2e_env - np.log(p2e_env)) if flag_fw: fwe_env = 1.0 / (fw_e ** 2.0 + fw_j_add ** 2) chi2_OUT += np.sum((fw_y - fw_model) ** 2 * fwe_env - np.log(fwe_env)) if flag_bs: bse_env = 1.0 / (bs_e ** 2.0 + bs_j_add ** 2) chi2_OUT += np.sum((bs_y - bs_model) ** 2 * bse_env - np.log(bse_env)) ## print ii_tot, chi2_bin, chi2_bin/ii_tot, theta[ip] return -0.5 * (chi2_OUT), derived_orb
x_pha = np.arange(-1.00, 2.00, 0.005, dtype=np.double) y_pha = np.zeros([np.size(x_pha), 2]) y_flg = np.ones(random_n, dtype=bool) y_kep_tmp = np.zeros(np.size(x_kep)) y_pha_tmp = np.zeros(np.size(x_pha)) if pams_limits[3, 0] < 0.02: pams_limits[3, 0] = 0.00 for ii in xrange(0, 4): y_flg = y_flg & (sample_plan[ii_kep, ii] >= pams_limits[ii, 0]) & ( sample_plan[ii_kep, ii] <= pams_limits[ii, 1]) y_kep[:, 0] = kp.kepler_RV_T0P(x_kep - Tref, orbit_pam[pp, 2], orbit_pam[pp, 0], orbit_pam[pp, 1], orbit_pam[pp, 3], orbit_pam[pp, 4]) y_kep[:, 1] = y_kep[:, 0] # value initialization y_pha[:, 0] = kp.kepler_RV_T0P(x_pha * orbit_pam[pp, 0], orbit_pam[pp, 2], orbit_pam[pp, 0], orbit_pam[pp, 1], orbit_pam[pp, 3], orbit_pam[pp, 4]) y_pha[:, 1] = y_pha[:, 0] fig1 = plt.plot(x_kep, y_kep[:, 0], c='g') fig2 = plt.plot(x_pha, y_pha[:, 0], c='g') print 'Accepted randomizations: ', np.sum(y_flg) for ii in xrange(0, random_n): ir = ii_kep[ii] if (y_flg[ii]):
def lnlike(theta): ## derived_orb = np.empty(0, dtype=np.double) derived_orb = [] ip = 0 if flag_rv: rv_model = np.zeros(rv_n, dtype=np.double) rv_j_add = np.zeros(rv_n, dtype=np.double) ## Going trough the orbital parameters of each individual planet ## to compute the non-interacting Keplerian RV for pp in xrange(0, n_planets): e = np.asarray(0., dtype=np.double) omega = np.asarray(0., dtype=np.double) ## P and K are converted from their logarithmic value P = 10.0**(theta[ip + 0]) k = 10.0**(theta[ip + 1]) ## Their values are stored in output to have the chain and correlation plot ## in a readable form derived_orb.append(P) derived_orb.append(k) if (n_orbpams[pp] == 5): ## for non-null eccentricity, sqrt(e)*sin(omega) and sqrt(e)*cos(omega) ## are converted to e and omega, and their value are given in output ## for readable display of chains and triangle diagram # theta[ip + 3] = sqrt(e)*sin(omega) # theta[ip + 4] = sqrt(e)*cos(omega) e = theta[ip + 3]**2 + theta[ip + 4]**2 omega = np.arctan2(theta[ip + 3], theta[ip + 4]) derived_orb.append(e) derived_orb.append(omega) rv_model += kp.kepler_RV_T0P(rv_x0, theta[ip + 2], P, k, e, omega) ip += n_orbpams[pp] # for ii in xrange(0, n_trends): # rv_model += rv_x0 ** ii * theta[ip + ii] # ip += n_trends for ii in xrange(0, n_rvj): rv_j_add += theta[ip + ii] * rvj_mask[:, ii] ip += n_rvj for ii in xrange(0, n_rvo): rv_model += theta[ip + ii] * rvo_mask[:, ii] ip += n_rvo for ii in xrange(0, n_rvl): rv_model += theta[ip + ii] * rv_x0 * rvl_mask[:, ii] ip += n_rvl if flag_p1: p1_model = np.zeros(p1_n, dtype=np.double) p1_j_add = np.zeros(p1_n, dtype=np.double) for ii in xrange(0, n_p1j): p1_j_add += theta[ip + ii] * p1j_mask[:, ii] ip += n_p1j for ii in xrange(0, n_p1o): p1_model += theta[ip + ii] * p1o_mask[:, ii] ip += n_p1o for ii in xrange(0, n_p1l): p1_model += theta[ip + ii] * p1_x0 * p1l_mask[:, ii] ip += n_p1l if flag_p2: p2_model = np.zeros(p2_n, dtype=np.double) p2_j_add = np.zeros(p2_n, dtype=np.double) for ii in xrange(0, n_p2j): p2_j_add += theta[ip + ii] * p2j_mask[:, ii] ip += n_p2j for ii in xrange(0, n_p2o): p2_model += theta[ip + ii] * p2o_mask[:, ii] ip += n_p2o for ii in xrange(0, n_p2l): p2_model += theta[ip + ii] * p2_x0 * p2l_mask[:, ii] ip += n_p2l if flag_fw: fw_model = np.zeros(fw_n, dtype=np.double) fw_j_add = np.zeros(fw_n, dtype=np.double) for ii in xrange(0, n_fwj): fw_j_add += theta[ip + ii] * fwj_mask[:, ii] ip += n_fwj for ii in xrange(0, n_fwo): fw_model += theta[ip + ii] * fwo_mask[:, ii] ip += n_fwo for ii in xrange(0, n_fwl): fw_model += theta[ip + ii] * fw_x0 * fwl_mask[:, ii] ip += n_fwl if flag_bs: bs_model = np.zeros(bs_n, dtype=np.double) bs_j_add = np.zeros(bs_n, dtype=np.double) for ii in xrange(0, n_bsj): bs_j_add += theta[ip + ii] * bsj_mask[:, ii] ip += n_bsj for ii in xrange(0, n_bso): bs_model += theta[ip + ii] * bso_mask[:, ii] ip += n_bso for ii in xrange(0, n_bsl): bs_model += theta[ip + ii] * bs_x0 * bsl_mask[:, ii] ip += n_bsl ## kind_sin option 1 (SPLINE fit) has been removed from this code if kind_sin > 1: Prot_run = theta[ip] ip += 1 ph_off = np.zeros(n_pof + 1, dtype=np.double) if (phase_coherence): ph_off[0] = theta[ip + n_pof] ph_off[1:n_pof + 1] = theta[ip:ip + n_pof] if ((not phase_synchro) and (not phase_coherence)): ph_off[1:n_pof + 1] = theta[ip:ip + n_pof] ip += n_pof for nk in xrange(0, n_periods): ph_sin = np.zeros(n_pha, dtype=np.double) if (phase_synchro): ph_sin[:] = theta[ip] if ((not phase_synchro) and (not phase_coherence)): ph_sin[:] = theta[ip:ip + n_pha] ip += n_pha ip_pof = 0 if rvp_flag[nk]: rv_xph = (rv_x0 / Prot_run) % 1 for jj in xrange(0, n_rva): for ii in xrange(0, n_amp[jj]): rv_model += rvp_mask[:, nk] * rva_mask[:, jj] * theta[ ip + ii] * np.sin( ((ii + 1.) * rv_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_amp[jj] ip_pof += 1 if p1p_flag[nk]: p1_xph = (p1_x0 / Prot_run) % 1 for ii in range(0, n_pho): p1_model += p1p_mask[:, nk] * theta[ip + ii] * np.sin( ((ii + 1.) * p1_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_pho ip_pof += 1 if p2p_flag[nk]: p2_xph = (p2_x0 / Prot_run) % 1 tp_pof = ip_pof - 1 for ii in range(0, n_pho): p2_model += p2p_mask[:, nk] * theta[ip + ii] * np.sin( ((ii + 1.) * p2_xph + ph_sin[ii] + ph_off[tp_pof]) * 2. * np.pi) ip += n_pho ## ip_pof += 1 if fwp_flag[nk]: fw_xph = (fw_x0 / Prot_run) % 1 for jj in xrange(0, n_fwa): for ii in range(0, n_amp): ## fw_model += fwp_mask[:, nk] * ( fw_model += fwp_mask[:, nk] * fwa_mask[:, jj] * theta[ ip + ii] * np.sin( ((ii + 1.) * fw_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_amp ip_pof += 1 if bsp_flag[nk]: bs_xph = (bs_x0 / Prot_run) % 1 for jj in xrange(0, n_bsa): for ii in range(0, n_amp[jj]): ## bs_model += bsp_mask[:, nk] * ( bs_model += bsp_mask[:, nk] * bsa_mask[:, jj] * theta[ ip + ii] * np.sin( ((ii + 1.) * bs_xph + ph_sin[ii] + ph_off[ip_pof]) * 2. * np.pi) ip += n_amp[jj] ip_pof += 1 chi2_OUT = 0. if flag_rv: rve_env = 1.0 / (rv_e**2.0 + rv_j_add**2.0) chi2_OUT += np.sum((rv_y - rv_model)**2 * rve_env - np.log(rve_env)) if flag_p1: p1e_env = 1.0 / (p1_e**2.0 + p1_j_add**2) chi2_OUT += np.sum((p1_y - p1_model)**2 * p1e_env - np.log(p1e_env)) if flag_p2: p2e_env = 1.0 / (p2_e**2.0 + p2_j_add**2) chi2_OUT += np.sum((p2_y - p2_model)**2 * p2e_env - np.log(p2e_env)) if flag_fw: fwe_env = 1.0 / (fw_e**2.0 + fw_j_add**2) chi2_OUT += np.sum((fw_y - fw_model)**2 * fwe_env - np.log(fwe_env)) if flag_bs: bse_env = 1.0 / (bs_e**2.0 + bs_j_add**2) chi2_OUT += np.sum((bs_y - bs_model)**2 * bse_env - np.log(bse_env)) ## print ii_tot, chi2_bin, chi2_bin/ii_tot, theta[ip] return -0.5 * (chi2_OUT), derived_orb