zblz / naima

Derivation of non-thermal particle distributions through MCMC spectral fitting
http://naima.readthedocs.io
BSD 3-Clause "New" or "Revised" License
45 stars 54 forks source link

Problem with plot_fit #140

Closed tibaldo closed 5 years ago

tibaldo commented 7 years ago

I was trying to print out full models covering a certain energy range (not just limited to the energy range covered by the datasets) plot_fit(sampler,e_range=[1.e3*u.eV,1.e14*u.eV],figure=fig) and got the following error (exert)

----> 1 p.map(partial(sampler.modelfn,data=data), pars)

/Users/ltibaldo/anaconda/envs/naima-turbB/lib/python2.7/site-packages/naima-0.8-py2.7.egg/naima/extern/interruptible_pool.pyc in map(self, func, iterable, chunksize)
     92         while True:
     93             try:
---> 94                 return r.get(self.wait_timeout)
     95             except TimeoutError:
     96                 pass

/Users/ltibaldo/anaconda/envs/naima-turbB/lib/python2.7/multiprocessing/pool.pyc in get(self, timeout)
    565             return self._value
    566         else:
--> 567             raise self._value
    568 
    569     def _set(self, i, obj):

TypeError: model() got an unexpected keyword argument 'data'

Could this be a coding bug or am I doing something wrong?

zblz commented 7 years ago

@tibaldo - naima here assumes that the model function that was passed to the sampler has a parameter called data, which is not necessarily true as we only require positional arguments and not keyword arguments for the provided model. Short term, calling the second argument of your model data will fix it. I'll write a failing test in a branch and find another way of getting the partial function without using named arguments.

zblz commented 7 years ago

I've found a fix (see #151), but it only works for Python > 3.3...