예제 #1
0
def boxleastsq(BJD, flux, mindur=0.5, maxdur=10.0):
    '''
	Box least squares module that uses bls.py from:
		https://github.com/dfm/bls.py

	Input:
		BJD     : array  - barycentric julian dates.
		flux    : array  - the normalized flux.
		mindur  : float  - the minimum duration of the transist.
		maxdur  : float  - the maximum duration of the transist.

	Output:
		BLSdict : dict   - dictionary containing period, mid transit time, transit duration, transit
						   depth, and the error on the depth.
		results : object - the results from the BLS.
	'''

    ## BOX LEASTSQUARE
    durations = np.linspace(mindur, maxdur, 10) * u.hour
    model = BLS(BJD * u.day, flux)
    results = model.autopower(durations,
                              minimum_n_transit=2,
                              frequency_factor=5.0)

    period = results.period[np.argmax(results.power)].value
    t0 = results.transit_time[np.argmax(results.power)].value
    dur = results.duration[np.argmax(results.power)].value
    dep = results.depth[np.argmax(results.power)]
    errdep = results.depth_err[np.argmax(results.power)]

    dep_even = model.compute_stats(period, dur, t0)['depth_even'][0]
    dep_odd = model.compute_stats(period, dur, t0)['depth_odd'][0]

    BLSdict = {
        'period': period,
        'midtransit_time': t0,
        'duration': dur,
        'depth': dep,
        'errdepth': errdep,
        'depth_even': dep_even,
        'depth_odd': dep_odd
    }

    return BLSdict, results
예제 #2
0
def bls_search(lc, target_ID, save_path):
    """
    Perform bls analysis using foreman-mackey's bls.py function
    """
    durations = np.linspace(0.05, 0.2, 22) * u.day
    model = BLS(lc.time * u.day, lc.flux)
    results = model.autopower(durations, frequency_factor=5.0)

    # Find the period and epoch of the peak
    index = np.argmax(results.power)
    period = results.period[index]
    t0 = results.transit_time[index]
    duration = results.duration[index]
    transit_info = model.compute_stats(period, duration, t0)

    epoch = transit_info['transit_times'][0]

    fig, ax = plt.subplots(1, 1, figsize=(8, 4))

    # Highlight the harmonics of the peak period
    ax.axvline(period.value, alpha=0.4, lw=3)
    for n in range(2, 10):
        ax.axvline(n * period.value, alpha=0.4, lw=1, linestyle="dashed")
        ax.axvline(period.value / n, alpha=0.4, lw=1, linestyle="dashed")

    # Plot the periodogram
    ax.plot(results.period, results.power, "k", lw=0.5)

    ax.set_xlim(results.period.min().value, results.period.max().value)
    ax.set_xlabel("period [days]")
    ax.set_ylabel("log likelihood")
    ax.set_title('{} - BLS Periodogram'.format(target_ID))
    #plt.savefig(save_path + '{} - BLS Periodogram.png'.format(target_ID))
    #    plt.close(fig)

    # Fold by most significant period
    phase_fold_plot(lc.time * u.day,
                    lc.flux,
                    period,
                    epoch,
                    target_ID,
                    save_path,
                    title='{} Lightcurve folded by {} days'.format(
                        target_ID, period))

    return results, transit_info
예제 #3
0
            BLS_flux = flatten_lc_after
        else:
            BLS_flux = combined_flux
        #model = BoxLeastSquares(t_cut*u.day, BLS_flux)
        model = BLS(lc_30min.time * u.day, BLS_flux)
        results = model.autopower(durations,
                                  minimum_n_transit=3,
                                  frequency_factor=5.0)

        # Find the period and epoch of the peak
        index = np.argmax(results.power)
        period = results.period[index]
        #print(results.period)
        t0 = results.transit_time[index]
        duration = results.duration[index]
        transit_info = model.compute_stats(period, duration, t0)
        print(transit_info)

        #epoch = transit_info['transit_times'][0]

        #    periodogram_fig, ax = plt.subplots(1, 1, figsize=(8, 4))
        periodogram_fig, ax = plt.subplots(1, 1)

        # Highlight the harmonics of the peak period
        ax.axvline(period.value, alpha=0.4, lw=3)
        for n in range(2, 10):
            ax.axvline(n * period.value, alpha=0.4, lw=1, linestyle="dashed")
            ax.axvline(period.value / n, alpha=0.4, lw=1, linestyle="dashed")

        # Plot and save the periodogram
        ax.plot(results.period, results.power, "k", lw=0.5)