generated from microsoft/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Allow makecommongp_fourier to take different Tspans for different pulsars.
#80
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
Open
meyers-academic
wants to merge
2
commits into
nanograv:main
Choose a base branch
from
meyers-academic:fourier_commongp_different_bases
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
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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,69 @@ | ||
| #!/usr/bin/env python3 | ||
| """Tests for discovery likelihood""" | ||
|
|
||
| import operator | ||
| from functools import reduce | ||
| from pathlib import Path | ||
|
|
||
| import discovery as ds | ||
| import jax | ||
| import pytest | ||
| import numpy as np | ||
| import numpy.testing as npt | ||
|
|
||
|
|
||
| class TestSignals: | ||
| data_dir = Path(__file__).resolve().parent.parent / "data" | ||
| psr_files = [ | ||
| data_dir / "v1p1_de440_pint_bipm2019-B1855+09.feather", | ||
| data_dir / "v1p1_de440_pint_bipm2019-B1953+29.feather", | ||
| ] | ||
| psrs = [ds.Pulsar.read_feather(psr) for psr in psr_files] | ||
|
|
||
| psr_rn_params = [f"{psrs[0].name}_red_noise_log10_A", f"{psrs[0].name}_red_noise_gamma", f"{psrs[1].name}_red_noise_log10_A", f"{psrs[1].name}_red_noise_gamma"] | ||
|
|
||
| # create fake parameter dict for testing | ||
| fake_params = {key: np.random.rand()*3 - 13 for key in psr_rn_params if 'log10_A' in key} | ||
| fake_params = {**fake_params, **{key: np.random.rand()*3 for key in psr_rn_params if 'gamma' in key}} | ||
|
|
||
| @pytest.mark.integration | ||
| def test_makecommongp_fourier_basis_construction(self): | ||
| tspans = [ds.getspan([psr]) for psr in self.psrs] | ||
| # make GP for both pulsars at once | ||
|
|
||
| gp = ds.makecommongp_fourier(self.psrs, ds.powerlaw, 14, T=tspans, name="red_noise") | ||
|
|
||
| # make two separate GPs | ||
| gp_psr1 = ds.makegp_fourier(self.psrs[0], ds.powerlaw, 14, T=tspans[0], name="red_noise") | ||
| gp_psr2 = ds.makegp_fourier(self.psrs[1], ds.powerlaw, 14, T=tspans[1], name="red_noise") | ||
|
|
||
| # check that bases are correct. | ||
| npt.assert_allclose(gp.F[0], gp_psr1.F) | ||
| npt.assert_allclose(gp.F[1], gp_psr2.F) | ||
|
|
||
| # check that noise matrices are correct | ||
| npt.assert_allclose(gp.Phi.getN(self.fake_params), np.vstack([gp_psr1.Phi.getN(self.fake_params), gp_psr2.Phi.getN(self.fake_params)])) | ||
|
|
||
| # now make the bases the same, giving a single tspan | ||
| # make GP for both pulsars at once | ||
| tspan_total = ds.getspan(self.psrs) | ||
| gp = ds.makecommongp_fourier(self.psrs, ds.powerlaw, 14, T=tspan_total, name="gw") | ||
|
|
||
| # make two separate GPs | ||
| gp_psr1 = ds.makegp_fourier(self.psrs[0], ds.powerlaw, 14, T=tspan_total, name="gw") | ||
| gp_psr2 = ds.makegp_fourier(self.psrs[1], ds.powerlaw, 14, T=tspan_total, name="gw") | ||
| # check that bases are correct. | ||
| npt.assert_allclose(gp.F[0], gp_psr1.F) | ||
| npt.assert_allclose(gp.F[1], gp_psr2.F) | ||
|
|
||
| # check that parameters are what they should be | ||
| gp = ds.makecommongp_fourier(self.psrs, ds.powerlaw, 14, T=tspans, name="red_noise") | ||
| expected_pars = set(self.psr_rn_params) | ||
| assert set(gp.Phi.params) == expected_pars | ||
|
|
||
| # check that common parameters are included | ||
| common = ["crn_log10_A", "crn_gamma"] | ||
| powerlaw = ds.makepowerlaw_crn(14) | ||
| gp = ds.makecommongp_fourier(self.psrs, powerlaw, 30, T=tspans, common=common, name="red_noise") | ||
| expected_pars = set(self.psr_rn_params + common) | ||
| assert set(gp.Phi.params) == expected_pars |
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 assume these
ifstatements are ok because they will get evaluated once when compiled?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.
check that
len(T) == len(psrs)