Periodogram¶
This tutorial demonstrates the Lomb–Scargle periodogram via light_curve.Periodogram.
Synthetic periodic light curve¶
In [ ]:
Copied!
import light_curve as lc
import numpy as np
rng = np.random.default_rng(0)
PERIOD = 23.5 # days
t = np.sort(rng.uniform(0, 300, 150))
m = 15.0 + 0.4 * np.sin(2 * np.pi * t / PERIOD) + rng.normal(0, 0.04, 150)
err = np.full(150, 0.04)
print(f'True period: {PERIOD} days, n_obs: {len(t)}')
import light_curve as lc
import numpy as np
rng = np.random.default_rng(0)
PERIOD = 23.5 # days
t = np.sort(rng.uniform(0, 300, 150))
m = 15.0 + 0.4 * np.sin(2 * np.pi * t / PERIOD) + rng.normal(0, 0.04, 150)
err = np.full(150, 0.04)
print(f'True period: {PERIOD} days, n_obs: {len(t)}')
True period: 23.5 days, n_obs: 150
Basic usage¶
Periodogram(peaks=1) returns the best period and its normalised power:
In [ ]:
Copied!
pg = lc.Periodogram(peaks=1, fast=True)
result = pg(t, m, err)
for name, val in zip(pg.names, result):
print(f' {name}: {val:.4f}')
pg = lc.Periodogram(peaks=1, fast=True)
result = pg(t, m, err)
for name, val in zip(pg.names, result):
print(f' {name}: {val:.4f}')
Multiple peaks¶
peaks=5 returns the five strongest periods:
In [ ]:
Copied!
pg5 = lc.Periodogram(peaks=5)
result5 = pg5(t, m, err)
print('Top 5 periods (days):')
for i in range(5):
print(f' peak {i+1}: period = {result5[i*2]:.3f} d, power = {result5[i*2+1]:.4f}')
pg5 = lc.Periodogram(peaks=5)
result5 = pg5(t, m, err)
print('Top 5 periods (days):')
for i in range(5):
print(f' peak {i+1}: period = {result5[i*2]:.3f} d, power = {result5[i*2+1]:.4f}')
Notes¶
fast=True(default) uses an FFT-based algorithm; setfast=Falsefor the exact O(N²) implementation.- Periods are in the same units as the input time array.
- See API reference for all constructor options.