Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimerzp committed Jun 17, 2024
1 parent 02d0330 commit 3fd92a5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/qp/test_projector_shifts_widths.py
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)

0 comments on commit 3fd92a5

Please sign in to comment.