Skip to content

Commit

Permalink
pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PFLeget committed Sep 25, 2024
1 parent 4da2b89 commit 840fad3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
7 changes: 4 additions & 3 deletions python/lsst/meas/algorithms/computeExPsf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from lsst.pex.config import Config, Field
from lsst.pipe.base import Task
import treecorr
import copy


__all__ = (
Expand Down Expand Up @@ -76,10 +77,10 @@ def run(self, de1, de2, ra, dec, units="arcmin"):
kk = treecorr.KKCorrelation(config_kk)

kk.process(cat1)
kk_E1 = kk.xi
kk_E1 = copy.deepcopy(kk.xi[0])
kk.process(cat2)
kk_E2 = kk.xi
kk_E2 = copy.deepcopy(kk.xi[0])
kk.process(cat1, cat2)
kk_Ex = kk.xi
kk_Ex = copy.deepcopy(kk.xi[0])

return kk_E1, kk_E2, kk_Ex
60 changes: 35 additions & 25 deletions tests/test_computeExPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,27 @@ def generate_gaussian_random_field(
correlation_length=10.0,
white_noise=1.0,
seed=42,
coord=None,
input_coord=None,
):
"""
TO DO.
"""
np.random.seed(seed)

if coord is not None:
npoints = len(coord[:, 0])
if input_coord is not None:
npoints = len(input_coord[:, 0])

if npoints > nmax:
ngenerated = nmax
else:
ngenerated = npoints

if coord is not None or npoints > nmax:
if input_coord is not None or npoints > nmax:
x1 = np.random.uniform(xmin, xmax, ngenerated)
x2 = np.random.uniform(ymin, ymax, ngenerated)
coord1 = np.array([x1, x2]).T
else:
coord1 = coord

coord1 = input_coord
kernel = rbf_kernel(coord1, coord1, std, correlation_length)
kernel += np.eye(ngenerated) * white_noise**2

Expand All @@ -97,10 +96,12 @@ def generate_gaussian_random_field(
# and then interpolate it with a GP to do data augmentation.

if npoints > nmax:
if coord is None:
if input_coord is None:
x1 = np.random.uniform(xmin, xmax, npoints)
x2 = np.random.uniform(ymin, ymax, npoints)
coord = np.array([x1, x2]).T
else:
coord = input_coord

tgp = GaussianProcessTreegp(
std=std,
Expand Down Expand Up @@ -129,50 +130,59 @@ def setUp(self):
"ymin": 0,
"ymax": 2000,
"npoints": 10000,
"nmax": 1000,
"nmax": 2000,
"std": 1.0,
"white_noise": 0.1,
"white_noise": 0.01,
}

coord1, de1 = generate_gaussian_random_field(
correlation_length=100.0,
correlation_length=200.0,
seed=42,
coord=None,
input_coord=None,
**kwargs_grf,
)

coord2, de2 = generate_gaussian_random_field(
correlation_length=300.0,
seed=43,
coord=coord1,
correlation_length=100.0,
seed=44,
input_coord=coord1,
**kwargs_grf,
)

self.coord1 = coord1
self.coord2 = coord2
self.de1 = de1 * 1e-3
self.de2 = de2 * 1e-3
self.de1 = de1
self.de2 = de2

def test_comp_ex_psf(self):
"""Test that ex metric are compute and make sense."""

np.testing.assert_equal(self.coord1, self.coord2)

ra = self.coord1[:,0]
dec = self.coord1[:,1]
ra = self.coord1[:, 0]
dec = self.coord1[:, 1]

config = ComputeExPsfTask.ConfigClass()
config.thetaMin = 0.0
config.thetaMin = 0.01
config.thetaMax = 5.0

task = ComputeExPsfTask(config)
k_E1, kk_E2, kk_Ex = task.run(self.de1, self.de2, ra, dec, units="arcmin")
kk_E1, kk_E2, kk_Ex = task.run(self.de1, self.de2, ra, dec, units="arcmin")

np.testing.assert_allclose(kk_E1, 1.0, atol=2e-1)
np.testing.assert_allclose(kk_E2, 1.0, atol=2e-1)
np.testing.assert_allclose(kk_Ex, 0.0, atol=1e-1)

config = ComputeExPsfTask.ConfigClass()
config.thetaMin = 600.0
config.thetaMax = 1000.0

task = ComputeExPsfTask(config)
kk_E1, kk_E2, kk_Ex = task.run(self.de1, self.de2, ra, dec, units="arcmin")

# dumb test to make sure I reach that point.
# TO DO: to remove, and add more complex tests.
TEST = 42
if TEST == 42:
raise ValueError("TEST == 42")
np.testing.assert_allclose(kk_E1, 0.0, atol=1e-1)
np.testing.assert_allclose(kk_E2, 0.0, atol=1e-1)
np.testing.assert_allclose(kk_Ex, 0.0, atol=1e-1)


def setup_module(module):
Expand Down

0 comments on commit 840fad3

Please sign in to comment.