# How to Interpret Lomb Scargle periodogram

lomb scargle periodogram: import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from scipy import signal
from astropy.time import Time
from astropy.timeseries import LombScargle

date    sales
0  2011-01-29  32631.0
1  2011-01-30  31749.0
2  2011-01-31  23783.0
3  2011-02-01  25412.0
4  2011-02-02  19146.0

"""Converting dates to MJD """
tmp_str = m5_data.iloc[:,0].astype(pd.StringDtype())
t_date = np.array(tmp_str.values,dtype = 'str')
t_date = Time(t_date, format='isot', scale='utc')
t_date.format = 'mjd'

y = m5_data.iloc[:,1]
m5_ls = LombScargle(t_date, y)
m5_frequency, m5_power = m5_ls.autopower()
plt.plot(m5_frequency,m5_power)
plt.show()

1. What does the x axis represent? Is it frequencies in days or is it frequencies in 1/day?
2. So the spike at 2 does that mean there is a period of every two days or does it mean there is a period 1/2 days, which is a fractional day and I do not understand how I could get fractional days when I only have 1 observation per day.

The overall goal is to find if the data is periodic. Given this data is sales of a product from a store I would expect that if the data is periodic that the periods would be 7days(weekly), 30days(monthly), 182days(semi annually)

So the spike at 2 does not make sense to me.

• Maybe programming Stack Exchange? Feb 2 at 20:52
• @User123 the question is about an astronomical technique and is just fine here. Astronomers use computer programs as often as they use telescopes to learn about the universe.
– uhoh
Feb 3 at 0:00
• How can a frequency be measured in days? Feb 3 at 0:53
• @ProfRob The data is daily samples i.e. one sample/observation a day. I guess the frequency is not days, but the period would be days which is 1/frequency, is that correct? It is the period that I am looking for. Looking here and here and here it seems like they talk about days/hour only when they convert from frequency to period which is 1/freq or 24/freq(if sampled in minutes) Feb 3 at 11:49
• Please don't edit this question all willy nilly, the data.head() is very important for people to get an idea of the exact type of data being used. Feb 3 at 14:46

In your case, the x-axis looks linear, and the the code you present appears to be using something labelled as a frequency on the x-axis. Therefore I would assume (though I would read the documentation for the functions you are using) that the x-axis is frequency. The units will be based on whatever units are in your input. i.e. It is just the inverse of whatever you are giving it for the times - in this case, $$d^{-1}$$.
If your sampling rate is once per day, then you are getting no reliable information at all about frequencies $$>1$$ d$$^{-1}$$. The stuff you should be concentrating on lies between $$0\leq f < 1$$ d$$^{-1}$$. Even in this range you won't have good fidelity on signals with $$0.5 d$$^{-1}$$ because they are undersampled. You can also expect to get aliasing signals in the range $$0\leq f <1$$ that are caused by true signals (including those with higher frequencies) aliasing with the 1 d$$^{-1}$$ frequency of your sampling.
It looks to me, by eye, like you might have a genuine signal at $$1/7$$ d$$^{-1}$$, corresponding to a weekly variation. There may be a weaker signal at much lower frequencies that might correspond to a monthly signal. The 2 signals either side of 1 day look like aliases of the weekly signal with the sampling frequency.