keflavich / dust_emissivity

Dust mass & emissivity calculation tools based on astropy's units framework
6 stars 7 forks source link

fit_modified_bb not creating Parameters object #8

Closed SpacialTree closed 2 years ago

SpacialTree commented 2 years ago

While attempting to create a modified blackbody fit, encountered the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-144-dff09ed1ff9b> in <module>
----> 1 dust_emissivity.fit_sed.fit_modified_bb(xdata=u.Quantity([p[0] for p in sed]).to(u.Hz, u.spectral()),
      2                                         flux=u.Quantity([p[1] for p in sed]),
      3                                         error=u.Quantity([1*u.Jy for p in sed]),
      4                                         guesses=[50*u.K, 2, 1e22*u.cm**-2],
      5                                         fitter='lmfit'

/blue/adamginsburg/adamginsburg/repos/dust_emissivity/dust_emissivity/fit_sed.py in fit_modified_bb(xdata, flux, error, guesses, fitter, return_error, **kwargs)
     69 
     70     if fitter == 'lmfit':
---> 71         lm = fit_sed_lmfit_hz(xdata=x, flux=fx, guesses=guesses, err=err,
     72                               blackbody_function='modified', **kwargs)
     73 

/blue/adamginsburg/adamginsburg/repos/dust_emissivity/dust_emissivity/fit_sed.py in fit_sed_lmfit_hz(xdata, flux, guesses, err, blackbody_function, quiet, sc, **kwargs)
    299                    ]
    300         guesspars = lmfit.Parameters()
--> 301         guesspars.update(OrderedDict(parlist),)
    302     else:
    303         guesspars = guesses

/orange/adamginsburg/miniconda3/envs/python38/lib/python3.8/site-packages/lmfit/parameter.py in update(self, other)
     72         """Update values and symbols with another Parameters object."""
     73         if not isinstance(other, Parameters):
---> 74             raise ValueError(f"'{other}' is not a Parameters object")
     75         self.add_many(*other.values())
     76         for sym in other._asteval.user_defined_symbols():

ValueError: 'OrderedDict([('T', <Parameter 'T', value=50.0, bounds=[-inf:inf]>), ('beta', <Parameter 'beta', value=2, bounds=[-inf:inf]>), ('N', <Parameter 'N', value=1e+22, bounds=[-inf:inf]>)])' is not a Parameters object

Suggestion: Instead of guesspars.update(), use guesspars.add() for individual parameters and guesspars.add_many() for multiple (sequence of tuples or Parameter objects) at once.