2

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.

LarsVegas
  • 6,522
  • 10
  • 43
  • 67
  • 1
    This question is lacking information how the code was executed in the first place. – Mikko Ohtamaa Aug 01 '15 at 18:23
  • What did you use? `python script_name.py`? What virtualenv? Reproduce it and `which python` tells you where the python interpreter actually is. – Joachim Aug 17 '15 at 16:14
  • 1
    I have the same TypeError when I call np.pad function. I run Python 2.7.10, anaconda installation. – phasselmann Nov 30 '15 at 16:16

0 Answers0