def gatspy_period(lc_g): time, mag, error = np.array(lc_g['MJD'].values), np.array(lc_g['MAG_KRON'].values), np.array(lc_g['MAGERR_KRON'].values) per_f = (np.max(time) - np.min(time))*10 periods = np.linspace(.01, per_f, 10000) model = LombScargle(fit_offset=True).fit(time, mag, error) power = model.score(periods) best_per = periods[np.argmax(power)] return best_per
if i == 0: ind = np.arange(Nobs) % 5 y = mags[ind, np.arange(Nobs)] f = np.array(filts)[ind] else: arrs = np.broadcast_arrays(t, mags, dy, filts[:, None]) t, y, dy, f = map(np.ravel, arrs) model1 = LombScargle() model1.fit(t, y, dy) yfit = model1.predict(tfit, period=period) plot_data(ax[0, 0], t, y, dy, f) ax[0, 0].plot(tfit / period, yfit, '-', color='gray', lw=4, alpha=0.5) ax[0, 1].plot(periods, model1.score(periods), color='gray') ax[0, 0].set_xlabel('') model2 = LombScargleMultiband(Nterms_base=1, Nterms_band=1) model2.fit(t, y, dy, f) yfits = model2.predict(tfit, filts=filts[:, None], period=period) plot_data(ax[1, 0], t, y, dy, f) for j in range(5): ax[1, 0].plot(tfit / period, yfits[j]) ax[1, 1].plot(periods, model2.score(periods)) fig.savefig('naive_{0}.png'.format(i + 1)) plt.show()
for ii in range(N_trials): for jj in range(len(W)): # maximum frequency/min period fmax = W[jj]/t.max() # "data" array y = np.random.normal(0, 1.0, t.size) ls = LombScargle().fit(t, y, 1.0) ls.optimizer.quiet = True ls.optimizer.period_range = (1/fmax, t[-1]) chisq_0 = np.var(y) scores[ii, jj] = ls.score(ls.best_period) * chisq_0 * 0.5 * (N_pts-1) # fout = open("output{0}.dat".format(fnum), "w") # for ii in range(N_trials): # fout.write("{0},{1}\n".format(scores[ii,0], scores[ii,1])) # fout.close() # data = data[:100000] # data = scores * (N_pts-1) # qw1 = np.percentile(data.T[0], [75,25]) # qw2 = np.percentile(data.T[1], [75,25]) # qw1 = qw1[0] - qw1[1] # qw2 = qw2[0] - qw2[1]