<p><strong>tl;dr</strong>: try a finer frequency grid to obtain the correct period, bin it with the function <code>astropy.timeseries.aggregate_downsample</code></p>
<p>Before addressing the binning, you have to obtain a correct phase folded plot. You rightly call it &quot;messy&quot;, the most likely reason is that the period you chose is wrong (assuming the data actually contains a periodic signal with good S/N).</p>
<p>I understand you might not want to share your code. I will then make some assumptions:</p>
<ul>
<li>you are using <code>python</code>, <code>matplotlib</code> and <code>astropy</code></li>
<li>you have computed the peridogram using <code>astropy.timeseries.LombScargle</code></li>
<li>you have used the default <code>normalization='standard'</code></li>
<li>you have taken the frequency of the highest peak on the plot you posted and used it to phase-fold the data</li>
</ul>
<p>In general, blindly taking the highest peak of the peridogram that comes out of the Lomb-Scargle is often not the best approach. In particular in this case the highest peak has a value of about <span class="math-container">$\approx 0.020$</span>, which is definitely low. The correct period usually comes with peridogram values higher than <span class="math-container">$0.4$</span> (the maximum is <span class="math-container">$1$</span>). But don't take this as a rule. You may use the method <code>false_alarm_probability</code> to better quantify the probability that the peak is significant and not random.</p>
<p>I believe that you have not found the correct period because you have used a too coarse frequency grid. The period lies between the points and you have missed it. Use a <strong>much</strong> finer frequency grid and you might be able to see a new peak appearing, very high and narrow. Alternatively, if you don't want to choose the spacing yourself, you may use the <code>autopower</code> method, that should find the best frequency grid for you.</p>
<p>After you have found the correct period and your folded curve makes sense, binning is the easiest part, there is a function that does just that: <code>astropy.timeseries.aggregate_downsample</code>.</p>
<p>Everything that I just said (and much more) is explained in the documentation of <code>astropy</code>, which is really complete and easy to understand. I cannot stress it enough, <strong>read the documentation</strong> and you will find that most of the problems you may encounter are already addressed there:</p>
<p><a href="https://docs.astropy.org/en/stable/timeseries/lombscargle.html" rel="nofollow noreferrer">astropy: Lomb-Scargle</a></p>
<p><a href="https://docs.astropy.org/en/stable/timeseries/index.html" rel="nofollow noreferrer">astropy: Time Series</a></p>
<p>And a more technical paper that explains the capabilities and limitations of the Lomb-Scargle, I suggest you keep it as a reference:</p>
<p><a href="https://ui.adsabs.harvard.edu/abs/2018ApJS..236...16V" rel="nofollow noreferrer">Understanding the Lomb-Scargle Periodogram</a></p>

CC BY-SA 4.0
2021-08-18T07:24:04.423Z
The Vanderplas paper is excellent.
ProfRob
CC BY-SA 4.0
2021-08-18T07:24:47.437Z
@ProfRob I just discovered it this morning, I am really impressed
Prallax
CC BY-SA 4.0
2021-08-19T00:58:49.153Z
There are some interesting things here: http://vanderplas.com/ Though not about Astronomy *per se* I linked to their github in [this SO answer](https://stackoverflow.com/a/34572718/3904031). Also, there are some other [Lomb-Scargle questions](https://astronomy.stackexchange.com/search?q=Scargle) and [periodogram questions](https://astronomy.stackexchange.com/search?q=Periodogram) that may also be in need of additional attention.
uhoh
CC BY-SA 4.0
2021-08-18T07:22:13.390Z
2021-08-18T07:22:13.390Z
Prallax
<p>How do I bin a messy phase folded lightcurve? This is one of the phase folded generated plots for a variable star. I plotted the phase using the period extracted by Lomb-Scargle Periodogram algorithm. I need to bin them say by ~100 or so. Kindly help me out. <a href="https://i.sstatic.net/SGR1i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SGR1i.png" alt="Phase Folded Light Curve" /></a></p>
<p>This is the periodigram obtained using Lomb-Scargle method.
<a href="https://i.sstatic.net/AOz3K.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AOz3K.png" alt="Lomb-Scargle Periodogram" /></a></p>

CC BY-SA 4.0
2021-08-17T12:00:54.590Z
I would have expected a much smoother curve. IMO, either it has not been folded properly or the curve is dominated by statistical errors (i.e. no detection)
Prallax
CC BY-SA 4.0
2021-08-17T13:51:15.367Z
Another reason could it be noise destruction.
Lariliss
CC BY-SA 4.0
2021-08-17T18:16:29.047Z
I plotted the periodogram and got the frequency as I expected. When I plotted the phase folded curve, I got this.
Abhinna Sundar
CC BY-SA 4.0
2021-08-17T19:03:57.870Z
If you'd like, you can post more information, like a few lines of the code you used to obtain it, the plot of the peridogram and a plot of the original data (possibly dot-plots, not line-plots, for visual clarity). I'm not an expert, but I'd be happy to help you pinpoint the problem
Prallax
CC BY-SA 4.0
2021-08-18T04:27:17.270Z
Yes, I've edited the question. I have added the periodogram.
Abhinna Sundar
<astrophysics><light-curve>
Binning a Phase Folded Lightcurve
Abhinna Sundar
# Binning a Phase Folded Lightcurve

(Asked by: username_0 on 2021-08-17)

How do I bin a messy phase folded lightcurve? This is one of the phase folded generated plots for a variable star. I plotted the phase using the period extracted by Lomb-Scargle Periodogram algorithm. I need to bin them say by ~100 or so. Kindly help me out. [![Phase Folded Light Curve](https://i.sstatic.net/SGR1i.png)](https://i.sstatic.net/SGR1i.png)

This is the periodigram obtained using Lomb-Scargle method.
[![Lomb-Scargle Periodogram](https://i.sstatic.net/AOz3K.png)](https://i.sstatic.net/AOz3K.png)

**Tags:** astrophysics, light-curve
> **Comments:**
> **username_1**: I would have expected a much smoother curve. IMO, either it has not been folded properly or the curve is dominated by statistical errors (i.e. no detection)  
> **username_2**: Another reason could it be noise destruction.  
> **username_0**: I plotted the periodogram and got the frequency as I expected. When I plotted the phase folded curve, I got this.  
> **username_1**: If you'd like, you can post more information, like a few lines of the code you used to obtain it, the plot of the peridogram and a plot of the original data (possibly dot-plots, not line-plots, for visual clarity). I'm not an expert, but I'd be happy to help you pinpoint the problem  
> **username_0**: Yes, I've edited the question. I have added the periodogram.  

---

## 1 answers

### Answer by username_1 on 2021-08-18. Score: 3

**tl;dr**: try a finer frequency grid to obtain the correct period, bin it with the function `astropy.timeseries.aggregate_downsample`

Before addressing the binning, you have to obtain a correct phase folded plot. You rightly call it "messy", the most likely reason is that the period you chose is wrong (assuming the data actually contains a periodic signal with good S/N).

I understand you might not want to share your code. I will then make some assumptions:

* you are using `python`, `matplotlib` and `astropy`
* you have computed the peridogram using `astropy.timeseries.LombScargle`
* you have used the default `normalization='standard'`
* you have taken the frequency of the highest peak on the plot you posted and used it to phase-fold the data

In general, blindly taking the highest peak of the peridogram that comes out of the Lomb-Scargle is often not the best approach. In particular in this case the highest peak has a value of about $\approx 0.020$, which is definitely low. The correct period usually comes with peridogram values higher than $0.4$ (the maximum is $1$). But don't take this as a rule. You may use the method `false_alarm_probability` to better quantify the probability that the peak is significant and not random.

I believe that you have not found the correct period because you have used a too coarse frequency grid. The period lies between the points and you have missed it. Use a **much** finer frequency grid and you might be able to see a new peak appearing, very high and narrow. Alternatively, if you don't want to choose the spacing yourself, you may use the `autopower` method, that should find the best frequency grid for you.

After you have found the correct period and your folded curve makes sense, binning is the easiest part, there is a function that does just that: `astropy.timeseries.aggregate_downsample`.

Everything that I just said (and much more) is explained in the documentation of `astropy`, which is really complete and easy to understand. I cannot stress it enough, **read the documentation** and you will find that most of the problems you may encounter are already addressed there:

[astropy: Lomb-Scargle](https://docs.astropy.org/en/stable/timeseries/lombscargle.html)

[astropy: Time Series](https://docs.astropy.org/en/stable/timeseries/index.html)

And a more technical paper that explains the capabilities and limitations of the Lomb-Scargle, I suggest you keep it as a reference:

[Understanding the Lomb-Scargle Periodogram](https://ui.adsabs.harvard.edu/abs/2018ApJS..236...16V)

> **Comments:**
> **username_3**: The Vanderplas paper is excellent.  
> **username_1**: @ProfRob I just discovered it this morning, I am really impressed  
> **username_4**: There are some interesting things here: http://vanderplas.com/ Though not about Astronomy *per se* I linked to their github in [this SO answer](https://stackoverflow.com/a/34572718/3904031). Also, there are some other [Lomb-Scargle questions](https://astronomy.stackexchange.com/search?q=Scargle) and [periodogram questions](https://astronomy.stackexchange.com/search?q=Periodogram) that may also be in need of additional attention.  

---

