def run_acf(self): """ Compute the autocorrelation function. """ self.lags, self.acf = interpacf.interpolated_acf( self.l_curve.times, self.l_curve.fluxes, cadences=self.l_curve.cadences)
def detect(ts_data, ts_timestamp): ts_data = is_array(ts_data) ts_timestamp = is_array(ts_timestamp) ts_data_ = ts_data - np.mean(ts_data) lag, acf = interpolated_acf(ts_timestamp, ts_data_) # TODO: 当使用csv_test.csv时,出现detected_period为non的情况 detected_period = dominant_period(lag, acf, plot=False) interval = int(get_interval(ts_timestamp)) return int(detected_period // interval)
def fig_acf(lc): """ display the acf results of light curve. However, this package is not robust as Mcquillian method. So we just take it as a reference. The acf accurate results are adopted from Mcq+ catalog Return: ------- figure: matplotlib.figure.Figure """ x = lc.lcf.time y = lc.lcf.flux min_period = np.max(sigmaclip(np.diff(x))[0]) max_period = 0.5 * (x.max() - x.min()) lag, acf = interpolated_acf(x, y) period, fig = dominant_period(lag, acf, min=min_period, max=max_period, plot=True) return period, fig
def k2_test(style=None): """ Demonstrate the technique for a K2 EB. Parameters ---------- style : str, optional The name of a matplotlib style sheet. """ nova = pd.read_csv("villanova-db.csv") # Load Aigrain et al. (2015) pipeline light curve. hdu = fits.open("hlsp_k2sc_k2_llc_212012387-c05_kepler_v1_lc.fits") time = hdu[1].data["time"] cadence = hdu[1].data["cadence"] # Add back stellar variability correction. flux = hdu[1].data["flux"] + hdu[1].data["trend_t"] - \ np.nanmedian(hdu[1].data["trend_t"]) flux /= np.nanmedian(flux) # Mask out bad fluxes finite = np.isfinite(flux) time = time[finite] flux = flux[finite] cadence = cadence[finite] # Load parameters from Villanova catalog epic = 212012387 eb = nova[nova["KIC"] == epic] p_orb = eb.period.values[0] t_0 = eb.bjd0.values[0] p_width = eb.pwidth.values[0] s_width = eb.swidth.values[0] sep = eb.sep.values[0] phase = ((time - t_0) % p_orb) / p_orb window = 1.0 mask = ((phase > p_width * window) & (phase < 1 - p_width * window)) & \ ((phase > sep + s_width * window) | (phase < sep - s_width * window)) timecut = time[mask] fluxcut = flux[mask] cadencecut = cadence[mask] model = LombScargleFast().fit(time, flux) period, power = model.periodogram_auto(oversampling=5) model = LombScargleFast().fit(timecut, fluxcut) period_c, power_c = model.periodogram_auto(oversampling=5) lag, acf = interpacf.interpolated_acf(time, flux - np.median(flux), cadence) lag_c, acf_c = interpacf.interpolated_acf(timecut, fluxcut - np.median(fluxcut), cadencecut) if style is not None: plt.style.use(style) plt.rcParams["font.size"] = 22 fig = plt.figure(figsize=(15, 12)) ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=2) ax2 = plt.subplot2grid((2, 2), (1, 0)) ax3 = plt.subplot2grid((2, 2), (1, 1)) # Plot lightcurve offset = 2304. ax1.plot(time - offset, flux, lw=1, color="k", alpha=0.4) ax1.plot(timecut - offset, fluxcut, lw=1, color="k") ax1.set_ylim(0.95, 1.01) ax1.set_xlabel("BJD - {0:.0f}".format(2454833 + offset)) ax1.set_ylabel("Normalized Flux") ax1.minorticks_on() # Plot periodograms ax2.plot(period, 2 * power, color="r", lw=1.25, alpha=1.0) ax2.plot(period_c, power_c, color="k", lw=1.25) ax2.axvline(p_orb, color="k", lw=1.5, linestyle=":") ax2.axvline(p_orb / 2., color="k", lw=1.5, linestyle=":") ax2.text(p_orb, ax2.get_ylim()[1] + 0.01, "$P_{orb}$", ha="center") ax2.text(p_orb / 2., ax2.get_ylim()[1] + 0.01, "$P_{orb}/2$", ha="center") ax2.set_xlabel("Period (days)") ax2.set_ylabel("Normalized Power") ax2.minorticks_on() ax2.set_xlim(0.01, 10) ax2.set_ylim(0, 0.6) ax3.plot(lag, acf / acf.max(), color="r", lw=1.5, alpha=1.0) ax3.plot(lag_c, acf_c / acf_c.max(), color="k", lw=1.5) ax3.axvline(p_orb, color="k", lw=1.5, linestyle=":") ax3.axvline(p_orb / 2., color="k", lw=1.5, linestyle=":") ax3.text(p_orb, 1.05, "$P_{orb}$", ha="center") ax3.text(p_orb / 2., 1.05, "$P_{orb}/2$", ha="center") ax3.minorticks_on() ax3.set_xlim(0.01, 10) ax3.set_ylim(-0.55, 1) ax3.set_xlabel("Lag (days)") ax3.set_ylabel("ACF") fig.suptitle("EPIC {0}".format(epic), fontsize=26, y=0.94) fig.subplots_adjust(wspace=0.3, hspace=0.35) plt.savefig("k2_removal_demo.pdf")
def eclipse_removal(kic, p_xlim=(0, 40), timerange=None, style=None,): """ Demonstrate the removal of eclipse signal. Parameters ---------- kic : int The system KIC number. p_xlim : 2-tuple, optional The x-limit of the periodogram plot. (Default: (0, 40)) timerange : 2-tuple, optional The time range of the light curve plot in Kepler mission days. Default plots first 50 days of light curve. style : str, optional The name of a matplotlib style sheet. """ binary = binaries.RealBinary(kic) timecut, fluxcut, errcut, cadencecut = binary.curve_cut(window=0.75)[:4] period, power = binary.periodogram(binary.time, binary.flux, binary.err, oversampling=1) period_c, power_c = binary.periodogram(timecut, fluxcut, errcut, oversampling=1) lag, acf = interpacf.interpolated_acf(binary.time, binary.flux - np.median(binary.flux), binary.cadence) lag_c, acf_c = interpacf.interpolated_acf(timecut, fluxcut - np.median(fluxcut), cadencecut) if style is not None: plt.style.use(style) if timerange is None: timerange = (binary.time[0], binary.time[0] + 50) plt.rcParams["font.size"] = 22 fig = plt.figure(figsize=(15, 12)) ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=2) ax2 = plt.subplot2grid((2, 2), (1, 0)) ax3 = plt.subplot2grid((2, 2), (1, 1)) # Plot lightcurve offset = timerange[0] ax1.plot(binary.time - offset, binary.flux, lw=1, color="k", alpha=0.4) ax1.plot(timecut - offset, fluxcut, lw=1, color="k") ax1.set_xlim(0, timerange[-1] - timerange[0]) ax1.set_ylim(0.95, 1.03) ax1.set_xlabel("BJD - {0:.0f}".format(2454833 + offset)) ax1.set_ylabel("Normalized Flux") ax1.minorticks_on() # Plot periodograms ax2.plot(period_c, power_c, color="k", lw=1.25) ax2.plot(period, 2 * power, color="r", lw=1.25, alpha=1, zorder=2) ax2.axvline(binary.p_orb, color="k", lw=1.5, linestyle=":") ax2.axvline(binary.p_orb / 2., color="k", lw=1.5, linestyle=":") ax2.text(binary.p_orb, ax2.get_ylim()[1] + 0.01, "$P_{orb}$", ha="center") ax2.text(binary.p_orb / 2., ax2.get_ylim()[1] + 0.01, "$P_{orb}/2$", ha="center") ax2.set_xlabel("Period (days)") ax2.set_ylabel("Normalized Power") ax2.minorticks_on() ax2.set_xlim(p_xlim) ax3.plot(lag, acf / acf.max(), color="r", lw=1.5, alpha=1.0) ax3.plot(lag_c, acf_c / acf_c.max(), color="k", lw=1.5) ax3.axvline(binary.p_orb, color="k", lw=1.5, linestyle=":") ax3.axvline(binary.p_orb / 2., color="k", lw=1.5, linestyle=":") ax3.text(binary.p_orb, 1.05, "$P_{orb}$", ha="center") ax3.text(binary.p_orb / 2., 1.05, "$P_{orb}/2$", ha="center") ax3.minorticks_on() ax3.set_xlim(p_xlim) ax3.set_ylim(-0.5, 1) ax3.set_xlabel("Lag (days)") ax3.set_ylabel("ACF") fig.suptitle("KIC {0}".format(kic), fontsize=26, y=0.94) fig.subplots_adjust(wspace=0.3, hspace=0.35) plt.savefig("removal_demo.pdf")
# ax[1, 0].plot(obs_time, model_residual, 'r', lw=2, zorder=10, label='microvar + spots') ax[1, 0].plot(obs_time, transitless_gp_mean, color='DodgerBlue', label='GP-transit', zorder=15) ax[1, 0].legend() ax[1, 0].set(xlabel='Time [d]', ylabel='Residuals') nparams = 5 # samples_t0 = obs_planet.samples_t0.reshape((len(obs_planet.samples_t0)//nparams, nparams)) samples_t0 = obs_planet.samples_t0.reshape( (nparams, len(obs_planet.samples_t0) // nparams)) for chain in samples_t0: lag, acf = interpolated_acf(np.arange(len(chain)), chain - np.median(chain)) ax[1, 1].plot(lag, acf / acf.max()) ax[1, 1].set_title('$t_0$ chains ACF') ax[1, 1].set(xlabel='Lag [d]', ylabel='ACF') lag, acf = interpolated_acf( obs_time, transitless_obs_flux - np.median(transitless_obs_flux)) ax[1, 3].plot(lag, acf / np.percentile(acf, 98), label='(Obs - transit) ACF') #ax[1, 3].set_title('(Obs. - transit) ACF') lag, acf = interpolated_acf( obs_time, transitless_gp_mean - np.median(transitless_gp_mean)) ax[1, 3].plot(lag, acf / acf.max(),