Using Lomb-Scargle periodogram to find a periodic signal


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

# use seaborn for matplotlib settings
import seaborn; seaborn.set()

The Data

Grab some data from astroML; astroML can be installed using pip install astroML.


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

In [3]:
lcid = 10022663
t, y, dy = data[lcid].T
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));


Running Lomb-Scargle


In [4]:
# add up-directory to Python path
import sys, os; sys.path.append(os.path.abspath('..'))
from periodogram.lomb_scargle import LombScargle


/Users/tdm/anaconda/lib/python2.7/site-packages/astroML/time_series/periodogram.py:8: UserWarning: Using slow version of lomb_scargle. Install astroML_addons to use an optimized version
  warnings.warn("Using slow version of lomb_scargle. Install astroML_addons "

In [8]:
model = LombScargle(pmin=0.2,pmax=0.8, resolution=1e4).fit(t, y, dy)

periods = np.linspace(0.2, 0.8, 10000)
scores = model.score(periods)

plt.plot(periods, scores);



In [ ]: