Skip to content

Commit

Permalink
improved tests in lens distribution draws
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Jun 27, 2024
1 parent 58d9bd4 commit c0ed4a6
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions test/test_Sampling/test_Distributions/test_lens_distribution.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import copy
import numpy.testing as npt

from hierarc.Sampling.Distributions.lens_distribution import LensDistribution


class TestLensDistribution(object):

def setup_method(self):
self.kwargs_sampling = {"lambda_mst_distribution": "GAUSSIAN",
self.kwargs_sampling = {
"lambda_mst_sampling": True,
"lambda_mst_distribution": "GAUSSIAN",
"gamma_in_sampling": True,
"gamma_in_distribution": "GAUSSIAN",
"log_m2l_sampling": True,
"log_m2l_distribution" : "GAUSSIAN",
"log_m2l_distribution": "GAUSSIAN",
"alpha_lambda_sampling": True,
"beta_lambda_sampling": True,
"alpha_gamma_in_sampling": True,
Expand All @@ -19,8 +22,8 @@ def setup_method(self):
"mst_ifu": False, # change for different tests
"lambda_scaling_property": 0.1,
"lambda_scaling_property_beta": 0.2,
"kwargs_min": {"gamma_in": 0, "log_m2l": -3},
"kwargs_max": {"gamma_in": 3, "log_m2l": 3}}
"kwargs_min": {"gamma_in": 1, "log_m2l": 0},
"kwargs_max": {"gamma_in": 2, "log_m2l": 1}}

self.kwargs_lens = {"lambda_mst": 1.1,
"lambda_mst_sigma": 0.1,
Expand All @@ -30,10 +33,10 @@ def setup_method(self):
"alpha_lambda": -0.2,
"beta_lambda": 0.3,
"gamma_in": 1.5,
"gamma_in_sigma": 0.2,
"gamma_in_sigma": 1,
"alpha_gamma_in": 0.2,
"log_m2l": 0.6,
"log_m2l_sigma": 0.2,
"log_m2l_sigma": 1,
"alpha_log_m2l": -0.1}

def test_draw_lens(self):
Expand All @@ -46,6 +49,21 @@ def test_draw_lens(self):
kwargs_sampling["log_scatter"] = True
kwargs_sampling["lambda_ifu"] = True
lens_dist = LensDistribution(kwargs_sampling)
kwargs_return = lens_dist.draw_lens(**self.kwargs_lens)
for i in range(100):
kwargs_return = lens_dist.draw_lens(**self.kwargs_lens)

assert "lambda_mst" in kwargs_return
assert "lambda_mst" in kwargs_return

def test_raises(self):

with npt.assert_raises(ValueError):
lens_dist = LensDistribution(**self.kwargs_sampling)
kwargs_lens = copy.deepcopy(self.kwargs_lens)
kwargs_lens["gamma_in"] = -10
kwargs_return = lens_dist.draw_lens(**kwargs_lens)

with npt.assert_raises(ValueError):
lens_dist = LensDistribution(**self.kwargs_sampling)
kwargs_lens = copy.deepcopy(self.kwargs_lens)
kwargs_lens["log_m2l"] = -100
kwargs_return = lens_dist.draw_lens(**kwargs_lens)

0 comments on commit c0ed4a6

Please sign in to comment.