コード例 #1
0
def measure_period(ticid, t, corrected_y, yerr):

    print("Measure the rotation period...")
    rotate = ss.RotationModel(t, corrected_y, yerr)
    ls_period = rotate.ls_rotation()
    acf_period = rotate.acf_rotation(interval=0.00138889,
                                     cutoff=1.5,
                                     window_length=1999)

    period_grid = np.arange(.5, 3 * ls_period, 30. / 1000.)
    if ls_period > 10:
        period_grid = np.linspace(.5, 30, 1000.)
    pdm_period = rotate.pdm_rotation(period_grid)

    # Make the figure
    fig = rotate.big_plot(methods=["pdm", "acf", "ls"],
                          xlim=(0, 100),
                          method_xlim=(-1, 50))
    rvar = np.log10(rotate.Rvar * 1e6)
    print("log10(Rvar) = ", rvar, "ppm")
    plt.title("log10(Rvar) = {0:.2f}".format(rvar), fontsize=20)
    fig.savefig("plots/{}_plot".format(ticid))

    # Get peak heights
    ls_peak_pos, ls_peak_height = rt.get_peak_statistics(
        1. / rotate.freq, rotate.power)
    acf_peak_pos, acf_peak_height = rt.get_peak_statistics(
        rotate.lags, rotate.acf)
    pdm_peak_pos, pdm_peak_height = rt.get_peak_statistics(
        rotate.phase, -rotate.phis)


    return rvar, ls_period, acf_period, pdm_period[0], pdm_period[1], \
        ls_peak_height[:3], ls_peak_pos[:3], acf_peak_height[:3], \
        acf_peak_pos[:3], pdm_peak_height[:3], pdm_peak_pos[:3]
コード例 #2
0
ファイル: check_code.py プロジェクト: RuthAngus/kepler_ages
def make_rotation_plots(time, flux, flux_err, interval=0.02043365,
                        period_grid=np.linspace(1, 50, 2000)):
    rotate = ss.RotationModel(time, flux, flux_err)
    ls_period = rotate.ls_rotation()
    acf_period = rotate.acf_rotation(interval)
    # pdm_period, period_err = rotate.pdm_rotation(rotate.lags, pdm_nbins=10)
    pdm_period, period_err = rotate.pdm_rotation(period_grid, pdm_nbins=10)
    fig = rotate.big_plot()
    return ls_period, acf_period, pdm_period, period_err, fig
コード例 #3
0
def test_rvar():
    time = np.linspace(0, 100, 1000)
    p = 10
    w = 2*np.pi/p
    flux = np.sin(w*time)
    flux_err = np.ones_like(flux)*1e-2
    star = ss.RotationModel(time, flux, flux_err)
    Rvar = star.calc_Rvar()
    total_range = max(flux) - min(flux)
    assert np.isclose(Rvar, total_range, atol=.1)
コード例 #4
0
ファイル: test_starspot.py プロジェクト: RuthAngus/starspot
def test_big_plot():
    # Generate some data
    time = np.linspace(0, 100, 1000)
    p = 10
    w = 2 * np.pi / p
    flux = np.sin(w * time) + np.random.randn(len(time)) * 1e-2
    flux_err = np.ones_like(flux) * 1e-2

    rotate = ss.RotationModel(time, flux, flux_err)
    ls_period = rotate.ls_rotation()
    acf_period = rotate.acf_rotation(interval=0.02043365)
    pdm_period, period_err = rotate.pdm_rotation(rotate.lags, pdm_nbins=10)
コード例 #5
0
def test_run():

    starname = "TIC 10863087"
    lcf = lk.search_lightcurvefile(starname).download()
    lc = lcf.PDCSAP_FLUX
    no_nan_lc = lc.remove_nans()
    clipped_lc = no_nan_lc.remove_outliers(sigma=3)
    clipped_lc.scatter(alpha=.5, s=.5)

    rotate = ss.RotationModel(clipped_lc.time, clipped_lc.flux,
                              clipped_lc.flux_err)
    rotate.lc_plot()
    ls_period = rotate.ls_rotation()
    rotate.ls_plot()
    tess_cadence = 1. / 24. / 30.  # This is a TESS 2 minute cadence star.
    acf_period = rotate.acf_rotation(tess_cadence)
    rotate.acf_plot()

    period_grid = np.linspace(.1, 2, 1000)
    pdm_period, period_err = rotate.pdm_rotation(period_grid, pdm_nbins=10)
    print(pdm_period, period_err)

    rotate.pdm_plot()

    # Lomb-Scargle periodogram
    period_array = 1. / rotate.freq
    power_array = rotate.power

    # Autocorrelation function
    ACF_array = rotate.acf
    lag_array = rotate.lags

    # Phase-dispersion minimization
    phi_array = rotate.phis  # The 'dispersion' plotted in the lower panel above.
    period_grid = period_grid  # We already defined this above.

    # Get peak positions and heights, in order of highest to lowest peak.
    peak_positions, peak_heights = rt.get_peak_statistics(
        1. / rotate.freq, rotate.power)
    print(peak_positions[0])

    # Get peak positions and heights, in order of highest to lowest peak.
    acf_peak_positions, acf_peak_heights = rt.get_peak_statistics(
        rotate.lags, rotate.acf, sort_by="height")
    print(acf_peak_positions[0])

    # Get peak positions and heights, in order of lags.
    acf_peak_positions, acf_peak_heights = rt.get_peak_statistics(
        rotate.lags, rotate.acf, sort_by="position")
    print(acf_peak_positions[0])
コード例 #6
0
ファイル: test_starspot.py プロジェクト: RuthAngus/starspot
def test_acf():
    time = np.linspace(0, 100, 1000)
    p = 10
    w = 2 * np.pi / p
    flux = np.sin(w * time) + np.random.randn(len(time)) * 1e-2
    flux_err = np.ones_like(flux) * 1e-2
    rotate = ss.RotationModel(time, flux, flux_err)
    acf_period = rotate.acf_rotation(interval=0.02043365)
    assert np.isclose(acf_period, 10, atol=1)

    acf_period = rotate.acf_rotation(interval=0.02043365, cutoff=1)
    assert np.isclose(acf_period, 10, atol=1)
    filtered_acf = rotate.acf

    acf_period = rotate.acf_rotation(interval=0.02043365,
                                     cutoff=1,
                                     window_length=None)
    unfiltered_acf = rotate.acf
    assert np.isclose(acf_period, 10, atol=1)
コード例 #7
0
def test_big_plot():
    # Generate some data
    time = np.linspace(0, 100, 1000)
    p = 10
    w = 2*np.pi/p
    flux = np.sin(w*time) + np.random.randn(len(time))*1e-2
    flux_err = np.ones_like(flux)*1e-2

    rotate = ss.RotationModel(time, flux, flux_err)
    ls_period = rotate.ls_rotation()
    acf_period = rotate.acf_rotation(interval=0.02043365)
    pdm_period, period_err = rotate.pdm_rotation(rotate.lags, pdm_nbins=10)

    fig1 = rotate.big_plot()
    fig1.savefig("big_plot_test")

    fig2 = rotate.big_plot(methods=["ls", "acf"])
    fig2.savefig("big_plot_test2")

    fig3 = rotate.big_plot(methods=["ls", "acf", "pdm"])
    fig3.savefig("big_plot_test3")
コード例 #8
0
ファイル: PDM_test.py プロジェクト: ernewton/starspot
def test_uncertainty():

    # Generate some data
    np.random.seed(42)
    t = np.linspace(0, 100, 1000)
    p = 10
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2

    rm = ss.RotationModel(t, x, xerr)
    nperiods = 200
    period_grid = np.linspace(1, 20, nperiods)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test")

    # 2 day period
    np.random.seed(42)
    p = 2
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2
    period_grid = np.linspace(.1, 5, nperiods)
    rm = ss.RotationModel(t, x, xerr)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test_2")

    # 5 day period
    np.random.seed(42)
    p = 5
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2
    period_grid = np.linspace(.1, 10, nperiods)
    rm = ss.RotationModel(t, x, xerr)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test_5")

    # 20 day period
    p = 20
    np.random.seed(42)
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2
    period_grid = np.linspace(5, 30, nperiods)
    rm = ss.RotationModel(t, x, xerr)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test_20")

    # 50 day period
    np.random.seed(42)
    t = np.linspace(0, 100, 1000)
    p = 50
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2
    period_grid = 10**np.linspace(0, np.log10(200), nperiods)
    rm = ss.RotationModel(t, x, xerr)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test_50")

    # 100 day period
    np.random.seed(42)
    p = 100
    w = 2 * np.pi / p
    x = np.sin(w * t) + np.random.randn(len(t)) * 1e-2
    xerr = np.ones_like(x) * 1e-2
    period_grid = 10**np.linspace(0, np.log10(200), nperiods)
    rm = ss.RotationModel(t, x, xerr)
    pdm_period, period_err = rm.pdm_rotation(period_grid)
    print(pdm_period, period_err)
    fig = rm.pdm_plot()
    plt.savefig("pdm_test_100")
コード例 #9
0
df = pd.read_csv("../kepler_stars_in_14_and_15.csv")
N = 4

cpm_periods = np.zeros(len(df))
for i, ticid in enumerate(df.TIC.values[:N]):
    print("Measuring period for", ticid)

    if os.path.exists("../data/{}_lc.csv".format(ticid)):
        lc = pd.read_csv("../data/{}_lc.csv".format(ticid))
        time, flux, flux_err = lc.time * 1, lc.flux * 1, lc.flux_err * 1

        # Take off a straight line
        p = np.polyfit(time, flux, 2)
        flux -= np.polyval(p, time)

        star = ss.RotationModel(time, flux, flux_err)
        ls_period = star.ls_rotation(max_period=50)
        cpm_periods[i] = ls_period

        fig = star.big_plot(["ls"], method_xlim=(0, 50))
        fig.savefig("plots/{}_bigplot".format(ticid))
        plt.close()
    else:
        print("No light curve found")

xs = np.linspace(min(df.Prot.values[:N]), max(df.Prot.values[:N]), 100)
plt.plot(df.Prot.values[:N], cpm_periods[:N], ".")
plt.plot(xs, xs)
plt.savefig("kepler_period_comparison")

df["cpm_period"] = np.array(cpm_periods)