SuperSmoother Example

This is an example of doing periodic analysis with the SuperSmoother


In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

# use seaborn's default plotting styles for matplotlib
import seaborn; seaborn.set()

The Data

The astroML project includes a data fetcher for light curves from the LINEAR survey. We'll use one of the light curves as an example.


In [2]:
from astroML.datasets import fetch_LINEAR_sample
data = fetch_LINEAR_sample()


[10003298 10004892 10013411 ...,  9984569  9987252   999528]

In [3]:
lcid = 10022663
t, y, dy = data[lcid].T

In [4]:
fig, ax = plt.subplots()
ax.errorbar(t, y, dy, fmt='o');
ax.invert_yaxis()
ax.set_xlabel('MJD')
ax.set_ylabel('magnitude')
ax.set_title('LINEAR object {0}'.format(lcid));


Computing the Periodogram

Now we import the functions to compute the periodogram:


In [5]:
# imports are from up one directory
import sys; import os; sys.path.append(os.path.abspath('..'))

from multiband_LS import SuperSmoother

In [6]:
model = SuperSmoother().fit(t, y, dy)
model.optimizer.period_range = (0.6, 0.65)
print("best period: {0:.4f}".format(model.best_period))


Finding optimal frequency:
 - Using omega_step = 0.00064
 - Computing periods at 1262 steps from 0.60 to 0.65
Zooming-in on 5 candidate peaks:
 - Computing periods at 1010 steps
best period: 0.6160

In [7]:
period = np.linspace(model.best_period - 0.005,
                     model.best_period + 0.005, 500)

P = model.periodogram(period)
plt.plot(period, P)
plt.xlabel('period (days)'); plt.ylabel('Lomb-Scargle Power');



In [8]:
t_fit = np.linspace(0, model.best_period, 500)

plt.errorbar(t % model.best_period, y, dy, fmt='o')
y_fit = model.predict(t_fit)
plt.plot(t_fit, y_fit, '-k')
plt.gca().invert_yaxis()


That's our result.