naima icon indicating copy to clipboard operation
naima copied to clipboard

Add a function to get a best-fit metadata blob

Open astrolog1986 opened this issue 8 years ago • 2 comments

Hi,

Sorry just a question about saving the results with naima. When the particle distribution are saved as a metadata blob as electron_e = np.logspace(11, 15, 100) * u.eV electron_dist = ECPL(electron_e)

# The first object returned must be the model photon spectrum, and
# subsequent objects will be stored as metadata blobs
return IC(data), (electron_e, electron_dist), We

it plots the electron distribution versus electron energy. Is there any way to save spectrum with best parameters in a ascii file, for example: electron_e electron_dist $$$$ $$$$$ $$$$ $$$$$ ....... ......... Thank you in advance

astrolog1986 avatar Aug 12 '16 12:08 astrolog1986

@astrolog1986 - There is a function in the plot module that allows you to obtain this sort of information, but currently it is only used used internally. The function is naima.plot.find_ML. The function takes a sampler and lets you specify the index of the blob for which you want to obtain the ML (maximum likelihood) value. For your example above, the index would be 1. This how you can use it (I assume a sampler that has already been run stored in the variable sampler):

from naima.plot import find_ML
ML, ML_params, ML_err, ML_model = find_ML(sampler, 1)

The four items returned are:

  • ML: The value of the loglikelihood for the returned model (which is the highest among all the samples).
  • ML_params: A tuple of the parameters that result in the maximum likelihood.
  • ML_err: A 1-sigma estimate of the confidence interval for each of the parameters considering all the samples.
  • ML_model: The model corresponding to the highest likelihood. The shape of this variable will always be (model_energy, model_value), and corresponds to the values saved in the metadata blobs.

zblz avatar Jan 26 '17 17:01 zblz

It might be worthwile to have a high-level function that does this and only returns the metadata blob of interest, so I'll keep the issue open and rename it to add that function.

zblz avatar Jan 26 '17 17:01 zblz