Example #1
0
def townsend_lombscargle_value(times, mags, omega):
    '''
    This calculates the periodogram value for each omega (= 2*pi*f). Mags must
    be normalized to zero with variance scaled to unity.

    '''
    cos_omegat = npcos(omega * times)
    sin_omegat = npsin(omega * times)

    xc = npsum(mags * cos_omegat)
    xs = npsum(mags * sin_omegat)

    cc = npsum(cos_omegat * cos_omegat)
    ss = npsum(sin_omegat * sin_omegat)

    cs = npsum(cos_omegat * sin_omegat)

    tau = nparctan(2 * cs / (cc - ss)) / (2 * omega)

    ctau = npcos(omega * tau)
    stau = npsin(omega * tau)

    leftsumtop = (ctau * xc + stau * xs) * (ctau * xc + stau * xs)
    leftsumbot = ctau * ctau * cc + 2.0 * ctau * stau * cs + stau * stau * ss
    leftsum = leftsumtop / leftsumbot

    rightsumtop = (ctau * xs - stau * xc) * (ctau * xs - stau * xc)
    rightsumbot = ctau * ctau * ss - 2.0 * ctau * stau * cs + stau * stau * cc
    rightsum = rightsumtop / rightsumbot

    pval = 0.5 * (leftsum + rightsum)

    return pval
Example #2
0
def specwindow_lsp_value(times, mags, errs, omega):
    '''
    This calculates the peak associated with the spectral window function
    for times and at the specified omega.

    '''

    norm_times = times - times.min()

    tau = ((1.0 / (2.0 * omega)) * nparctan(
        npsum(npsin(2.0 * omega * norm_times)) /
        npsum(npcos(2.0 * omega * norm_times))))

    lspval_top_cos = (npsum(1.0 * npcos(omega * (norm_times - tau))) *
                      npsum(1.0 * npcos(omega * (norm_times - tau))))
    lspval_bot_cos = npsum((npcos(omega * (norm_times - tau))) *
                           (npcos(omega * (norm_times - tau))))

    lspval_top_sin = (npsum(1.0 * npsin(omega * (norm_times - tau))) *
                      npsum(1.0 * npsin(omega * (norm_times - tau))))
    lspval_bot_sin = npsum((npsin(omega * (norm_times - tau))) *
                           (npsin(omega * (norm_times - tau))))

    lspval = 0.5 * ((lspval_top_cos / lspval_bot_cos) +
                    (lspval_top_sin / lspval_bot_sin))

    return lspval
Example #3
0
def specwindow_lsp_value(times, mags, errs, omega):
    '''This calculates the peak associated with the spectral window function
    for times and at the specified omega.

    NOTE: this is classical Lomb-Scargle, not the Generalized
    Lomb-Scargle. `mags` and `errs` are silently ignored since we're calculating
    the periodogram of the observing window function. These are kept to present
    a consistent external API so the `pgen_lsp` function below can call this
    transparently.

    Parameters
    ----------

    times,mags,errs : np.array
        The time-series to calculate the periodogram value for.

    omega : float
        The frequency to calculate the periodogram value at.

    Returns
    -------

    periodogramvalue : float
        The normalized periodogram at the specified test frequency `omega`.

    '''

    norm_times = times - times.min()

    tau = ((1.0 / (2.0 * omega)) * nparctan(
        npsum(npsin(2.0 * omega * norm_times)) /
        npsum(npcos(2.0 * omega * norm_times))))

    lspval_top_cos = (npsum(1.0 * npcos(omega * (norm_times - tau))) *
                      npsum(1.0 * npcos(omega * (norm_times - tau))))
    lspval_bot_cos = npsum((npcos(omega * (norm_times - tau))) *
                           (npcos(omega * (norm_times - tau))))

    lspval_top_sin = (npsum(1.0 * npsin(omega * (norm_times - tau))) *
                      npsum(1.0 * npsin(omega * (norm_times - tau))))
    lspval_bot_sin = npsum((npsin(omega * (norm_times - tau))) *
                           (npsin(omega * (norm_times - tau))))

    lspval = 0.5 * ((lspval_top_cos / lspval_bot_cos) +
                    (lspval_top_sin / lspval_bot_sin))

    return lspval
Example #4
0
def generalized_lsp_value(times, mags, errs, omega):
    '''Generalized LSP value for a single omega.

    P(w) = (1/YY) * (YC*YC/CC + YS*YS/SS)

    where: YC, YS, CC, and SS are all calculated at T

    and where: tan 2omegaT = 2*CS/(CC - SS)

    and where:

    Y = sum( w_i*y_i )
    C = sum( w_i*cos(wT_i) )
    S = sum( w_i*sin(wT_i) )

    YY = sum( w_i*y_i*y_i ) - Y*Y
    YC = sum( w_i*y_i*cos(wT_i) ) - Y*C
    YS = sum( w_i*y_i*sin(wT_i) ) - Y*S

    CpC = sum( w_i*cos(w_T_i)*cos(w_T_i) )
    CC = CpC - C*C
    SS = (1 - CpC) - S*S
    CS = sum( w_i*cos(w_T_i)*sin(w_T_i) ) - C*S

    '''

    one_over_errs2 = 1.0 / (errs * errs)

    W = npsum(one_over_errs2)
    wi = one_over_errs2 / W

    sin_omegat = npsin(omega * times)
    cos_omegat = npcos(omega * times)

    sin2_omegat = sin_omegat * sin_omegat
    cos2_omegat = cos_omegat * cos_omegat
    sincos_omegat = sin_omegat * cos_omegat

    # calculate some more sums and terms
    Y = npsum(wi * mags)
    C = npsum(wi * cos_omegat)
    S = npsum(wi * sin_omegat)

    YpY = npsum(wi * mags * mags)

    YpC = npsum(wi * mags * cos_omegat)
    YpS = npsum(wi * mags * sin_omegat)

    CpC = npsum(wi * cos2_omegat)
    # SpS = npsum( wi*sin2_omegat )

    CpS = npsum(wi * sincos_omegat)

    # the final terms
    YY = YpY - Y * Y
    YC = YpC - Y * C
    YS = YpS - Y * S
    CC = CpC - C * C
    SS = 1 - CpC - S * S  # use SpS = 1 - CpC
    CS = CpS - C * S

    # calculate tau
    tan_omega_tau_top = 2.0 * CS
    tan_omega_tau_bottom = CC - SS
    tan_omega_tau = tan_omega_tau_top / tan_omega_tau_bottom
    tau = nparctan(tan_omega_tau / (2.0 * omega))

    periodogramvalue = (YC * YC / CC + YS * YS / SS) / YY

    return periodogramvalue
Example #5
0
def generalized_lsp_value(times, mags, errs, omega):
    '''Generalized LSP value for a single omega.

    P(w) = (1/YY) * (YC*YC/CC + YS*YS/SS)

    where: YC, YS, CC, and SS are all calculated at T

    and where: tan 2omegaT = 2*CS/(CC - SS)

    and where:

    Y = sum( w_i*y_i )
    C = sum( w_i*cos(wT_i) )
    S = sum( w_i*sin(wT_i) )

    YY = sum( w_i*y_i*y_i ) - Y*Y
    YC = sum( w_i*y_i*cos(wT_i) ) - Y*C
    YS = sum( w_i*y_i*sin(wT_i) ) - Y*S

    CpC = sum( w_i*cos(w_T_i)*cos(w_T_i) )
    CC = CpC - C*C
    SS = (1 - CpC) - S*S
    CS = sum( w_i*cos(w_T_i)*sin(w_T_i) ) - C*S

    '''

    one_over_errs2 = 1.0/(errs*errs)

    W = npsum(one_over_errs2)
    wi = one_over_errs2/W

    sin_omegat = npsin(omega*times)
    cos_omegat = npcos(omega*times)

    sin2_omegat = sin_omegat*sin_omegat
    cos2_omegat = cos_omegat*cos_omegat
    sincos_omegat = sin_omegat*cos_omegat

    # calculate some more sums and terms
    Y = npsum( wi*mags )
    C = npsum( wi*cos_omegat )
    S = npsum( wi*sin_omegat )

    YpY = npsum( wi*mags*mags)

    YpC = npsum( wi*mags*cos_omegat )
    YpS = npsum( wi*mags*sin_omegat )

    CpC = npsum( wi*cos2_omegat )
    # SpS = npsum( wi*sin2_omegat )

    CpS = npsum( wi*sincos_omegat )

    # the final terms
    YY = YpY - Y*Y
    YC = YpC - Y*C
    YS = YpS - Y*S
    CC = CpC - C*C
    SS = 1 - CpC - S*S # use SpS = 1 - CpC
    CS = CpS - C*S

    # calculate tau
    tan_omega_tau_top = 2.0*CS
    tan_omega_tau_bottom = CC - SS
    tan_omega_tau = tan_omega_tau_top/tan_omega_tau_bottom
    tau = nparctan(tan_omega_tau/(2.0*omega))

    periodogramvalue = (YC*YC/CC + YS*YS/SS)/YY

    return periodogramvalue
Example #6
0
def generalized_lsp_value(times, mags, errs, omega):
    '''Generalized LSP value for a single omega.

    The relations used are::

        P(w) = (1/YY) * (YC*YC/CC + YS*YS/SS)

        where: YC, YS, CC, and SS are all calculated at T

        and where: tan 2omegaT = 2*CS/(CC - SS)

        and where:

        Y = sum( w_i*y_i )
        C = sum( w_i*cos(wT_i) )
        S = sum( w_i*sin(wT_i) )

        YY = sum( w_i*y_i*y_i ) - Y*Y
        YC = sum( w_i*y_i*cos(wT_i) ) - Y*C
        YS = sum( w_i*y_i*sin(wT_i) ) - Y*S

        CpC = sum( w_i*cos(w_T_i)*cos(w_T_i) )
        CC = CpC - C*C
        SS = (1 - CpC) - S*S
        CS = sum( w_i*cos(w_T_i)*sin(w_T_i) ) - C*S

    Parameters
    ----------

    times,mags,errs : np.array
        The time-series to calculate the periodogram value for.

    omega : float
        The frequency to calculate the periodogram value at.

    Returns
    -------

    periodogramvalue : float
        The normalized periodogram at the specified test frequency `omega`.

    '''

    one_over_errs2 = 1.0 / (errs * errs)

    W = npsum(one_over_errs2)
    wi = one_over_errs2 / W

    sin_omegat = npsin(omega * times)
    cos_omegat = npcos(omega * times)

    sin2_omegat = sin_omegat * sin_omegat
    cos2_omegat = cos_omegat * cos_omegat
    sincos_omegat = sin_omegat * cos_omegat

    # calculate some more sums and terms
    Y = npsum(wi * mags)
    C = npsum(wi * cos_omegat)
    S = npsum(wi * sin_omegat)

    CpS = npsum(wi * sincos_omegat)
    CpC = npsum(wi * cos2_omegat)
    CS = CpS - C * S
    CC = CpC - C * C
    SS = 1 - CpC - S * S  # use SpS = 1 - CpC

    # calculate tau
    tan_omega_tau_top = 2.0 * CS
    tan_omega_tau_bottom = CC - SS
    tan_omega_tau = tan_omega_tau_top / tan_omega_tau_bottom
    tau = nparctan(tan_omega_tau) / (2.0 * omega)

    YpY = npsum(wi * mags * mags)

    YpC = npsum(wi * mags * cos_omegat)
    YpS = npsum(wi * mags * sin_omegat)

    # SpS = npsum( wi*sin2_omegat )

    # the final terms
    YY = YpY - Y * Y
    YC = YpC - Y * C
    YS = YpS - Y * S

    periodogramvalue = (YC * YC / CC + YS * YS / SS) / YY

    return periodogramvalue