Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prospector doesn't save model to h5 file #339

Open
grotova opened this issue Aug 31, 2024 · 1 comment
Open

Prospector doesn't save model to h5 file #339

grotova opened this issue Aug 31, 2024 · 1 comment

Comments

@grotova
Copy link

grotova commented Aug 31, 2024

Hello, could you please help me to solve an issue:

after running my fit I try to save output to h5 file,

from prospect.io import write_results as writer
hfile = name+".h5"
writer.write_hdf5(hfile=hfile,
run_params=run_params,
model=model,
obs=obs,
sampler=output["sampling"][0],
optimize_result_list=output["optimization"][0],
tsample=output["sampling"][1],
toptimize=output["optimization"][1],
sps=sps)

however, when I then read it to do the plotting:

import prospect.io.read_results as reader
filename = "J1401_24Aug31-13.47.h5"
results1, obs1, model1 = reader.results_from(filename)

model1 = None
This causes issues when I try to use plotting functions provided.

Right before saving my model gives a normal output:
:::::::
<class 'prospect.models.sedmodel.SedModel'>

Free Parameters: (name: prior)

mass: <class 'prospect.models.priors.LogUniform'>(mini=1000000.0,maxi=1000000000000.0)
logzsol: <class 'prospect.models.priors.TopHat'>(mini=-2,maxi=0.19)
dust2: <class 'prospect.models.priors.TopHat'>(mini=0.0,maxi=2.0)
tage: <class 'prospect.models.priors.TopHat'>(mini=0.001,maxi=13.8)
tau: <class 'prospect.models.priors.LogUniform'>(mini=0.1,maxi=100.0)

Fixed Parameters: (name: value [, depends_on])

zred: [0.031]
sfh: [4]
imf_type: [2]
dust_type: [2.]
lumdist: [135.92003034]
add_dust_emission: [ True]
duste_umin: [1.]
duste_qpah: [4.]
duste_gamma: [0.001]

Could you please help me what could be a reason for that?
My goal is to plot posteriors.

Best regards,
Iuliia

@bd-j
Copy link
Owner

bd-j commented Sep 1, 2024

Hi @grotova

When saving your fit results, make sure to include a line that saves the text of the parameter file. e.g.,

run_params["param_file"] = __file__

from prospect.io import write_results as writer
hfile = name+".h5"
writer.write_hdf5(hfile=hfile,
    run_params=run_params,
    model=model,
    obs=obs,
    sampler=output["sampling"][0],
    optimize_result_list=output["optimization"][0],
    tsample=output["sampling"][1],
    toptimize=output["optimization"][1],
    sps=sps)

If you want to get more information about what might be going wrong when reading the results, try this:

import prospect.io.read_results as reader
filename = "J1401_24Aug31-13.47.h5"
results1, obs1, model1 = reader.results_from(filename)
if model1 is None:
    model2 = reader.get_model(results1)
    print(model2)

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants