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

Super weird nu, nuFnu reported values after calling eval() #52

Closed
mireianievas opened this issue Nov 4, 2021 · 6 comments
Closed

Super weird nu, nuFnu reported values after calling eval() #52

mireianievas opened this issue Nov 4, 2021 · 6 comments

Comments

@mireianievas
Copy link

I have done a couple of fits:

image

image

I want to make the plot a bit nicer, so I explore each model component and plot it with matplotlib. I get:

image

image

I really don't understand this. I have all these Jet instances stored in a dict and I'm doing exactly the same eval() thing for all of them, and using the same plotting code. It is not a bug in the code because the weird output happens only sometimes, other times it is plot correctly. I have been dealing with this issue for months and I have found no logical pattern, maybe you can bring some light to it ??

PS. I also have other issues with jetset, like how the fit is done (e.g. why if I set a maximum of calls to 300 it does whatever it wants, being it 20 calls or 500?, or why if I set the starting parameters to a reasonable solution the minimizer goes crazy exploring a random part of the space parameter that is super far away from the initial parameter values) or why if I store the Jet models then recovering them brings me wrong parameters?. But for now let's concentrate on the plotting thing I presented before :P

@andreatramacere
Copy link
Owner

Dear Mireia, thanks a lot for using jeteset. Before going into the details may I ask you which version you are using?
I suggest you to install the release candidate of the new version: https://github.com/andreatramacere/jetset/releases/tag/1.2.0rc10
You can directly use the installer https://github.com/andreatramacere/jetset-installer, passing to the command line the argument 1.2.0rc10.
The documentation for the pre-release is here: https://andreatramacere.github.io/jetsetdoc/html/index.html
Now, coming to your issue. I should have a look at the code that you use to plot in matplotlib to understand what is going on. The other problem might be solved with the version that I am suggesting you to install.
Please, let me know how things evolve and how I can help you.
Cheers
Andrea

@mireianievas
Copy link
Author

I am using 1.1.2, the last stable I guess. I will try the pre-release you mention. Any big compatibility issue I need to know in advance?

One, maybe relevant bit, is that I have my own electron distribution defined. It is basically a broken power law, but defined in a way that it is always concave (i.e. redefining p_1 so that p_1' = abs(p_1 - p). Maybe (I'm not saying it is the reason) jetset 'forgets' at some point it is a custom distribution and uses a standard broken power law?

from jetset.jet_emitters import EmittersDistribution
def distr_func_bkn(gamma_break,gamma,p,p_1):
    return np.power(gamma,-np.abs(p))*(1.+(gamma/gamma_break))**(-np.abs(p_1))

bkn2=EmittersDistribution('bkn')
bkn2.add_par('gamma_break',par_type='turn-over-energy',val=1E3,vmin=1., vmax=None, unit='lorentz-factor')
bkn2.add_par('p',par_type='LE_spectral_slope',val=2.5,vmin=0., vmax=10, unit='')
bkn2.add_par('p_1',par_type='HE_spectral_slope',val=3.2,vmin=0., vmax=10, unit='')
bkn2.set_distr_func(distr_func_bkn)
bkn2.parameters.show_pars()
bkn2.parameters.p.val=2
bkn2.parameters.p_1.val=0.5

p=bkn2.plot3p()
p.fig

At least that would perhaps explain this non-sense SED

image

@andreatramacere
Copy link
Owner

So I found what happens, you called the distribution with the same name of the custom model, 'bkn'. Once you save the model, and you load it, the constructor is getting the custom one. In version 1.1.2 I have not implemented the serialization of the custom electron distribution. This is done with the version that I have suggested before, anyhow I found the solution for your problem, still using version 1.1.2. Use the code attached, and remember, once you load the model and then you update it with the saved custom distribution, run .eval() to update
custom_emitters_ditribution_serialization.ipynb.gz

@andreatramacere
Copy link
Owner

I have also pushed the notebook with the solution to the git repo that you share before.
Please, let me know if this solved your problem

@mireianievas
Copy link
Author

mireianievas commented Nov 5, 2021 via email

@andreatramacere
Copy link
Owner

Regarding compatibility, there might be minor changes. Just in case, share with me a piece of code with all the jetset steps that you are using, I will check if it is OK

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