Lomb-Scargle on Generated light curves

Here we'll use the RR Lyrae template-based light curve generation and do some Lomb-Scargle fits on them.


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

import seaborn as sns; sns.set()

In [2]:
import os, sys; sys.path.append(os.path.abspath('..'))
from multiband_LS.generated import RRLyraeObject
from multiband_LS import LombScargle, LombScargleAstroML, LombScargleMultiband

lcids = list(RRLyraeObject.lcdata.ids)

In [3]:
def show_LS_fits(i=0, Nobs=40, rseed=0, dy=0.05):
    lcid = lcids[i]
    
    rng = np.random.RandomState(rseed)
    rrlyrae = RRLyraeObject(lcid, random_state=rseed)

    t = 300 * rng.rand(Nobs)
    mags = np.array([rrlyrae.generated(band, t, err=dy, corrected=False)
                     for band in 'ugriz'])

    periods = np.linspace(0.2, 0.9, 10000)

    P = [LombScargleAstroML().fit(t, m, dy).periodogram(periods) for m in mags]

    fig, ax = plt.subplots(1, 2, figsize=(12, 4))
    for i, band in enumerate('ugriz'):
        ax[0].errorbar(t % rrlyrae.period, mags[i], dy, fmt='o', label=band)
    ax[0].invert_yaxis()
    ax[0].legend(loc='upper left', ncol=3)
    ax[0].set_title('Folded Data (id={0})'.format(lcid))

    for i, Pi in enumerate(P):
        ax[1].plot(periods, Pi + i * 1, lw=0.5)
    ax[1].set_title('Lomb-Scargle in Each Band')
    ax[1].yaxis.set_major_formatter(plt.NullFormatter())

In [4]:
from IPython.html.widgets import interact, fixed

interact(show_LS_fits, i=(0, len(lcids) - 1), Nobs=(2, 100),
         rseed=fixed(0), dy=fixed(0.05));



In [5]:
def show_LS_fits_multi(i=0, Nobs=60, rseed=0, dy=0.05):
    lcid = lcids[i]
    
    rng = np.random.RandomState(rseed)
    rrlyrae = RRLyraeObject(lcid, random_state=rseed)
    
    # Alternate between the five bands
    t = 300 * rng.rand(Nobs)
    filts = np.take(list('ugriz'), np.arange(Nobs), mode='wrap')
    mags = np.array([rrlyrae.generated(band, t, err=dy, corrected=False)
                     for band in 'ugriz'])[np.arange(Nobs) % 5, np.arange(Nobs)]
    
    periods = np.linspace(0.2, 0.9, 10000)
    
    masks = [(filts == band) for band in 'ugriz']

    P = [LombScargleAstroML().fit(t[mask], mags[mask], dy).periodogram(periods) for mask in masks]
    
    P_multi = LombScargleMultiband(Nterms_base=1, Nterms_band=0).fit(t, mags, dy, filts).periodogram(periods)

    fig, ax = plt.subplots(1, 3, figsize=(17, 4))
    fig.subplots_adjust(wspace=0.1)
    
    for band, mask in zip('ugriz', masks):
        ax[0].errorbar(t[mask] % rrlyrae.period, mags[mask], dy, fmt='o', label=band)
    ax[0].invert_yaxis()
    ax[0].legend(loc='upper left', ncol=3)
    ax[0].set_title('Folded Data')

    for i, Pi in enumerate(P):
        ax[1].plot(periods, Pi + i * 1, lw=0.5)
    ax[1].set_title('Lomb-Scargle in Each Band')
    ax[1].yaxis.set_major_formatter(plt.NullFormatter())
    
    ax[2].plot(periods, P_multi, lw=0.5)
    ax[2].set_title('multiband Lomb-Scargle')
    ax[2].set_ylim(0, 1)

In [6]:
from IPython.html.widgets import interact, fixed

interact(show_LS_fits_multi, i=(0, len(lcids) - 1), Nobs=(2, 200),
         rseed=fixed(0), dy=fixed(0.05));