def detrend(time, merged_flux): trend = untrendy.median(time, merged_flux, dt=0.6) mergedfluxD = np.zeros(len(time)) for i in range(len(time)): mergedfluxD[i] = merged_flux[i] - trend[i] return mergedfluxD
def medfilt(time,flux,window=10.0): """ window in days """ flux = flux / untrendy.median( time,flux,dt=window) return flux
########################## #END LOOP ########################## ###################################### #UNCOMMMENT TO SAVE DIFF, SDE, PER, RAD TEXT OUTPUT #CHANGE PATH TO APPROPRIATE BLANK TEXT FILE ###################################### #np.savetxt('/Users/sheilasagear/OneDrive/K2_Research/bls-ktransit/SDE_text/data213244700.txt', np.column_stack((detect_diff, detect_SDE, detect_BLS_per, detect_per, detect_rad)), fmt='%.5f') ########################## #INITIAL LIGHT CURVE ########################## q = untrendy.median(time, flux) """ pylab.cla() fig, ax = plt.subplots(1, 1, figsize=[11,8]) ax.scatter(time, flux, color='k', s=2) ax.plot(time, q, color='mediumaquamarine') ax.set_xlabel('Time') ax.set_ylabel('Corrected Flux (Normalized)') ax.set_title('EPIC ' + str(targetname)) #show() """ #color for outliers
#print('flux = ' + str(type(flux))) flux = np.asarray(flux) time = np.asarray(time) #print(type(flux)) #SIGMA CLIPPING flux = sigma_clip(flux, sigma=3, iters=1) flux = flux.filled(fill_value=0) #uncomment if extra trend = untrendy.median(time, flux) fluxDetrend = np.zeros(len(time)) for i in range(len(time)): fluxDetrend[i] = flux[i] - trend[i] ax.scatter(time, fluxDetrend, marker='o', color='k', s=1) ax.set_title('EPIC 217976219', fontsize=20) ax.set_xlabel('Time (days)', fontsize=20) ax.set_ylabel('Detrended Flux', fontsize=20) #show() #period = np.random.randint(low=1, high=26) period = 8.0 tested_period.append(period)
def setup(gp=True): client = kplr.API() # Query the KIC and get some parameters. kic = client.star(7364176) teff, logg, feh = kic.kic_teff, kic.kic_logg, kic.kic_feh assert teff is not None # Get the limb darkening law. mu1, mu2 = get_quad_coeffs(teff, logg=logg, feh=feh) bins = np.linspace(0, 1, 50)[1:] ** 0.5 ldp = bart.ld.QuadraticLimbDarkening(mu1, mu2).histogram(bins) # Build the star object. star = bart.Star(ldp=ldp) # Set up the planet. prng = 5.0 period = 272.1884457597957407 size = 0.01 epoch = 103.7235285266694973 + 0.265 a = star.get_semimajor(period) b = 0.1 incl = np.degrees(np.arctan2(a, b)) planet = bart.Planet(size, a, t0=epoch) # Set up the system. ps = bart.PlanetarySystem(star, iobs=incl) ps.add_planet(planet) # Initialize the model. model = bart.Model(ps) # Load the data and inject into each transit. lcs = kic.get_light_curves(short_cadence=False, fetch=False) # Loop over the datasets and read in the data. minn, maxn = 1e10, 0 for lc in lcs: with lc.open() as f: # The light curve data are in the first FITS HDU. hdu_data = f[1].data time_, flux_, ferr_, quality = [hdu_data[k] for k in ["time", "sap_flux", "sap_flux_err", "sap_quality"]] # Mask the missing data. mask = (np.isfinite(time_) * np.isfinite(flux_) * np.isfinite(ferr_) * (quality == 0)) time_, flux_, ferr_ = [v[mask] for v in [time_, flux_, ferr_]] # Cut out data near transits. hp = 0.5 * period inds = np.abs((time_ - epoch + hp) % period - hp) < prng if not np.sum(inds): continue time_, flux_, ferr_ = [v[inds] for v in [time_, flux_, ferr_]] # Inject the transit. flux_ *= ps.lightcurve(time_) tn = np.array(np.round(np.abs((time_ - epoch) / period)), dtype=int) alltn = set(tn) maxn = max([maxn, max(alltn)]) minn = min([minn, min(alltn)]) for n in alltn: m = tn == n tf = time_[m] fl = flux_[m] fle = ferr_[m] if not gp: mu = untrendy.median(tf, fl, dt=4.0) fl /= mu fle /= mu model.datasets.append(dsc(tf, fl, fle, alpha=1.0, l2=3.0, dtbin=None)) # Add some priors. dper = prng / (maxn - minn) # Add some parameters. model.parameters.append(Parameter(planet, "t0")) model.parameters.append(Parameter(planet, "r")) model.parameters.append(ImpactParameter(planet)) # Prior range for the period so that it doesn't predict transits outside # of the data range. ppr = UniformPrior(period - dper, period + dper) model.parameters.append(PeriodParameter(planet, lnprior=ppr)) return model, period
def setup(gp=True): client = kplr.API() # Query the KIC and get some parameters. # kic = client.star(8415109) # Bright variable. kic = client.star(2301306) # Quiet G-type. teff, logg, feh = kic.kic_teff, kic.kic_logg, kic.kic_feh assert teff is not None # Get the limb darkening law. mu1, mu2 = get_quad_coeffs(teff, logg=logg, feh=feh) bins = np.linspace(0, 1, 50)[1:] ** 0.5 ldp = bart.ld.QuadraticLimbDarkening(mu1, mu2).histogram(bins) # Build the star object. star = bart.Star(ldp=ldp) # Set up the planet. prng = 3.0 period = 278. size = 0.03 epoch = 20.0 a = star.get_semimajor(period) b = 0.3 incl = np.degrees(np.arctan2(a, b)) planet = bart.Planet(size, a, t0=epoch) # Set up the system. ps = bart.PlanetarySystem(star, iobs=incl) ps.add_planet(planet) # Initialize the model. model = bart.Model(ps) # Load the data and inject into each transit. lcs = kic.get_light_curves(short_cadence=False, fetch=False) # Choose the type of dataset to use. if gp: args = {"alpha": 1.0, "l2": 3.0, "dtbin": None} dsc = bart.data.GPLightCurve else: args = {"dtbin": None} dsc = bart.data.LightCurve # Loop over the datasets and read in the data. minn, maxn = 1e10, 0 for lc in lcs: with lc.open() as f: # The light curve data are in the first FITS HDU. hdu_data = f[1].data time_, flux_, ferr_, quality = [hdu_data[k] for k in ["time", "sap_flux", "sap_flux_err", "sap_quality"]] # Mask the missing data. mask = (np.isfinite(time_) * np.isfinite(flux_) * np.isfinite(ferr_) * (quality == 0)) time_, flux_, ferr_ = [v[mask] for v in [time_, flux_, ferr_]] # Cut out data near transits. hp = 0.5 * period inds = np.abs((time_ - epoch + hp) % period - hp) < prng if not np.sum(inds): continue time_, flux_, ferr_ = [v[inds] for v in [time_, flux_, ferr_]] # Inject the transit. flux_ *= ps.lightcurve(time_) if not gp: mu = untrendy.median(time_, flux_, dt=3.0) flux_ /= mu ferr_ /= mu tn = np.array(np.round(np.abs((time_ - epoch) / period)), dtype=int) alltn = set(tn) maxn = max([maxn, max(alltn)]) minn = min([minn, min(alltn)]) for n in alltn: m = tn == n tf = time_[m] fl = flux_[m] fle = ferr_[m] model.datasets.append(dsc(tf, fl, fle, **args)) # Add some priors. dper = prng / (maxn - minn) # Add some parameters. model.parameters.append(Parameter(planet, "t0")) model.parameters.append(Parameter(planet, "r")) model.parameters.append(ImpactParameter(planet)) # Prior range for the period so that it doesn't predict transits outside # of the data range. ppr = UniformPrior(period - dper, period + dper) model.parameters.append(PeriodParameter(planet, lnprior=ppr)) # # Sample in the GP hyper-parameters. # apr = UniformPrior(0.0, 10.0) # model.parameters.append(MultiParameter(model.datasets, "alpha", # lnprior=apr)) # lpr = UniformPrior(3.0, 20.0) # model.parameters.append(MultiParameter(model.datasets, "l2", # lnprior=lpr)) return model, period