hippke / tls

Transit Least Squares: An optimized transit-fitting algorithm to search for periodic transits of small planets
MIT License
48 stars 24 forks source link

Why TLS use duration from minimum chi2 period instead of maximum power period? #106

Closed Farthing-0 closed 1 year ago

Farthing-0 commented 1 year ago

I understand that the choice of best fit of period should based on power spectra and that's what tls do. But I'm quite curious about why tls choose the duration based on the minimum chi2 and combine it with the period based on the power spectra, then send them to other process.

https://github.com/hippke/tls/blob/4ef0f141d842377dd2541906d84c2e4350027c27/transitleastsquares/main.py#L198-L200 https://github.com/hippke/tls/blob/4ef0f141d842377dd2541906d84c2e4350027c27/transitleastsquares/main.py#L286-L288

I think the choice of duration should also be based on power spectra, is this a bug or I miss something?

This is the first time I open an issue, so please tell me if I did something wrong.

hippke commented 1 year ago

It's a 4D chi2 grid of period, phase, transit duration, and transit depth. TLS aims to find the minimum. The power spectrum shows the minimum of (phase, transit duration, transit depth) for each period.

Farthing-0 commented 1 year ago

Thanks for your reply and this very useful package!

But what I found is only the transit depth and period are found based on the "index_highest_power", which is the position of the maximum power period. https://github.com/hippke/tls/blob/4ef0f141d842377dd2541906d84c2e4350027c27/transitleastsquares/main.py#L270-L272 And the duration is based on the "best_row" and "idx_best", which is the position of minimum chi2 period. https://github.com/hippke/tls/blob/4ef0f141d842377dd2541906d84c2e4350027c27/transitleastsquares/main.py#L198-L200 So the duration and depth are found in different locations. Is this intentionally designed? Or I get something wrong?

hippke commented 1 year ago

It's in a different code position to be able to use numba for acceleration through JIT compilation. Not very pretty code, but much faster.

Farthing-0 commented 1 year ago

Well, I think I might not express my question clearly. I think the function you link is used for find residual for specific period and duration, and the function is only called from "search_period".

But what I am talking about is after all the finding is over, during the process of confirming the best period and duration. After iteratively search periods, power is calculated by chi2.

And my question is, why the best duration is confirmed by the chi2, since depth and period are confirmed by the power spectrum.

Since the function you link is not called from "main.py", I don't see how it affects my question.

Again, thanks for your time.

hippke commented 1 year ago

Ah! That's just a coding/implementation peculiarity. I optimized so that the core search (step 1) runs inside of the L2 cache of common CPUs, giving 10x faster speed. Caches are small, so we can't save all 4D chi2 results (ideally we would save the entire matrix for post-processing / selection). Thus, without the information of the best duration, we need to recover it (re-search it) afterwards.

If you're interested, feel free to re-implement the TLS procedure! Perhaps you find a more elegant and/or faster way.

Farthing-0 commented 1 year ago

Thanks for your explanation! This package do interest me and I will see what I can do.