Skip to content

Commit 1afd935

Browse files
committed
move parameter validity check to _update_params() where the python parameters are passed to the fortran driver.
1 parent 8cdfd49 commit 1afd935

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/fsps/fsps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ def __init__(
544544
self._libraries = None
545545

546546
def _update_params(self):
547+
self.params.check_params()
547548
if self.params.dirtiness == 2:
548549
driver.set_ssp_params(*[self.params[k] for k in self.params.ssp_params])
549550
if self.params.dirtiness >= 1:
@@ -1334,4 +1335,3 @@ def __setitem__(self, k, v):
13341335
self.dirtiness = max(1, self.dirtiness)
13351336

13361337
self._params[k] = v
1337-
self.check_params()

tests/tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ def test_libraries(pop_and_params):
6161
assert dlib == pop.duste_library
6262

6363

64+
def test_param_checks(pop_and_params):
65+
pop, params = pop_and_params
66+
_reset_default_params(pop, params)
67+
pop.params["sfh"] = 1
68+
pop.params["tage"] = 2
69+
pop.params["sf_start"] = 0.5
70+
# this should never raise an error:
71+
w, s = pop.get_spectrum(tage=pop.params["tage"])
72+
# this used to raise an assertion error in the setter:
73+
pop.params["sf_start"] = 2.1
74+
# this also used to raise an assertion error in the setter:
75+
pop.params["imf_type"] = 8
76+
# fix the IMF issue but leave the sf_start error
77+
pop.params["imf_type"] = 1
78+
try:
79+
# This *should* still raise an AssertionError
80+
w, s = pop.get_spectrum(tage=pop.params["tage"])
81+
# Hacky way to make sure the AssertionError still got thrown
82+
raise ValueError("Did not throw exception for invalid sf_start > tage")
83+
except(AssertionError):
84+
pass
85+
pop.params["tage"] = 1.0
86+
pop.params["sf_start"] = 0.1
87+
w, s = pop.get_spectrum(tage=pop.params["tage"])
88+
89+
6490
def test_filters():
6591
"""Test all the filters got transmission data loaded."""
6692
flist = filters.list_filters()

0 commit comments

Comments
 (0)