In [1]:
from __future__ import print_function, division
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
# Use seaborn plot style defaults
import seaborn; seaborn.set()
In [2]:
# imports are from up one directory
import sys; import os; sys.path.append(os.path.abspath('..'))
from multiband_LS.data import fetch_rrlyrae
rrlyrae = fetch_rrlyrae()
lcids = np.fromiter(rrlyrae.ids, dtype=int)
Let's plot the first set of light curves
In [3]:
t, y, dy, filts = rrlyrae.get_lightcurve(lcids[0], return_1d=True)
for i, filt in enumerate('ugriz'):
mask = (filts == filt)
plt.errorbar(t[mask], y[mask], dy[mask], fmt='o', label=filt)
plt.gca().invert_yaxis()
plt.legend(ncol=3, loc='upper left', fontsize=12)
plt.xlabel('observation date'); plt.ylabel('magnitude');
In [4]:
from multiband_LS import LombScargleMultibandFast
model = LombScargleMultibandFast()
model.optimizer.period_range = (0.4, 0.8)
model.fit(t, y, dy, filts)
Out[4]:
Let's find the best period:
In [5]:
print("best period: {0:.4f}".format(model.best_period))
Let's zoom-in around this best value:
In [6]:
periods = np.linspace(model.best_period - 0.01,
model.best_period + 0.01, 1000)
P = model.periodogram(periods)
plt.plot(periods, P);
Now given this optimal period, we can plot the folded light curves along with the model fit:
In [7]:
def plot_folded(model):
tfit = np.linspace(0, model.best_period, 100)[:, None]
yfits = model.predict(tfit, filts=['u', 'g', 'r', 'i', 'z'])
colors = plt.rcParams['axes.color_cycle']
for i, (color, filt) in enumerate(zip(colors[:5], 'ugriz')):
mask = (filts == filt)
plt.errorbar(t[mask] % model.best_period, y[mask], dy[mask], fmt='o', c=color)
plt.plot(tfit, yfits[:, i], '-', c=color, alpha=0.6, label=filts[i])
plt.gca().invert_yaxis()
plt.legend()
plot_folded(model)
From this model, we can plot the trend in color-color space as a function of phase:
In [8]:
def plot_color_mag(model):
tfit = np.linspace(0, model.best_period, 100)[:, None]
yfits = model.predict(tfit, filts=['u', 'g', 'r', 'i', 'z'])
g, dg = y[filts == 'g'], dy[filts == 'g']
r, dr = y[filts == 'r'], dy[filts == 'r']
dgr = np.sqrt(dg ** 2 + dr ** 2)
gfit = yfits[:, 1]
rfit = yfits[:, 2]
plt.errorbar(g - r, r, yerr=dg, xerr=dgr, fmt='o')
plt.plot(gfit - rfit, rfit, '-k', alpha=0.7)
plt.xlabel('g - r'); plt.ylabel('r');
plot_color_mag(model)
This can also be repeated with a multi-term truncated Fourier series. Let's do four terms:
In [9]:
model = LombScargleMultibandFast(Nterms=4)
model.optimizer.period_range = (0.6, 0.65)
model.fit(t, y, dy, filts)
Out[9]:
In [10]:
print("best period: {0:.4f} days".format(model.best_period))
In [11]:
plot_folded(model)
In [12]:
plot_color_mag(model)
Here's the more flexible multiband method. Here we can fit a certain number of terms for the base model, and then a certain number of terms for the color offsets. A very light regularization is used to make sure that the models are well-behaved, and to drive the bulk of the variation into the base model.
In [13]:
from multiband_LS import LombScargleMultiband
model = LombScargleMultiband(Nterms_base=4, Nterms_band=2)
model.optimizer.period_range = (0.6, 0.65)
model.fit(t, y, dy, filts)
Out[13]:
In [14]:
print("best period: {0:.4f}".format(model.best_period))
In [15]:
plot_folded(model)
In [16]:
plot_color_mag(model)