-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Hello,
I am working with Prospector to build a parametric SFH model. I've encountered an issue when trying to modify both 'tage' and 'sf_start' with the sfh=1 FSPS model.
The error traces back to the assertion statements (here, lines 1314-1318).
It looks like because Prospector loops through the parameter list, and in each loop there is this check, it can fail if "tage" updates before "sf_start", and the new "tage" is younger than the old "sf_start". I imagine this could be avoided if the check was done after updating the full parameter list.
I've skirted this issue by commenting out the assertion statement, and it appears to be running fine. I have built my actual model such that sf_start < tage < sf_trunc.
Here is a basic example of how I am encountering this issue:
from prospect.models.templates import TemplateLibrary
model_params = TemplateLibrary["parametric_sfh"]
model_params["tage"] = {'N': 1, 'init': 0, 'units': 'Gyr'}
model_params["sf_start"] = {'N': 1, 'init': 1, 'units': 'Gyr', }
model_params["sf_trunc"] = {'N': 1, 'init': 3, "units": "Gyr", }
model_params["tage"]["init"] = 0.5*( model_params["sf_start"]['init'] + model_params["sf_trunc"]['init'] )
from prospect.models import sedmodel
model = sedmodel.PolySpecModel(model_params)
from prospect.sources import CSPSpecBasis
sps = CSPSpecBasis(zcontinuous=1)
# sf_start < tage < sf_trunc
# this will work
_ = model.predict( model.theta, sps=sps, obs={"wavelength":None, "filters":None})
# Now make the new sf_start larger than the old tage
model.params["sf_start"] = model.params["tage"] + 0.1
model.params["tage"] = 0.5*( model.params["sf_start"] + model.params["sf_trunc"] )
# this will work
_ = model.predict( model.theta, sps=sps, obs={"wavelength":None, "filters":None})
# Now make the new tage younger than the old sf_start
model.params["sf_start"] = 0.1
model.params["tage"] = 0.5*( model.params["sf_start"] + model.params["sf_trunc"] )
# this will fail
_ = model.predict( model.theta, sps=sps, obs={"wavelength":None, "filters":None})
Here is the full error code:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-12-77dec1eb0718> in <module>
----> 1 _ = model.predict( model.theta, sps=sps, obs={"wavelength":None, "filters":None})
~/venv3/lib/python3.9/site-packages/prospect/models/sedmodel.py in predict(self, theta, obs, sps, sigma_spec, **extras)
72 # generate and cache model spectrum and info
73 self.set_parameters(theta)
---> 74 self._wave, self._spec, self._mfrac = sps.get_galaxy_spectrum(**self.params)
75 self._zred = self.params.get('zred', 0)
76 self._eline_wave, self._eline_lum = sps.get_galaxy_elines()
~/venv3/lib/python3.9/site-packages/prospect/sources/galaxy_basis.py in get_galaxy_spectrum(self, **params)
106 # Loop over mass components
107 for i, m in enumerate(mass):
--> 108 self.update_component(i)
109 wave, spec = self.ssp.get_spectrum(tage=self.ssp.params['tage'],
110 peraa=False)
~/venv3/lib/python3.9/site-packages/prospect/sources/galaxy_basis.py in update_component(self, component_index)
80 this_v = v
81
---> 82 self.ssp.params[k] = deepcopy(this_v)
83
84 def get_galaxy_spectrum(self, **params):
~/venv3/lib/python3.9/site-packages/fsps/fsps.py in __setitem__(self, k, v)
1304
1305 self._params[k] = v
-> 1306 self.check_params()
~/venv3/lib/python3.9/site-packages/fsps/fsps.py in check_params(self)
1281 6
1282 ), "imf_type={0} out of range [0, 5]".format(self._params["imf_type"])
-> 1283 assert (self._params["tage"] <= 0) | (
1284 self._params["tage"] > self._params["sf_start"]
1285 ), "sf_start={0} is greater than tage={1}".format(
AssertionError: sf_start=2.1 is greater than tage=1.55