-
Notifications
You must be signed in to change notification settings - Fork 144
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
capy-on-caffeine
wants to merge
9
commits into
StingraySoftware:main
Choose a base branch
from
capy-on-caffeine:unit-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
09dd77e
Manual Test added. Can be improved
capy-on-caffeine 7837fc2
Merge branch 'StingraySoftware:main' into unit-test
capy-on-caffeine 0c07a21
Black formatting
capy-on-caffeine 5cce813
Merge branch 'main' into unit-test
capy-on-caffeine e191a88
improved get_mean_phase_difference, get_phase_lag
capy-on-caffeine 6f576f9
formatting and changelog
capy-on-caffeine 0b6f419
Merge branch 'main' into unit-test
capy-on-caffeine 96ed9d9
Merge branch 'main' into unit-test
capy-on-caffeine 4e5823b
Merge branch 'main' into unit-test
matteobachetti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added unit tests for get_mean_phase_difference and get_phase_lag in stingray/spectroscopy.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,10 +236,6 @@ def test_ccf(self): | |
assert np.all(np.isclose(ccf_norm, avg_seg_ccf, atol=0.01)) | ||
assert np.all(np.isclose(error_ccf, np.zeros(shape=error_ccf.shape), atol=0.01)) | ||
|
||
def test_get_mean_phase_difference(self): | ||
_, a, b, _ = spec.get_parameters(self.ref_aps.lc1.counts, self.ref_aps.lc1.dt, self.model) | ||
assert a == b | ||
|
||
|
||
def test_load_lc_fits(): | ||
dt = 0.1 | ||
|
@@ -395,3 +391,47 @@ def test_compute_rms(): | |
|
||
with pytest.raises(ValueError): | ||
spec.compute_rms(cs, model, criteria="filter") | ||
|
||
|
||
def test_get_mean_phase_difference(): | ||
dt = 0.01 | ||
time = np.arange(0, 100, dt) | ||
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) | ||
counts = counts_qpo + counts_harmonic | ||
|
||
lc = Lightcurve(time, counts, dt=dt) | ||
cs = Crossspectrum(lc, lc) | ||
|
||
model = models.Lorentz1D(x_0=qpo_freq, amplitude=100) + models.Lorentz1D( | ||
x_0=harmonic_freq, amplitude=50 | ||
) | ||
avg_psi, stddev = spec.get_mean_phase_difference(cs, model) | ||
|
||
assert np.isclose(avg_psi, np.pi / 2, 1e-5) | ||
assert np.isclose(stddev, np.pi / 2, 1e-5) | ||
|
||
|
||
def test_get_phase_lag(): | ||
dt = 0.01 | ||
time = np.arange(0, 100, dt) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
counts = counts_qpo + counts_harmonic | ||
|
||
lc = Lightcurve(time, counts, dt=dt) | ||
cs = Crossspectrum(lc, lc) | ||
|
||
qpo_phase = np.pi / 4 | ||
harmonic_phase = np.pi / 4 | ||
model = models.Lorentz1D(x_0=qpo_freq) + models.Lorentz1D(x_0=harmonic_freq) | ||
|
||
cap_phi_1, cap_phi_2, small_psi = spec.get_phase_lag(cs, model) | ||
|
||
assert np.isclose(cap_phi_1, np.pi / 2, atol=1e-2) | ||
assert np.isclose(cap_phi_2, 2 * np.pi, atol=1e-2) | ||
assert np.isclose(small_psi, np.pi / 2, atol=1e-2) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?