def fitt_bootstrap(time, flux, ferr, resid, fitp, fits): T0, period, impact = fitp['pnum0']['T0'], fitp['pnum0']['period'], fitp[ 'pnum0']['impact'] rprs, ecosw, esinw = fitp['pnum0']['rprs'], fitp['pnum0']['ecosw'], fitp[ 'pnum0']['esinw'] zpt, rho, ld1, ld2 = fits['zpt'], fits['rho'], fits['ld1'], fits['ld2'] fitT = FitTransit() fitT.add_guess_star(rho=rho, zpt=zpt, ld1=ld1, ld2=ld2) fitT.add_guess_planet(period=period, impact=impact, T0=T0, rprs=rprs, ecosw=ecosw, esinw=esinw) flux_resid = flux + choice(resid, size=len(flux)) fitT.add_data(time=time, flux=flux_resid, ferr=ferr) vary_star = ['rho', 'zpt', 'ld1', 'ld2'] # free stellar parameters vary_planet = ([ 'period', # free planetary parameters 'T0', 'impact', 'rprs', 'ecosw', 'esinw' ]) fitT.free_parameters(vary_star, vary_planet) fitT.do_fit() # run the fitting return fitT.fitresult
def build_ktransit_model(ticid, lc, rprs=0.02, vary_transit=True): from ktransit import FitTransit fitT = FitTransit() model = BoxLeastSquares(lc.time, lc.flux) results = model.autopower(0.16, minimum_period=2., maximum_period=21.) period = results.period[np.argmax(results.power)] t0 = results.transit_time[np.argmax(results.power)] if rprs is None: depth = results.depth[np.argmax(results.power)] rprs = depth ** 2 fitT.add_guess_star(rho=0.022, zpt=0, ld1=0.6505,ld2=0.1041) #come up with better way to estimate this using AS fitT.add_guess_planet(T0=t0, period=period, impact=0.5, rprs=rprs) ferr = np.ones_like(lc.time) * 0.00001 fitT.add_data(time=lc.time,flux=lc.flux,ferr=ferr)#*1e-3) vary_star = ['zpt'] # free stellar parameters if vary_transit: vary_planet = (['period', 'impact', # free planetary parameters 'T0', #'esinw', 'ecosw', 'rprs']) #'impact', # free planet parameters are the same for every planet you model else: vary_planet = (['rprs']) fitT.free_parameters(vary_star, vary_planet) fitT.do_fit() # run the fitting return fitT
def transit_fit(t1, cfflux, cadence='long', rho=50.0): addtime = 4833 # convert from trappist time to kepler time time = t1 [(cfflux < 0.025) * (cfflux > -0.025)] +addtime # you need a time and a flux flux = cfflux[(cfflux < 0.025) * (cfflux > -0.025)] # there are no transits here :( ferr = np.ones_like(time) * 0.001 # uncertainty on the data fitT = FitTransit() fitT.add_guess_star(rho=rho, ld1 = 1.0181, ld2 = -0.0404) # fixed because I'm sleepy for planet in [planetb, planetc, planetd, planete, planetf, planetg, planeth]: fitT.add_guess_planet( period=planet['period_days'][0], impact=planet['impact'][0], T0=planet['t0'][0], rprs=(planet['td_percent'][0]/100)**0.5) if cadence == 'long': fitT.add_data(time=time, flux=flux, ferr=ferr, itime=np.ones_like(time) * 0.0188) elif cadence == 'short': fitT.add_data(time=time, flux=flux, ferr=ferr, itime=np.ones_like(time) * 0.0188 / 30) vary_star = ['rho', 'zpt'] # free stellar parameters vary_planet = (['period', # free planetary parameters 'T0', 'impact', 'rprs']) # free planet parameters are the same for every planet you model fitT.free_parameters(vary_star, vary_planet) fitT.do_fit() # run the fitting return time, flux, fitT
def main(kic): client = kplr.API() star = client.star(kic) lcs = star.get_light_curves(short_cadence=False) time, flux, ferr, quality,quarter = [], [], [], [], [] for lc in lcs: with lc.open() as f: # The lightcurve data are in the first FITS HDU. hdu_data = f[1].data time = np.r_[time,hdu_data["time"]] #fluxval = hdu_data["sap_flux"] #fluxmed = np.median(fluxval) #flux = np.r_[flux,fluxval / fluxmed] #ferr = np.r_[ferr,hdu_data["sap_flux_err"] / fluxmed] flux = np.r_[flux,hdu_data["sap_flux"]] ferr = np.r_[ferr,hdu_data["sap_flux_err"]] quality = np.r_[quality,hdu_data["sap_quality"]] quarter = np.r_[quarter,f[0].header["QUARTER"] + np.zeros(len(hdu_data["time"]))] flux, ferr = byebyebaddata(flux,ferr,quality) flux, ferr = norm_by_quarter(flux, ferr,quarter) cflux = (flux / med_filt(time,flux,dt=1.0)) - 1.0 time,cflux,ferr = i_hate_nans(time,cflux,ferr) fitT = FitTransit() fitT.add_guess_star(rho=2.45) k0 = star.kois[0] fitT.add_guess_planet( period=k0.koi_period, impact=k0.koi_impact, T0=k0.koi_time0bk, rprs=k0.koi_ror) k1 = star.kois[1] fitT.add_guess_planet( period=k1.koi_period, impact=k1.koi_impact, T0=k1.koi_time0bk, rprs=k1.koi_ror) k2 = star.kois[2] fitT.add_guess_planet( period=k2.koi_period, impact=k2.koi_impact, T0=k2.koi_time0bk, rprs=k2.koi_ror) fitT.add_data(time=time,flux=cflux,ferr=ferr) freeparstar = ['rho','zpt'] freeparplanet = [ 'period','T0','impact','rprs'] fitT.free_parameters(freeparstar,freeparplanet) fitT.do_fit() return (time,cflux,ferr),fitT
def main(kic): client = kplr.API() star = client.star(kic) lcs = star.get_light_curves(short_cadence=False) time, flux, ferr, quality, quarter = [], [], [], [], [] for lc in lcs: with lc.open() as f: # The lightcurve data are in the first FITS HDU. hdu_data = f[1].data time = np.r_[time, hdu_data["time"]] #fluxval = hdu_data["sap_flux"] #fluxmed = np.median(fluxval) #flux = np.r_[flux,fluxval / fluxmed] #ferr = np.r_[ferr,hdu_data["sap_flux_err"] / fluxmed] flux = np.r_[flux, hdu_data["sap_flux"]] ferr = np.r_[ferr, hdu_data["sap_flux_err"]] quality = np.r_[quality, hdu_data["sap_quality"]] quarter = np.r_[quarter, f[0].header["QUARTER"] + np.zeros(len(hdu_data["time"]))] flux, ferr = byebyebaddata(flux, ferr, quality) time, flux, ferr, quarter, quality = i_hate_nans(time, flux, ferr, quarter, quality) flux, ferr = norm_by_quarter(flux, ferr, quarter) cflux = (flux / med_filt(time, flux, dt=1.0)) - 1.0 fitT = FitTransit() fitT.add_guess_star(rho=2.45) k0 = star.kois[0] fitT.add_guess_planet(period=k0.koi_period, impact=k0.koi_impact, T0=k0.koi_time0bk, rprs=k0.koi_ror) k1 = star.kois[1] fitT.add_guess_planet(period=k1.koi_period, impact=k1.koi_impact, T0=k1.koi_time0bk, rprs=k1.koi_ror) k2 = star.kois[2] fitT.add_guess_planet(period=k2.koi_period, impact=k2.koi_impact, T0=k2.koi_time0bk, rprs=k2.koi_ror) fitT.add_data(time=time, flux=cflux, ferr=ferr) freeparstar = ['rho', 'zpt'] freeparplanet = ['period', 'T0', 'impact', 'rprs'] fitT.free_parameters(freeparstar, freeparplanet) fitT.do_fit() return (time, cflux, ferr), fitT
def fitModel(time, flux, guessDict, freeParPlanet, ferr = 0): if not np.all(ferr): ferr = np.ones_like(flux)*1.E-5 freeParStar = ['rho'] # Make the fitting object according to guess dictionary fitT = FitTransit() fitT.add_guess_star(ld1 = 0, ld2 = 0) fitT.add_guess_planet(period = guessDict['period'], T0 = guessDict['T0']) fitT.add_data(time = time, flux = flux, ferr = ferr) fitT.free_parameters(freeParStar, freeParPlanet) fitT.do_fit() return fitT
def fitModel(time, flux, guessDict, freeParPlanet, ferr = 0): if not np.all(ferr): ferr = np.ones_like(flux)*1.E-5 freeParStar = ['rho'] # Make the fitting object according to guess dictionary fitT = FitTransit() fitT.add_guess_star(ld1 = 0, ld2 = 0) fitT.add_guess_planet(period = guessDict['period'], T0 = guessDict['T0']) fitT.add_data(time = time, flux = flux, ferr = ferr) fitT.free_parameters(freeParStar, freeParPlanet) fitT.do_fit() return fitT
def fit_data(data, star=[1.4,0,0,0,0,0,1], planet=[365,0.0,0.0,.009155, 0.0, 0.0, 0.0], star_vary=[''], planet_vary=[''], auto=True, fold=False): """solves problems in assignment 2 star = stellar density, limb darkening parameters (4), dilution, zpt planet = T0, period, impact, rprs, ecosw, esinw, occ """ # Estimating basic input parameters, unless we give them in the call if auto: box = 5; sm_flux = msmooth(data[1],box) star[-1] = np.median(sm_flux) # Establishing photometric zero-point if fold: star[-1] += np.std(data[1]) ind = np.where(sm_flux < star[-1]-np.std(data[1]))[0] ind = ind[np.where(ind > box)] ind = ind[0] planet[0] = data[0][ind] # Estimating something close to a transit midpoint if fold: if star[0] > 15: planet[0] = 0.8 planet[3] = (data[1].max()-data[1].min())**0.5 # Estimating the depth # Performing the actual fit fitT = FitTransit() fitT.add_guess_star(rho=star[0], ld1=star[1], ld2=star[2],ld3=star[3],ld4=star[4], dil=star[5], zpt=star[6]) fitT.add_guess_planet(T0=planet[0], period=planet[1],impact=planet[2], rprs=planet[3],ecosw=planet[4],esinw=planet[5], occ=planet[6]) fitT.add_data(time=data[0],flux=data[1],ferr=data[2]) fitT.free_parameters(star_vary, planet_vary) fitT.do_fit() return fitT.__dict__['fitresultstellar'], \ fitT.__dict__['fitresultplanets'], \ fitT.transitmodel, star, planet
#fluxDetrend = [x-1.0 for x in fluxDetrend] fitT = FitTransit() fitT.add_guess_star(rho=1.5) fitT.add_guess_planet(period=results[1], impact=0.0, T0=3.0, rprs=.2) #need a guess rprs fitT.add_data(time=time, flux=fluxDetrend) vary_star = [ 'rho' ] # not sure how to avoid free stellar parameters? ideally would not vary star at all vary_planet = (['period', 'rprs', 'impact', 'T0']) fitT.free_parameters(vary_star, vary_planet) fitT.do_fit() #print(fitT.fitresultstellar.items()) #print(fitT.fitresultplanets.items()) bestFstellar = fitT.fitresultstellar.items() bestFrho = bestFstellar[0][1] #Best Fit Rho bestFplanet = fitT.fitresultplanets.items() bestFperiod = bestFplanet[0][1]['period'] #Best Fit Period bestFrprs = bestFplanet[0][1]['rprs'] #Best Fit rprs fitT.print_results() #save figure
ell=50.8, alb=27) # radial velocity semi-amplitude in m/s time,flux,ferr = get_lc() rvtime,rvval,rverr = get_rv() fitT.add_data( time=time, flux=flux,ferr=ferr) fitT.add_rv(rvtime=rvtime, # radial velocity observation timestamps rvval=rvval,rverr=rverr) # integration time of each timestamp vary_star = ['rho', 'zpt'] # free stellar parameters vary_planet = (['period', # free planetary parameters 'T0', 'impact', 'rprs']) # free planet parameters are the same for every planet you model fitT.free_parameters(vary_star, vary_planet) fitT.do_fit() #plt.plot(fitT.time,fitT.tmod) #plt.plot(M.rvtime,rvmodel)