python - scipy fftconvolve claims input parameters don't have same dimensionality. What am I parsing? -


i'm trying create class uses fftconvolve scipy.signal convolve data gaussian inside method of class instance. every time create instance , call method enlarge_smooth (which happens upon right arrow key press), error fftconvolve stating: valueerror: in1 , in2 should have same dimensionality. happens in function def fftconvolve(in1, in2, mode="full"): when line elif not in1.ndim == in2.ndim: evaluates true. line print vals.ndim == gs.ndim prints true before call fftconvolve, , both vals , gs have dimensions (101,). if not parsing vals , gs fftconvolve parsing? , why doesn't work?

class smoother(object):     import sys     sys.path.append("/data/pythonfunktioner")     scipy.signal import fftconvolve     import pyximport; pyximport.install()     fitting6 import gs_smooth1     """     class allows user smooth function of 1 variable gaussian using fftconvolve while looking @ smoothed function. smoothing parameter changed arrow keys , chosen enter.     """      def __init__(self, data):         self.data = data         self.sigma = 1 #smallest possible sigma smoothing         self.arr = np.arange(len(self.data.get_ydata()), dtype='float64') - len(self.data.get_ydata())/2         self.stack = [data]         self.line = data         self.active = true      def connect(self):         self.cidkpress = self.data.figure.canvas.mpl_connect('key_press_event', self.key)      def key(self, event):         if event.key == 'right':             self.enlarge_smooth()         elif event.key == 'left':             self.lower_smooth()         elif event.key == 'enter':             self.term(event)      def enlarge_smooth(self):         if 0: #check if larger smooth in stack             pass#set larger smooth current         else:             gs = self.gs_smooth1(self.arr.copy(), self.sigma) #gaussian core centered @ 0             vals = self.data.get_ydata().copy()             print vals.ndim == gs.ndim             print vals.ndim, type(vals), vals.dtype             print gs.ndim, type(gs), gs.dtype #            print vals, type(vals), vals.dtype #            print gs, type(gs), gs.dtype             newsmooth = self.fftconvolve(vals, gs)             self.line = line2d(self.data.get_xdata(), newsmooth)             self.stack.append(self.line)      def lower_smooth(self):         if 1: #check if current smooth lowest possible             print "cannot smooth less. least smooth active."         else:             pass#set lesser smooth current      def term(self, event):         self.active = false         self.disconnect()      def disconnect(self):         self.data.figure.canvas.mpl_disconnect(self.cidkpress) 

i've tried parsing vals[0] , gs[0] check if parse 2 lists of length 101. turned out parse 2 scalars though, , ftconvolve` exit error: typeerror: unsupported operand type(s) *: 'smoother' , 'float'.

it looks though i'm parsing instance of class itself. can't see how.

if helps im testing class trough call following function

def smoothbf(datalist):     matplotlib import pyplot plt     in xrange(len(datalist)):         fig, axs = plt.subplots(nrows=1, ncols=1)         data, = axs.plot(datalist[i][0], datalist[i][1])         smoother = smoother(data)         smoother.connect()         while smoother.active:             plt.pause(0.1)         #return current result         plt.close(fig) 

where datalist list containing tuple (np.arange(101), np.random.random(101))

update: seems have importing fftconvolve inside class definition. adding print statements types , number of dimensions inside scipy fftconvolve function confims in1 somehow smoother type. gives different result when write from scipy.signal import fftconvolve in top of module istead of inside class definition , call newsmooth = fftconvolve(vals, gs) instead of newsmooth = self.fftconvolve(vals, gs). error message attributeerror: 'numpy.ndarray' object has no attribute 'ndims' fftconvolve.

your "trick" import fftconvolve inside class definition trips in end. unless haven't shown define smooth.fftconvolve elsewhere.

here's have now:

class smooth(object):     scipy.signal import fftconvolve      def enlarge_smooth(self):         # other stuff         self.fftconvolve(vals, gs) 

and when call

s = s() s.enlarge_smooth() 

fftconvolve called

fftconvolve(self, vals, gs) 

the solution simple: don't kind of trickery. instead, import fftconvolve outside class , call function directly:

from scipy.signal import fftconvolve  class smooth(object):      def enlarge_smooth(self):         # other stuff         fftconvolve(vals, gs) 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -