[AstroPy] Ap.modeling.fitting.SLSQPLSQFitter() argument fails.

Éric Depagne eric at depagne.org
Mon Jan 8 07:21:28 EST 2018


Hi all.

I have a problem with SLSQPLSQFitter that seems to be related to the astropy/scipy version I'm 
using, but I can't find out why it's failing, so any help will be appreciated.

I have the following code:

def _gaussian_fit(self, a, k):
    from astropy.modeling import fitting, models
    fitter = fitting.SLSQPLSQFitter()
    gaus = models.Gaussian1D(amplitude=1., mean=a, stddev=5.)
	try:
		gfit = fitter(gaus, y, self.hrs.data[y, 50 * (k + 1)] / self.hrs.data[y, 50 * (k + 
1)].max(), verblevel=0)
	except IndexError:
		return

def find_orders(self, op):
	vgf = np.vectorize(self._gaussian_fit)
	for i in range(op.shape[1]):
		tt = vgf(op[:, i], i)
		fit[:, i] = tt
	positions[:, :, 0], positions[:, :, 1], positions[:, :, 2] = vadd(fit)
  
  
I have a virtual environnment where I'm using astropy v 2.0.1 and scipy v 0.19.1 and the code 
works as expected: it fits the data.

I am also running this code on the default version installed on my Ubuntu box, which are : astropy 
v 1.3 and scipy v 0.18.1 and in this case, I have the following error message:

/home/eric/stability/stability.py in find_orders(self, op)
    349         positions = np.zeros((op.shape[0], op.shape[1], 3))
    350         for i in range(op.shape[1]):
--> 351             tt = vgf(op[:, i], i)
    352             fit[:, i] = tt

/usr/lib/python3/dist-packages/numpy/lib/function_base.py in __call__(self, *args, **kwargs)
   2574             vargs.extend([kwargs[_n] for _n in names])
   2575 
-> 2576         return self._vectorize_call(func=func, args=vargs)
   2577 
   2578     def _get_ufunc_and_otypes(self, func, args):

/usr/lib/python3/dist-packages/numpy/lib/function_base.py in _vectorize_call(self, func, args)
   2644             res = func()
   2645         else:
-> 2646             ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
   2647 
   2648             # Convert args to object arrays first

/usr/lib/python3/dist-packages/numpy/lib/function_base.py in _get_ufunc_and_otypes(self, func, 
args)
   2604 
   2605             inputs = [arg.flat[0] for arg in args]
-> 2606             outputs = func(*inputs)
   2607 
   2608             # Performance note: profiling indicates that -- for simple

/home/eric/stability/stability.py in _gaussian_fit(self, a, k)
    325         y = np.arange(y1, y2)
    326         try:
--> 327             gfit = fitter(gaus, y, self.hrs.data[y, 50 * (k + 1)] / self.hrs.data[y, 50 * (k + 1)].max(), 
verblevel=0)
    328         except IndexError:
    329             return

/usr/lib/python3/dist-packages/astropy/modeling/fitting.py in __call__(self, model, x, y, z, weights, 
**kwargs)
    682         p0, _ = _model_to_fit_params(model_copy)
    683         fitparams, self.fit_info = self._opt_method(
--> 684             self.objective_function, p0, farg, **kwargs)
    685         _fitter_to_model_params(model_copy, fitparams)
    686 

/usr/lib/python3/dist-packages/astropy/modeling/optimizers.py in __call__(self, objfunc, initval, 
fargs, **kwargs)
    160             objfunc, initval, args=fargs, full_output=True,
    161             bounds=bounds, eqcons=eqcons, ieqcons=ineqcons,
--> 162             **kwargs)
    163 
    164         self.fit_info['final_func_val'] = final_func_val

TypeError: fmin_slsqp() got an unexpected keyword argument 'verblevel'


I have had a look on the astropy and scipy github to check whether the verblevel keyword had 
been added in between the versions (1.3 and 2.0) and/or (0.18.1 and 0.19.1), but it's not the case.

I know that 1.3 and 0.18 are old and not stable version anymore, so I can simply do a version check 
and have my code exit if they are too old, but I'd be interested in understanding where I am doing 
something wrong.

Thanks.

Éric.

-- 
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne                            

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20180108/218fd0bf/attachment.html>


More information about the AstroPy mailing list