Example #1
0
results = compute_best_frequencies(ids, n_eval=10000, n_retry=5)

#------------------------------------------------------------
# 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)
Example #2
0
for f in factors:
    for n in nterms:
        PSDs[(f, n)] = multiterm_periodogram(t, y, dy, omega / f, n)

# Compute the best-fit omega from the 6-term fit
omega_best = dict()
for f in factors:
    omegaf = omega / f
    PSDf = PSDs[(f, 6)]
    omega_best[f] = omegaf[np.argmax(PSDf)]

# Compute the best-fit solution based on the fundamental frequency
best_fit = dict()
for f in factors:
    for n in nterms:
        mtf = MultiTermFit(omega_best[f], n)
        mtf.fit(t, y, dy)
        phase_best, y_best = mtf.predict(1000, adjust_offset=False)

        best_fit[(f, n)] = (phase_best, y_best)

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(12, 6))
fig.subplots_adjust(left=0.07, right=0.95, wspace=0.18,
                    bottom=0.1, top=0.95, hspace=0.12)

for i, f in enumerate(factors):
    P_best = 2 * np.pi / omega_best[f]
    phase_best = (t / P_best) % 1
Example #3
0
for f in factors:
    for n in nterms:
        PSDs[(f, n)] = multiterm_periodogram(t, y, dy, omega / f, n)

# Compute the best-fit omega from the 6-term fit
omega_best = dict()
for f in factors:
    omegaf = omega / f
    PSDf = PSDs[(f, 6)]
    omega_best[f] = omegaf[np.argmax(PSDf)]

# Compute the best-fit solution based on the fundamental frequency
best_fit = dict()
for f in factors:
    for n in nterms:
        mtf = MultiTermFit(omega_best[f], n)
        mtf.fit(t, y, dy)
        phase_best, y_best = mtf.predict(1000, adjust_offset=False)

        best_fit[(f, n)] = (phase_best, y_best)

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 2.5))
fig.subplots_adjust(left=0.1, right=0.95, wspace=0.25,
                    bottom=0.12, top=0.95, hspace=0.2)

for i, f in enumerate(factors):
    P_best = 2 * np.pi / omega_best[f]
    phase_best = (t / P_best) % 1
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]
Example #5
0
    fluxByPhase = [f for _, f in sorted(zip(phase, astDiffFlux))]
    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,