Esempio n. 1
0
 def clean_lc(self, threshold=1.7):
     for i, lc in enumerate(self.lc):
         x = lc.data.phase
         y = lc.data.mag
         if "mag_err" in lc.data.columns:
             y_err = lc.data.mag_err
         else:
             y_err = np.ones_like(x) * 0.1
         mtf = MultiTermFit(2 * np.pi, 8)
         mtf.fit(x, y, y_err)
         X_scaled = mtf._make_X(x)
         y_fit = np.dot(X_scaled, mtf.w_)
         v = y - y_fit
         v_mean = np.mean(v)
         v_std = np.std(v)
         flag = np.abs(v - v_mean) / v_std < threshold
         self.lc[i].data = self.lc[i].data.assign(flag=flag)
Esempio n. 2
0
#------------------------------------------------------------
# Plot the phased light-curves
fig = plt.figure(figsize=(5, 6.5))
fig.subplots_adjust(hspace=0.1, bottom=0.06, top=0.94, left=0.12, right=0.94)

for i in range(6):
    # get the data and best-fit angular frequency
    t, y, dy = data[ids[i]].T
    omega, power = results[ids[i]]
    omega_best = omega[np.argmax(power)]
    print " - omega_0 = %.10g" % omega_best

    # do a fit to the first 4 Fourier components
    mtf = MultiTermFit(omega_best, 4)
    mtf.fit(t, y, dy)
    phase_fit, y_fit, phased_t = mtf.predict(1000, return_phased_times=True)

    # plot the phased data and best-fit curves
    ax = fig.add_subplot(321 + i)
    ax.errorbar(phased_t, y, dy, fmt='.k', ecolor='gray',
                lw=1, ms=4, capsize=1.5)
    ax.plot(phase_fit, y_fit, '-b', lw=2)

    ax.set_xlim(0, 1)
    ax.set_ylim(plt.ylim()[::-1])
    ax.yaxis.set_major_locator(plt.MaxNLocator(4))

    ax.text(0.03, 0.04, "ID = %i" % ids[i], ha='left', va='bottom',
            transform=ax.transAxes)
    ax.text(0.03, 0.96, "P = %.2f hr" % (2 * np.pi / omega_best * 24.),
Esempio n. 3
0
#------------------------------------------------------------
# Plot the phased light-curves
fig = plt.figure(figsize=(8, 10))
fig.subplots_adjust(hspace=0.1)

for i in range(6):
    # get the data and best-fit angular frequency
    t, y, dy = data[ids[i]].T
    omega, power = results[ids[i]]
    omega_best = omega[np.argmax(power)]
    print " - omega_0 = %.10g" % omega_best

    # do a fit to the first 4 Fourier components
    mtf = MultiTermFit(omega_best, 4)
    mtf.fit(t, y, dy)
    phase_fit, y_fit, phased_t = mtf.predict(1000, return_phased_times=True)

    # plot the phased data and best-fit curves
    ax = fig.add_subplot(321 + i)
    ax.errorbar(phased_t, y, dy, fmt='.k', ecolor='gray',
                lw=1, ms=4, capsize=2)
    ax.plot(phase_fit, y_fit, '-b', lw=2)

    ax.set_xlim(0, 1)
    ax.set_ylim(plt.ylim()[::-1])
    ax.yaxis.set_major_locator(plt.MaxNLocator(4))

    ax.text(0.02, 0.02, "ID = %i" % ids[i], ha='left', va='bottom',
            transform=ax.transAxes, fontsize=14)
    ax.text(0.02, 0.98, "P = %.2f hr" % (2 * np.pi / omega_best * 24.),
for i, window in enumerate(windows):
    plt.figure()
    ## A ##
    # get the data and best-fit angular frequency
    tA = data['t_eval'][data['window_id'] == window]
    yA = data['sig_evalA'][data['window_id'] == window]
    yA = (yA - np.mean(yA)) / np.std(yA)
    dyA = data['sig_errA'][data['window_id'] == window]
    dyA = (dyA - np.mean(dyA)) / np.std(dyA)
    omegaA, powerA = resultsA[window]
    omega_bestA = omegaA[np.argmax(powerA)]
    print " - omega_0A = %.10g" % omega_bestA

    # do a fit to the first 4 Fourier components
    mtfA = MultiTermFit(omega_bestA, 10)
    mtfA.fit(tA, yA, dyA)
    phase_fitA, y_fitA, phased_tA = mtfA.predict(1000,
                                                 return_phased_times=True)

    plt.errorbar(phased_tA,
                 yA,
                 dyA,
                 fmt='.r',
                 ecolor='gray',
                 lw=1,
                 ms=4,
                 capsize=1.5)
    plt.plot(phase_fitA,
             y_fitA,
             '-b',
             lw=2,
for i, window in enumerate(windows):
    plt.figure()
    ## A ##
    # get the data and best-fit angular frequency
    tA = data['t_eval'][data['window_id']==window]
    yA = data['sig_evalA'][data['window_id']==window]
    yA = (yA - np.mean(yA)) / np.std(yA)
    dyA = data['sig_errA'][data['window_id']==window]
    dyA = (dyA - np.mean(dyA)) / np.std(dyA)
    omegaA, powerA = resultsA[window]
    omega_bestA = omegaA[np.argmax(powerA)]
    print " - omega_0A = %.10g" % omega_bestA

    # do a fit to the first 4 Fourier components
    mtfA = MultiTermFit(omega_bestA, 10)
    mtfA.fit(tA, yA, dyA)
    phase_fitA, y_fitA, phased_tA = mtfA.predict(1000, return_phased_times=True)
    
    plt.errorbar(phased_tA, yA, dyA,
                     fmt='.r', ecolor='gray',
                     lw=1, ms=4, capsize=1.5)
    plt.plot(phase_fitA, y_fitA, '-b', lw=2, label="P_A = %.2f day" %(2 * np.pi / omega_bestA * 24. * 365.))
    ## B ##
    # get the data and best-fit angular frequency
    tB = data['t_eval'][data['window_id']==window]
    yB = data['sig_evalB'][data['window_id']==window]
    yB = (yB - np.mean(yB)) / np.std(yB)
    dyB = data['sig_errB'][data['window_id']==window]
    dyB = (dyB - np.mean(dyB)) / np.std(dyB)
    omegaB, powerB = resultsB[window]
    omega_bestB = omegaB[np.argmax(powerB)]
Esempio n. 6
0
    errByPhase = [f for _, f in sorted(zip(phase, astFluxErr))]
    sortedPhase = sorted(phase)
    sortedPhaseBin = sorted(rtp.binning(phase, time, binW, ind)[0])
    fluxByPhaseBin = rtp.binWeighted(fluxByPhase, time, astFluxErr, binW,
                                     ind)[0]
    weights = [1. / (err**2) for err in errByPhase]
    pfit = np.poly1d(np.polyfit(sortedPhase, fluxByPhase, deg=d, w=weights))
    fitCurve = pfit(sortedPhase)
    strCurve = fluxByPhase / fitCurve

fluxByPhaseSG = savitzky_golay(fluxByPhase, window_size=wsSG, order=4)

#----- Fourier Fit ------------------------------------------------------------
omega = 2 * np.pi / Prot * 24.
mtf = MultiTermFit(omega, ffOrder)
mtf.fit(time, astDiffFlux, astFluxErr)
phaseFit, fluxFit, phasedTime = mtf.predict(1000, return_phased_times=True)

phaseFit -= phasedTime[0]
phasedTime -= phasedTime[0]
phasedTime = [1 + t if t < 0 else t for t in phasedTime]
phaseFit = [1 + t if t < 0 else t for t in phaseFit]

plt.errorbar(phasedTime,
             astDiffFlux,
             astFluxErr,
             fmt='.k',
             ecolor='gray',
             lw=1,
             ms=4,
             capsize=1.5)