Exemple #1
0
    def _compute_thresholds(t,
                            y,
                            dy,
                            omegas,
                            confidence=None,
                            nbootstraps=1000):
        """
        Determine periodicity significance thresholds. Thresholds are obtained by repeatedly subsampling data, then compiling a distribution of maximum power levels detected in each sample.

        Args:

            t (np.ndarray) - timepoints

            y (np.ndarray) - values

            dy (np.ndarray) - estimated measurement error

            omega (np.ndarray) - spectral frequencies tests

            confidence (array like) - confidence levels to assess, length C

            nbootstraps (int) - number of boostrap samples

        Returns:

            thresholds (np.ndarray) - spectral power thresholds, length C

        """

        if confidence is None:
            confidence = [95, 99, 99.9]

        # get seed for random state
        seed = np.random.randint(0, 1000)

        # assemble spectral powers for null models (random subsamples)
        null_ps = lomb_scargle_bootstrap(t,
                                         y,
                                         dy,
                                         omegas,
                                         generalized=True,
                                         N_bootstraps=nbootstraps,
                                         random_state=seed)

        # compute significance thresholds
        thresholds = {c: np.percentile(null_ps, c) for c in confidence}

        return thresholds
def get_period_sigf(jd, mag, mag_e):  #parameters: time, mag, mag error
    omega = frequency_grid(0.1, 1850)  # grid of frequencies
    p = lomb_scargle(
        jd, mag, mag_e, omega,
        generalized=True)  # Lomb-Scargle power associated to omega
    peak = max(p)  #power associated with best_period
    best_period = LS_peak_to_period(omega,
                                    p)  #estimates a period from periodogram

    # Get significance via bootstrap
    D = lomb_scargle_bootstrap(jd,
                               mag,
                               mag_e,
                               omega,
                               generalized=True,
                               N_bootstraps=1000,
                               random_state=0)
    sig1, sig5 = np.percentile(
        D, [99, 95])  # 95% and 99% confidence, to compare with peak

    return best_period, peak, sig5, sig1
    omega = np.linspace(17, 22, 1000)

    # Notice the typo: we used y rather than y_obs
    if typo is True:
        P_S = lomb_scargle(t, y, dy, omega, generalized=False)
        P_G = lomb_scargle(t, y, dy, omega, generalized=True)
    else:
        P_S = lomb_scargle(t, y_obs, dy, omega, generalized=False)
        P_G = lomb_scargle(t, y_obs, dy, omega, generalized=True)

    #------------------------------------------------------------
    # Get significance via bootstrap
    D = lomb_scargle_bootstrap(t,
                               y_obs,
                               dy,
                               omega,
                               generalized=True,
                               N_bootstraps=1000,
                               random_state=0)
    sig1, sig5 = np.percentile(D, [99, 95])

    #------------------------------------------------------------
    # Plot the results
    fig = plt.figure(figsize=(5, 3.75))

    # First panel: input data
    ax = fig.add_subplot(211)
    ax.errorbar(t, y_obs, dy, fmt='.k', lw=1, ecolor='gray')
    ax.plot([-2, 32], [10, 10], ':k', lw=1)

    ax.set_xlim(-2, 32)
Exemple #4
0
P = 0.3

t = np.random.randint(100, size=N) + 0.3 + 0.4 * np.random.random(N)
y = 10 + np.sin(2 * np.pi * t / P)
dy = 0.5 + 0.5 * np.random.random(N)
y_obs = np.random.normal(y, dy)

#------------------------------------------------------------
# Compute periodogram
period = 10 ** np.linspace(-1, 0, 10000)
omega = 2 * np.pi / period
PS = lomb_scargle(t, y_obs, dy, omega, generalized=True)

#------------------------------------------------------------
# Get significance via bootstrap
D = lomb_scargle_bootstrap(t, y_obs, dy, omega, generalized=True,
                           N_bootstraps=1000, random_state=0)
sig1, sig5 = np.percentile(D, [99, 95])

#------------------------------------------------------------
# Plot the results
fig = plt.figure()
fig.subplots_adjust(left=0.1, right=0.9, hspace=0.25)

# First panel: the data
ax = fig.add_subplot(211)
ax.errorbar(t, y_obs, dy, fmt='.k', lw=1, ecolor='gray')
ax.set_xlabel('time (days)')
ax.set_ylabel('flux')
ax.set_xlim(-5, 105)

# Second panel: the periodogram & significance levels
Exemple #5
0
        # compute upper flux limit and plot as arrow or triangle
        upperlim2 = np.append(upperlim2, 
                              zp2[i] - 2.5 * np.log10(snu * sigflux2[i]))
        upperlim2date = np.append(upperlim2date, mjd1[i])
        
#------------------------------------------------------------
# Compute periodogram
period = np.linspace(1, 50, 100000)
omega = 2 * np.pi / period
#PS = lomb_scargle(t, y_obs, dy, omega, generalized=True)

PS = lomb_scargle(mag1date, mag1, mag1sig, omega, generalized = True)

#------------------------------------------------------------
# Get significance via bootstrap
D = lomb_scargle_bootstrap(mag1date, mag1, mag1sig, omega, generalized = True,
                           N_bootstraps=500, random_state=0)
sig1, sig5 = np.percentile(D, [99, 95])

#------------------------------------------------------------
# Plot the results
fig = plt.figure(figsize=(5, 3.75))
fig.subplots_adjust(left=0.1, right=0.9, hspace=0.25)

# First panel: the data
ax = fig.add_subplot(211)
ax.errorbar(mag1date, mag1, mag1sig, fmt='.k', lw=1, ecolor='gray')
ax.set_xlabel('time (days)')
ax.set_ylabel('flux')
ax.set_xlim(mag1date[0] - 50, mag1date[-1] + 50)
ax.set_ylim(16, max(mag1) + 0.5)