Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for get_phase_lag and get_mean_phase_difference #714

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

capy-on-caffeine
Copy link
Contributor

This PR is for adding unit tests for get_phase_lag and get_mean_phase_difference in spectroscopy.py as per issue #358. The current tests can be further improved by creating light curves with more data points.

@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.59%. Comparing base (14756d9) to head (0b6f419).
Report is 6 commits behind head on main.

❗ Current head 0b6f419 differs from pull request most recent head 4e5823b. Consider uploading reports for the commit 4e5823b to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #714       +/-   ##
===========================================
- Coverage   96.47%   48.59%   -47.89%     
===========================================
  Files          45       45               
  Lines        9135     9135               
===========================================
- Hits         8813     4439     -4374     
- Misses        322     4696     +4374     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matteobachetti
Copy link
Member

Note to self and @capy-on-caffeine : this is worth completing :)

@pep8speaks
Copy link

pep8speaks commented Jan 21, 2024

Hello @capy-on-caffeine! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-04-22 11:18:43 UTC

@capy-on-caffeine capy-on-caffeine marked this pull request as ready for review April 1, 2024 04:10
@capy-on-caffeine
Copy link
Contributor Author

@matteobachetti any suggestions for an improved unit test?

@matteolucchini1
Copy link
Collaborator

Hi @capy-on-caffeine ! One thing that might be worth trying if you want something more fancy is a more realistic case where your lightcurve is a sum of a QPO plus a harmonic (rather than the simple wave you have now), plus the QPO and harmonic have (known) non-zero phase. Then you can test against that known phase rather than 0 (or pi or pi/2) like you are doing now.

@capy-on-caffeine
Copy link
Contributor Author

@matteolucchini1 Thank you, I'll try this out

@capy-on-caffeine
Copy link
Contributor Author

@matteobachetti @matteolucchini1 I made some changes, any changes are welcome.

@matteobachetti
Copy link
Member

@capy-on-caffeine there is something I don't understand in these tests. Why should phase lags be $\pi/2$ between two identical light curves? Also, @matteolucchini1 's suggestion to inject an actual phase difference and trying to recover it from the measurement is great.
Am I missing something? Some comments to the code would not hurt 😅

@capy-on-caffeine
Copy link
Contributor Author

Sorry for the late reply. I'll go through these again and change them after discussing.

qpo_freq = 0.1
harmonic_freq = 2 * qpo_freq
counts_qpo = 100 * np.sin(2 * np.pi * qpo_freq * time - np.pi / 4)
counts_harmonic = 50 * np.sin(2 * np.pi * harmonic_freq * time - np.pi / 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by the phases here - it looks like both are -pi/4. Should they not be -pi/4 for one, and +pi/4 for the other, if you want a difference of pi/2?

qpo_freq = 0.1
harmonic_freq = 2 * qpo_freq
counts_qpo = 100 * np.sin(2 * np.pi * qpo_freq * time + np.pi / 4)
counts_harmonic = 50 * np.sin(2 * np.pi * harmonic_freq * time + np.pi / 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above - it looks like the phases here are the same. I think I am also misunderstanding something, but should cap_phi_1 and cap_phi_2 not be pi/4 then, and small_psi 0?

@capy-on-caffeine
Copy link
Contributor Author

@matteobachetti @matteolucchini1 I was looking into it and noticed a few things:

  1. get_mean_phase_difference() uses cs.m but m = 1 from the input, which possibly disrupts the calculation. I'm reading through the docs to set that first.
  2. While graphing the crossspectrum, I noticed some peaks. Just wanted to know if these are normal?
    Screenshot 2024-04-26 200438
    Screenshot 2024-04-26 200503

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants