These are chat archives for astropy/astropy

20th
Mar 2017
Aarya Patil
@AustereCuriosity
Mar 20 2017 06:55
I'm trying to solve issue #5845. What I am doing is that after the CParser supplies the data as a dictionary of numpy arrays, I'm converting the arrays in place according to the converters specified.
Thomas Spriggs
@tspriggs
Mar 20 2017 14:11
I have made a custom Guassian model using the class definition, having defined the model and the derivs, it throws up the error that the fit_deriv() takes 4 arguments, but is given 5... I can't seem to find out where this 5th element is coming from
matrixbot
@matrixbot
Mar 20 2017 15:09
bsipocz @tspriggs - could you paste an example with a full traceback?
matrixbot
@matrixbot
Mar 20 2017 15:30
Cadair @tspriggs is it 'self' that one often gets me
bsipocz @Cadair - "self" is my suspect, too, but we should spot if that the case with an example
Cadair :)
Thomas Spriggs
@tspriggs
Mar 20 2017 16:17
sure, give me a sec
' class Gaussian_OIII(Fittable1DModel):
amplitude_0 = Parameter()
mean_0 = Parameter()
stddev_0 = Parameter()
@staticmethod
def evaluate(x, amplitude_0, mean_0, stddev_0):
    return (amplitude_0 * np.exp(- 0.5 * (x - mean_0) ** 2 / stddev_0 ** 2) + (1/3)*amplitude_0 * np.exp(- 0.5 * (x - (mean_0 - 48.75) ** 2 / stddev_0 ** 2)))


def fit_deriv(x, amplitude_0, mean_0, stddev_0):
    d_amplitude_0 = np.exp(-0.5 * ((x - mean_0) ** 2)/ (stddev_0 ** 2)) + (1/3 * np.exp(- 0.5 * (x - (mean_0 - 48.75) ** 2 / stddev_0 ** 2)))
    d_mean_0 = (amplitude_0 * np.exp(-0.5 * ((x - mean_0) ** 2)/ (stddev_0 ** 2)) * (x - mean_0) / stddev_0 ** 2) + (-(1/3) * amplitude_0 * (x-mean_0 - 48.75) *np.exp(- 0.5 * (x - mean_0 - 48.75) ** 2 / stddev_0 ** 2))/stddev_0**2
    d_stddev_0 = amplitude_0 * np.exp(-0.5 * ((x - mean_0) ** 2)/ (stddev_0 ** 2)) * (x - mean_0) ** 2 / stddev_0 ** 3 + ((1/3) * amplitude_0 * (x-mean_0 - 48.75)**2 * np.exp(- 0.5 * (x - mean_0 - 48.75) ** 2 / stddev_0 ** 2)/stddev_0**3)
    return [d_amplitude_0, d_mean_0, d_stddev_0]
 '

'
RuntimeWarning: overflow encountered in exp
return (amplitude_0 np.exp(- 0.5 (x - mean_0) 2 / stddev_0 2) + (1/3)amplitude_0 np.exp(- 0.5 (x - (mean_0 - 48.75) * 2 / stddev_0 2)))

<matplotlib.figure.Figure at 0x12e4379ac50>
Traceback (most recent call last):

File "<ipython-input-1-67cec5a03f65>", line 1, in <module>
runfile('C:/Users/Thomas Spriggs/Desktop/PNe_project/gaussian_fit.py', wdir='C:/Users/Thomas Spriggs/Desktop/PNe_project')

File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)

File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Thomas Spriggs/Desktop/PNe_project/gaussian_fit.py", line 118, in <module>
g_fit = fitter(g_init, wavelength, flux_density)

File "C:\Anaconda3\lib\site-packages\astropy\modeling\fitting.py", line 560, in call
xtol=acc, full_output=True)

File "C:\Anaconda3\lib\site-packages\scipy\optimize\minpack.py", line 390, in leastsq
_check_func('leastsq', 'Dfun', Dfun, x0, args, n, (n, m))

File "C:\Anaconda3\lib\site-packages\scipy\optimize\minpack.py", line 26, in _check_func
res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))

File "C:\Anaconda3\lib\site-packages\astropy\modeling\fitting.py", line 620, in _wrapderiv
return [np.ravel(
) for _ in np.ravel(weights) np.array(model.fit_deriv(x, params))]

TypeError: fit_deriv() takes 4 positional arguments but 5 were given
'

sorry for the format :/
Aarya Patil
@AustereCuriosity
Mar 20 2017 17:36
========= 6 failed, 1535 passed, 76 skipped, 6 xfailed in 113.78 seconds ==========
I've run the tests for the issue #5845
I'm getting TypeError: unhashable type: 'numpy.ndarray'
For all the failed tests.
converters = self.converters.get(col_name, None), gives this error. The converters attribute is the converters parameter passed for reading and if not passed it's None.
should I open a pull request with the errors or can someone help me out a little? :/
Aarya Patil
@AustereCuriosity
Mar 20 2017 17:46
Oh, I spoke a little too fast. Found the error.
Aarya Patil
@AustereCuriosity
Mar 20 2017 18:48
@tspriggs I think what Cadair said is right. In your code the evaluate method is the static method but fit_deriv isn't. So it would receive self as a parameter.
Thomas Spriggs
@tspriggs
Mar 20 2017 19:00
ah ok, what's the best way round this? as I can't see too many differences between this code and the official Gaussian1D code
Aarya Patil
@AustereCuriosity
Mar 20 2017 19:01
I guess adding a self parameter to fit_deriv would solve it.
Since the error is with model.fit_deriv(x, params)