-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jaimerzp
committed
Jun 17, 2024
1 parent
02d0330
commit 3fd92a5
Showing
1 changed file
with
39 additions
and
0 deletions.
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,39 @@ | ||
import qp | ||
import numpy as np | ||
import qp.projectors as proj | ||
|
||
|
||
def make_qp_ens(file): | ||
zs = file['zs'] | ||
nzs = file['pzs'] | ||
dz = np.mean(np.diff(zs)) | ||
zs_edges = np.append(zs - dz/2, zs[-1] + dz/2) | ||
q = qp.Ensemble(qp.hist, data={"bins":zs_edges, "pdfs":nzs}) | ||
return q | ||
|
||
|
||
def make_projector(): | ||
file = np.load('tests/qp/dummy.npz') | ||
ens = make_qp_ens(file) | ||
return proj.ProjectorShiftsWidths(ens) | ||
|
||
|
||
def test_prior(): | ||
projector = make_projector() | ||
prior = projector.get_prior() | ||
assert prior is not None | ||
|
||
|
||
def test_sample_prior(): | ||
projector = make_projector() | ||
prior_sample = projector.sample_prior() | ||
assert len([prior_sample]) == len([projector.shift, projector.width]) | ||
|
||
|
||
def test_model(): | ||
projector = make_projector() | ||
shift, width = projector.sample_prior() | ||
input = np.array([projector.z, projector.nz_mean]) | ||
output = projector.evaluate_model(input, shift, width) | ||
assert (projector.z == output[0]).all() | ||
assert len(output[1]) == len(projector.nz_mean) |