title: Python 2D convolution without forcing periodic boundaries
body: <p>I'm modeling a disease problem where each individual in a 2D landscape has a transmissibility described by a (radial basis) kernel function. My goal is to convolve the kernel with the population density such that the output captures the transmission risks across the landscape.</p>
  
  <p>I performed the convolution using NumPy's 2D FFT and inverse-FFT functions. However, this forces a periodic/wrapped boundary condition in the result, which is unsuited for my model. Is there a way to convolve within the context of the original, fixed boundaries?</p>
  
  <pre><code>import numpy as np
  import random
  from math import *
  import matplotlib.pyplot as plt
  
  ''' Landscape parameters ''' 
  L = 10.
  nx = 100
  dx = L/nx
  hs = .5 * dx  # half-step
  ulist = np.linspace(hs, L-hs, nx)
  
  ''' Radial Basis Function Kernel '''
  alpha = 1.
  i, j = ulist.reshape(nx,1), ulist.reshape(1,nx)
  r = np.minimum(i-ulist[0], L-i+ulist[0])**2 + np.minimum(j-ulist[0], L-j+ulist[0])**2
  rbf = sqrt(1 / (2 * alpha ** 2))
  ker = np.exp(-(rbf * r) ** 2)
  ker = ker/np.sum(ker)
  
  ''' Population Density '''
  ido = np.random.randint(nx, size=(1000,2)).astype(np.int)
  og = np.zeros((nx,nx))
  np.add.at(og, (ido[:,0], ido[:,1]), 1)
  
  ''' Convolution via FFT and inverse-FFT '''
  v1 = np.fft.fft2(ker)
  v2 = np.fft.fft2(og)
  v0 = np.fft.ifft2(v1*v2)
  dd = np.abs(v0)
  
  plt.plot(ido[:,1], ido[:,0], 'ko', alpha=.5)
  plt.imshow(dd, origin='origin')
  plt.show()
  </code></pre>