0

I'm trying to calculate the discrete derivative using gaussian_filter from scipy.ndimage and so the output is presenting some strange behavior with boundary conditions. The code is below:

from scipy import ndimage
import numpy as np
import matplotlib.pyplot as plt

y = np.linspace(0.2*np.pi,0.7*np.pi,100)
U = np.sin(y)


sg = 1
Uy  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='constant',cval=0)
Uy2  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='nearest')
Uy3  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='reflect')
Uy4  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='mirror')
Uy5  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='wrap')


fig,(a1,a2) = plt.subplots(1,2)
a1.plot(U , y,label='data')
a2.plot(Uy, y,label='constant')
a2.plot(Uy2,y,label='nearest')
a2.plot(Uy3,y,label='reflect')
a2.plot(Uy4,y,label='mirror')
a2.plot(Uy5,y,label='wrap')
a1.legend(loc='best')
a2.legend(loc='best')

enter image description here

What happened? Constant mode should result cval on boudary? Is that the expected result?

iury simoes-sousa
  • 1,440
  • 3
  • 20
  • 37
  • why do you think that you can get the discrete derivative of an array using the gaussian filter? What do you expect to have as output? – Jalo Nov 16 '16 at 15:04
  • The "order" arg is the order of discrete derivative tha will be calculated. As you can see on stackoverflow.com/questions/18991408/python-finite-difference-functions – iury simoes-sousa Nov 16 '16 at 15:11
  • 1
    The function does not substitute values on borders by *cval*. Instead, it "fills past edges of input" to cval. This is the same as saying that it supposes that all the points out of bounds are equal to *cval=0*, and thus the borders will be influenced by the following points – Jalo Nov 16 '16 at 15:23
  • Ok. So.. maybe it's not what I need.. – iury simoes-sousa Nov 16 '16 at 15:33

0 Answers0