Closed jensmelinder closed 2 months ago
Hi @jensmelinder (cc @jwan)
For the stochastic SFH prior you need to use a special SpecModel
subclass that overrides the prior_product
method:
from prospect.models import sedmodel, templates
model_params = template.TemplateLibrary["stochastic_sfh"]
model = sedmodel.HyperSpecModel(model_params)
print(model.prior_product(model.theta))
In v1.4.0 this yields a scalar for me, which should fix the error during fitting. We should improve the documentation to mention this. Note that HyperSpecModel
is just
from prospect.models.hyperparameters import ProspectorHyperParams
from prospect.models.sedmodel import SpecModel
class HyperSpecModel(ProspectorHyperParams, SpecModel):
pass
The warning has to do with a bug in how prior lengths are computed, which because of the covariance matrix for logsfr_ratios
returns (N_bin -1)**2
instead of just N_bin-1
for that prior. I think it can be safely ignored.
Also, just want to make sure that you really want to ignore stars younger than 1 Myr, which can be important for the SED, with the agebins that you are using.
Hope this helps, Ben
Thanks a lot! I figured that there was some documentation missing there. Will try with HyperSpecModel
.
Yeah, I was just testing with the agebins and wanted something non-zero to not get log errors (but perhaps the code deals with that anyway).
Yes, 0 corresponds to 1 year - the code extrapolates the youngest available SSP to cover these very recent ages.
The fitting worked just fine after making the change. Feel free to close this (I'll check and close it within a few days otherwise). Thanks again for the prompt reply.
Just one more question about the Stochastic SFH if I may. To transform the logsfr_ratios into SFRs can I use the Continuity SFH transform function (transforms.logsfr_ratios_to_sfrs
)? I couldn't find a convenience function for this for the Stochastic SFH, but I don't think that conversion depends on the prior so it should be ok?
Great, glad it worked. And yes, it should be ok to use the regular transform for SFRs, as you say the conversion itself does not depend on the prior.
Hi, I'm having some problems running the StochasticSFH binned SFH treatment. My code runs fine with the parametric fitting and the binned Dirichlet mode SFH, but with StochasticSFH I get a warning (see below) and then the code fails with an error message. I'm not sure these are related (it could be me giving the wrong inputs to initialize the model).
I'm fitting a SED for a high-z galaxy with known spectroscopic redshift, and I'm thus using the priors and recommendations from Wan+24, with the exception of dust where I use the simpler 1-parameter model (dust:0 in FSPS), and keeping the gas parameters fixed.
I'm using prospector v1.4.0.
My code for building the model is:
Running this function throws the warning:
However, as far as I can see the prior seems to have the correct length. It also throws the same error with the default parameters. As far as I understand, the number of logsfr_ratios (and priors on them) should be one less than the number of agebins (so 6 ratios and 7 agebins in my case).
I include nebular emission and IGM transmission in the model. I also have a build_obs function that reads the data (this seems to be ok since the parametric and Dirichlet SFH runs work fine), and I initialize FSPS with:
I then run the actual fitting with:
The run then fails with this error message (also including the model params in the beginning):
I'm guessing this indicates that there are problems with the calculated values in lnp_prior, but I'm at a loss trying to figure out what went wrong, and if it is related to the earlier runtime warning. Would be grateful for any help with this.