delta_chi2 = {}#np.zeros(len(transits)) with ProgressBar(len(transits)) as bar: for i, lc in enumerate(transits): #lc.plot() # Remove linear out-of-transit trend from transit lc.remove_linear_baseline(kepler17_params) residuals = lc.fluxes - generate_lc_depth(lc.times_jd, depth, kepler17_params) best_fit_params = peak_finder(lc.times.jd, residuals, lc.errors, kepler17_params) transit_model = generate_lc_depth(lc.times_jd, depth, kepler17_params) chi2_transit = np.sum((lc.fluxes - transit_model)**2/lc.errors**2)/len(lc.fluxes) gaussian_model = summed_gaussians(lc.times.jd, best_fit_params) if best_fit_params is not None: split_input_parameters = np.split(np.array(best_fit_params), len(best_fit_params)/3) delta_chi2[i] = [] for amplitude, t0, sigma in split_input_parameters: model_i = gaussian(lc.times.jd, amplitude, t0, sigma) chi2_bumps = np.sum((lc.fluxes - transit_model - model_i)**2/lc.errors**2)/len(lc.fluxes) delta_chi2[i].append(np.abs(chi2_transit - chi2_bumps)) if plots: fig, ax = plt.subplots(3, 1, figsize=(8, 14), sharex=True) ax[0].errorbar(lc.times.jd, lc.fluxes, lc.errors, fmt='.', color='k') ax[0].plot(lc.times.jd, transit_model, 'r') ax[0].set(ylabel='Flux')
lc = transits[104] # Remove linear out-of-transit trend from transit lc.remove_linear_baseline() depth = 0.13413993**2 residuals = lc.fluxes - generate_lc_depth(lc.times_jd, depth) # Fit the transit model residuals for n_peaks gaussians sampler, samples = run_emcee(lc.times.jd, residuals, lc.errors, n_peaks=4) # Plot the results import corner corner.corner(samples) median_params = np.median(samples, axis=0) transit_model = generate_lc_depth(lc.times_jd, depth) gaussian_model = summed_gaussians(lc.times.jd, median_params) fig, ax = plt.subplots(3, 1, figsize=(8, 14), sharex=True) ax[0].errorbar(lc.times.jd, lc.fluxes, lc.errors, fmt='.', color='k') ax[0].plot(lc.times.jd, transit_model, 'r') ax[0].set(ylabel='Flux') ax[1].errorbar(lc.times.jd, lc.fluxes - transit_model, fmt='.', color='k') ax[1].errorbar(lc.times.jd, gaussian_model, fmt='.', color='r') ax[1].axhline(0, color='r') ax[1].set_ylabel('Transit Residuals') ax[2].errorbar(lc.times.jd, lc.fluxes - transit_model - gaussian_model, fmt='.', color='k') ax[2].axhline(0, color='r') ax[2].set_ylabel('Gaussian Residuals')