Skip to content

Commit 756762d

Browse files
authored
Merge pull request #187 from bd-j/parupdate
Move parameter check
2 parents 8cdfd49 + 929a23d commit 756762d

2 files changed

Lines changed: 30 additions & 3 deletions

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: 29 additions & 2 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"] = pop.params["tage"] + 0.1
74+
# this also used to raise an assertion error in the setter:
75+
pop.params["imf_type"] = 8
76+
# fix the invalid IMF but leave the invalid sf_start > tage
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()
@@ -73,10 +99,11 @@ def test_filters():
7399
def test_get_mags(pop_and_params):
74100
"""Basic test for supplying filter names to get_mags"""
75101
pop, params = pop_and_params
102+
_reset_default_params(pop, params)
76103
fuv1 = pop.get_mags(bands=["galex_fuv"])[:, 0]
77104
mags = pop.get_mags()
78-
fuv2 = mags[:, 61]
79-
fuv3 = mags[:, 62]
105+
fuv2 = mags[:, 61] # this should be galex_FUV
106+
fuv3 = mags[:, 62] # this should *not* be galex_FUV
80107
assert np.all(fuv1 == fuv2)
81108
assert np.all(fuv1 != fuv3)
82109

0 commit comments

Comments
 (0)