ax[0].errorbar(phase[mask], mag[mask], dmag[mask], fmt='o', color='#666666') ax[0].errorbar(phase[~mask], mag[~mask], dmag[~mask], fmt='o', color='#CCCCCC') ax[0].invert_yaxis() for fit_offset in [False, True]: i = int(fit_offset) model = LombScargle(fit_offset=fit_offset).fit(t[mask], mag[mask], dmag[mask]) P = model.periodogram(periods) if fit_offset: label = 'floating mean' else: label = 'standard' lines = ax[0].plot(phasefit, model.predict(tfit, period=rrlyrae.period), label=label) ax[1 + i].plot(periods, P, lw=1, c=lines[0].get_color()) ax[1 + i].set_title('{0} Periodogram'.format(label.title())) ax[1 + i].set_ylabel('power') ax[1 + i].set_ylim(0, 1) ax[1 + i].set_xlim(0.2, 1.4) ax[0].legend(loc='upper left') ax[0].set_xlabel('phase') ax[0].set_ylabel('magnitude') ax[0].set_title('Phased data (period=0.622 days)') ax[1].xaxis.set_major_formatter(plt.NullFormatter()) ax[2].set_xlabel('Period (days)')
fig.add_subplot(gs[0, 1])] # Plot the data ax[0].errorbar(t, mag, dmag, fmt='o', color='#333333') ax[1].errorbar(phase, mag, dmag, fmt='.', color='#888888') # Fit and plot the model model = LombScargle().fit(t, mag, dmag) model.optimizer.period_range = (0.2, 1.2) phase = (t / model.best_period) % 1 phasefit = np.linspace(0, 1, 1000) tfit = model.best_period * phasefit lines = ax[2].plot(periods, model.periodogram(periods), lw=1) ax[1].plot(phasefit, model.predict(tfit), c=lines[0].get_color()) ax[1].invert_yaxis() ax[0].set_xlabel('date of observation (MJD)') ax[0].set_ylabel('magnitude') ax[0].set_title('Input Data') ax[0].invert_yaxis() ax[1].set_title('Folded Data (P={0:.3f} days)'.format(rrlyrae.period)) ax[1].set_xlabel('phase') ax[1].yaxis.set_major_locator(plt.MultipleLocator(0.2)) ax[2].set_title('Periodogram') ax[2].set_xlabel('period (days)') ax[2].set_ylabel('power')
for i in range(2): fig, ax = plt.subplots(2, 2, figsize=(10, 4), sharex='col') fig.subplots_adjust(left=0.07, right=0.95, wspace=0.1, bottom=0.15) 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))
plot_data(ax) ax.set_title('Input Data') plt.savefig('buildup_1.png') # Plot the base model fig, ax = plt.subplots() plot_data(ax) t_all = np.ravel(t * np.ones_like(mags)) mags_all = np.ravel(mags) dy_all = np.ravel(dy * np.ones_like(mags)) basemodel = LombScargle(Nterms=2).fit(t_all, mags_all, dy_all) period = rrlyrae.period tfit = np.linspace(0, period, 1000) base_fit = basemodel.predict(tfit, period=period) ax.plot(tfit / period, base_fit, color='black', lw=5, alpha=0.5) ax.set_title('2-term Base Model') # Plot the band-by-band augmentation multimodel = LombScargleMultiband(Nterms_base=2, Nterms_band=1) t1, y1, dy1, f1 = map(np.ravel, np.broadcast_arrays(t, mags, dy, filts[:, None])) multimodel.fit(t1, y1, dy1, f1) yfits = multimodel.predict(tfit, filts=filts[:, None], period=period) plt.savefig('buildup_2.png') fig, ax = plt.subplots()
color='#666666') ax[0].errorbar(phase[~mask], mag[~mask], dmag[~mask], fmt='o', color='#CCCCCC') ax[0].invert_yaxis() for fit_offset in [False, True]: i = int(fit_offset) model = LombScargle(fit_offset=fit_offset).fit(t[mask], mag[mask], dmag[mask]) P = model.periodogram(periods) if fit_offset: label = 'floating mean' else: label = 'standard' lines = ax[0].plot(phasefit, model.predict(tfit, period=rrlyrae.period), label=label) ax[1 + i].plot(periods, P, lw=1, c=lines[0].get_color()) ax[1 + i].set_title('{0} Periodogram'.format(label.title())) ax[1 + i].set_ylabel('power') ax[1 + i].set_ylim(0, 1) ax[1 + i].set_xlim(0.2, 1.4) ax[0].legend(loc='upper left') ax[0].set_xlabel('phase') ax[0].set_ylabel('magnitude') ax[0].set_title('Phased data (period=0.622 days)') ax[1].xaxis.set_major_formatter(plt.NullFormatter()) ax[2].set_xlabel('Period (days)')
# Plot the data ax[0].errorbar(phase, mag, dmag, fmt='o', color='#AAAAAA') # Plot the fits for i, Nterms in enumerate(models): model = LombScargle(Nterms=Nterms).fit(t, mag, dmag) P = model.periodogram(periods) label = "{0} terms".format(Nterms) if Nterms == 1: label = label[:-1] alpha = 1.0 if (Nterms < 20) else 0.5 lines = ax[0].plot(phasefit, model.predict(tfit, period=rrlyrae.period), label=label, alpha=alpha) ax[1 + i].plot(periods, model.periodogram(periods), color=lines[0].get_color(), lw=1) ax[1 + i].set_title("{0}-term Periodogram".format(Nterms)) ax[1 + i].set_xlim(0.2, 1.4) ax[1 + i].set_ylim(0, 1) ax[2].set_ylabel('power') ax[3].set_xlabel('period (days)') for i in [1, 2]: ax[i].xaxis.set_major_formatter(plt.NullFormatter()) ax[0].set_xlabel('phase') ax[0].set_ylabel('magnitude')
] # Plot the data ax[0].errorbar(t, mag, dmag, fmt='o', color='#333333') ax[1].errorbar(phase, mag, dmag, fmt='.', color='#888888') # Fit and plot the model model = LombScargle().fit(t, mag, dmag) model.optimizer.period_range = (0.2, 1.2) phase = (t / model.best_period) % 1 phasefit = np.linspace(0, 1, 1000) tfit = model.best_period * phasefit lines = ax[2].plot(periods, model.periodogram(periods), lw=1) ax[1].plot(phasefit, model.predict(tfit), c=lines[0].get_color()) ax[1].invert_yaxis() ax[0].set_xlabel('date of observation (MJD)') ax[0].set_ylabel('magnitude') ax[0].set_title('Input Data') ax[0].invert_yaxis() ax[1].set_title('Folded Data (P={0:.3f} days)'.format(rrlyrae.period)) ax[1].set_xlabel('phase') ax[1].yaxis.set_major_locator(plt.MultipleLocator(0.2)) ax[2].set_title('Periodogram') ax[2].set_xlabel('period (days)') ax[2].set_ylabel('power') ax[2].set_xlim(0.2, 1.4)