Quick Start

In this section, we will walk through a few simple examples to help you get started on EzTao. For more in-depth tutorials, please check out the sections listed under Tutorials on the main page (or other notebooks if you are running this in mybinder).

[1]:
# general packages
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline

# packages/modules from eztao and celerite
import eztao
from eztao.carma import DRW_term
from eztao.ts import gpSimRand
from eztao.ts import drw_fit
from celerite import GP

# use eztao matplotlib style
mpl.rc_file(os.path.join(eztao.__path__[0], "viz/eztao.rc"))

Simulate a DRW process

Here, we are simulating a DRW process with a RMS amplitude of 0.2 and a decorrelation/characteristic timescale of 100 days by first declaring a DRW GP kernel and generating the time series of a signal-to-noise ratio of 10, duration of 10 years and totally 200 data points using gpSimRand.

[2]:
# initialize DRW kernel, amp is RMS amplitude and tau is the decorrelation timescale
amp = 0.2
tau = 100
DRW_kernel = DRW_term(np.log(amp), np.log(tau))

# generate the time series, y-axis is linear
SNR = 10
duration = 365*10.0
npts = 200
t, y, yerr = gpSimRand(DRW_kernel, SNR, duration, npts, log_flux=False)
[3]:
# plot the simulated process
fig, ax = plt.subplots(1,1, dpi=120, figsize=(8,3))
ax.errorbar(t, y, yerr, fmt='.')
ax.set_xlabel('Time (day)')
ax.set_ylabel('Flux (arb. unit)')
ax.set_title('Simulated DRW process')
[3]:
Text(0.5, 1.0, 'Simulated DRW process')
../_images/notebooks_01_Quick_start_4_1.png

Fit the simulated DRW process

[4]:
best_fit = drw_fit(t, y, yerr)
print(f'Best-fit DRW parameter: {best_fit}')
Best-fit DRW parameter: [ 0.21092082 96.47362586]

Compare the True PSD with the Best-fit PSD

PSD stands for power spectral density. We will use the PSD function provided the \(\mathit{celerite}\).

[5]:
# import the GP PSD function from eztao
from eztao.carma import gp_psd
[6]:
# define the true/best-fit PSD functions using the input kernel
# and a new kernel initalized with the best-fit parameters
best_fit_kernel = DRW_term(*np.log(best_fit))

true_psd = gp_psd(DRW_kernel)
best_psd = gp_psd(best_fit_kernel)
[7]:
# plot and compare their PSDs
fig, ax = plt.subplots(1,1, dpi=120, figsize=(6,4))
freq = np.logspace(-5, 2)
ax.plot(freq, true_psd(freq), label='Input PSD')
ax.plot(freq, best_psd(freq), label='Best-fit PSD')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel(r'Frequency ($\frac{1}{\mathrm{day}}$)')
ax.set_ylabel('PSD')
ax.set_title('The PSD of a DRW process', fontsize=14)
ax.legend()
fig.tight_layout()
../_images/notebooks_01_Quick_start_10_0.png

Note

Here, we are using a DRW model for demonstration purpose only, the same analysis can be applied using any CARMA models. We will show that in the next few notebooks.