I'm trying to remove the rotation signal from a lightcurve using the Lomb-Scargle method, however it won't model the lightcurve, it is only giving a straight horizontal line. The first image is the lightcurve, the second image is the attempted modelling with the black line at the top of the second image being the lightcurve. Any help to get the model to work would be appreciated.
The body of code is as follows:
from lightkurve import search_targetpixelfile
from lightkurve import TessTargetPixelFile
import lightkurve as lk
import numpy as np
import astropy.units as u
import matplotlib.pyplot as plt
TIC='TIC 126947245'
#using target pixel file (TPF)
search_result = lk.search_targetpixelfile(TIC, mission='TESS', sector=1)
tpf = search_result.download()
aperture_mask = tpf.create_threshold_mask(threshold=20)
tpf.plot(aperture_mask=tpf.pipeline_mask)
#lightcurve plot (using TPF)
lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)
lc.plot(linewidth = 0, marker = '.', color = 'green', alpha = 0.3)
#periodogram
pg = lc.to_periodogram(maximum_period=100)
pg.plot(view='period');
period = pg.period_at_max_power
frequency = pg.frequency_at_max_power
print('The Period Is' , period)
print('The Frequency Is ' , frequency)
# Create a model light curve for the highest peak in the periodogram
lc_model = pg.model(time=lc.time, frequency=frequency)
# Plot the light curve
ax = lc.plot()
# Plot the model light curve on top
lc_model.plot(ax=ax, lw=3, ls='--', c='red');
EDIT: For anyone else running into this issue, it was because I didn't normalise the lightcurve beforehand. Its working now, I just added .normalize() to lc = tpf.to_lightcurve(aperture_mask=tpf.pipeline_mask)

