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
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
def do_bls(self): """ """ self.bls_time = self.time[30:-20] self.bls_flux = self.det_flux[30:-20] durations = np.linspace(0.05, 0.2, 10) bls_model = BLS(self.bls_time, self.bls_flux) bls_results = bls_model.autopower(durations, frequency_factor=5.0) self.bls_results = bls_results index = np.argmax(bls_results.power) bls_period = bls_results.period[index] bls_t0 = bls_results.transit_time[index] bls_duration = bls_results.duration[index] bls_depth = bls_results.depth[index] self.bls_model = bls_model self.bls_period = bls_period self.bls_t0 = bls_t0 self.bls_depth = bls_depth self.bls_duration = bls_duration
'{} LombScargle Periodogram for original lc'.format(target_ID)) #ls_plot.show(block=True) ls_fig.savefig(save_path + '{} - Lomb-Sacrgle Periodogram for original lc.png'. format(target_ID)) plt.close(ls_fig) i = np.argmax(power) freq_rot = freq[i] p_rot = 1 / freq_rot print('Rotation Period = {:.3f}d'.format(p_rot)) # From BLS durations = np.linspace(0.05, 0.2, 100) * u.day #model = BoxLeastSquares(lc_30min.time*u.day, normalized_flux) model = BLS(lc_30min.time * u.day, normalized_flux) results = model.autopower(durations, frequency_factor=5.0) rot_index = np.argmax(results.power) rot_period = results.period[rot_index] rot_t0 = results.transit_time[rot_index] print("Rotation Period from BLS of original = {}d".format(rot_period)) ########################### batman stuff ###################################### # type_of_planet = 'Hot Jupiter' # stellar_type = 'F or G' #params = batman.TransitParams() #object to store transit parameters #print("batman works y'all") #params.t0 = -4.5 #time of inferior conjunction #params.per = 8.0 #orbital period (days) - try 0.5, 1, 2, 4, 8 & 10d periods # Change for type of star #params.rp = 0.05 #planet radius (in units of stellar radii) - Try between 0.01 and 0.1 (F/G) or 0.025 to 0.18 (K/M) # For a: 25 for 10d; 17 for 8d; 10 for 4d; 4-8 (6) for 2 day; 2-5 for 1d; 1-3 (or 8?) for 0.5d
t_cut = lc_30min.time[~near_peak_or_trough] flux_cut = combined_flux[~near_peak_or_trough] flux_err_cut = lc_30min.flux_err[~near_peak_or_trough] # flux = combined_flux # frequency, power = LombScargle(lc_30min.time, flux).autopower() # plt.plot(frequency, power) # i = np.argmax(power) # freq_rot = frequency[i] # p_rot = 1/freq_rot durations = np.linspace(0.05, 0.2, 22) * u.day model = BLS(lc_30min.time*u.day, combined_flux) # model = BLS(lc_30min.time*u.day, BLS_flux) results = model.autopower(durations, frequency_factor=5.0) # Find the period and epoch of the peak rot_index = np.argmax(results.power) rot_period = results.period[rot_index] rot_t0 = results.transit_time[rot_index] ## p_rot = 3.933 # AB Pic ## p_rot = 3.6 # HIP 1113 ## p_rot = 4.36 # HIP 1993 ## p_rot = 3.405 # HIP 105388 ## p_rot = 3.9 # HIP 32235 ## p_rot = 2.67 # AO Men ## p_rot = 0.57045 # 2 MASS J23261069-7323498 ## p_rot = 4.425 # 2 MASS J22428896-7142211 # p_rot = 2.95 # HIP 116748 AB