In [1]:
%matplotlib inline
import numpy as np
from scipy import stats
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import matplotlib.cm as cm
import pandas as pd
from astropy.io import fits
from astropy.stats import LombScargle
from gatspy import datasets, periodic
In [2]:
matplotlib.rcParams.update({'font.size':18})
matplotlib.rcParams.update({'font.family':'serif'})
In [3]:
target = fits.open('kplr010536761-2009166043257_llc.fits')
In [4]:
target.info()
In [5]:
target[0].header
Out[5]:
In [6]:
data = target[1].data
In [7]:
time = data['TIME']
flux = data['PDCSAP_FLUX']
rel_flux = (flux-np.nanmedian(flux))/np.nanmedian(flux)
err = data['PDCSAP_FLUX_ERR']
rel_err = (err-np.nanmedian(err))/np.nanmedian(err)
In [8]:
fig = plt.figure(figsize = (11,5))
plt.plot(time,rel_flux,color='b')
plt.xlim(150,160)
plt.ylim(-0.02,0.05)
plt.xlabel('Time [BJD-2454833]')
plt.ylabel('Relative Flux')
plt.title('KIC 10536761')
Out[8]:
In [9]:
cut = np.where(np.isnan(flux) == False)
In [10]:
np.size(time[cut])
Out[10]:
In [11]:
fig = plt.figure(figsize = (11,5))
plt.plot(time[cut],rel_flux[cut],color='b')
#plt.xlim(150,156)
plt.ylim(-0.02,0.05)
plt.xlabel('Time [BJD-2454833]')
plt.ylabel('Relative Flux')
plt.title('KIC 10536761')
plt.savefig('KIC10536761_lc.pdf', dpi = 600)
In [12]:
model = periodic.LombScargleFast(fit_period = True)
model.optimizer.period_range = (0.2, 6.0)
model.fit(time[cut], rel_flux[cut], err[cut])
Out[12]:
In [13]:
model.best_period
Out[13]:
In [20]:
# Compute the scores on a grid of periods
periods = np.linspace(0.2, 10.0, 10000)
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
scores = model.score(periods)
# Plot the results
fig, ax = plt.subplots(figsize=(11, 5))
fig.subplots_adjust(bottom=0.2)
ax.plot(periods, scores, 'red')
ax.set(xlabel='period (days)', ylabel='Lomb Scargle Power', title='L-S Periodogram',
xlim=(0.0, 10.0), ylim=(0, 1), xscale = 'log')
plt.savefig('KIC10536761_periodogram.pdf', dpi = 600)
In [ ]:
In [ ]: