I am asking because I encounter something very strange. The following method throws an exception when called from within a script:
def gaussian_blur(self, in_array, size):
# expand in_array to fit edge of kernel
padded_array = np.pad(in_array, (10,), 'reflect')
# build kernel
x, y = np.mgrid[-size:size + 1, -size:size + 1]
g = np.exp(-(x**2 / float(size) + y**2 / float(size)))
g = (g / g.sum()).astype(in_array.dtype)
# do the Gaussian blur
return fftconvolve(padded_array, g, mode='valid')
Traceback (most recent call last):
File "raster_tools/smooth.py", line 130, in <module>
blurred = ri.gaussian_blur(my_array, 10)
File "raster_tools/smooth.py", line 80, in gaussian_blur
padded_array = np.pad(in_array, (10,), 'reflect')
File "/home/.virtualenvs/geo/local/lib/python2.7/site-packages/numpy/lib/arraypad.py", line 1358, in pad
kwargs)
File "/home/.virtualenvs/geo/local/lib/python2.7/site-packages/numpy/lib/shape_base.py", line 91, in apply_along_axis
res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
TypeError: 'unicode' object is not callable
When I set a breakpoint using ipdb and then call
padded_array = np.pad(in_array, (10,), 'reflect')
(and all other lines of codes in the function as well by the way) the error won't occur. As the python script is being called within an virtual environment I could imagine that ipdb
is using a different interpreter. Even though running the code outside the virtual env gives the same behavior.