code: def test_kernel():
      # Verify that convolution with a delta function gives the correct
      # answer.
      tol = 0.9999
      sdtol = 1.0e-8
      for x in range(6):
          shape = randint(30, 60 + 1, (3,))
          # pos of delta
          ii, jj, kk = randint(11, 17 + 1, (3,))
          # random affine coordmap (diagonal and translations)
          coordmap = AffineTransform.from_start_step(
              "ijk",
              "xyz",
              randint(5, 20 + 1, (3,)) * 0.25,
              randint(5, 10 + 1, (3,)) * 0.5,
          )
          # delta function in 3D array
          signal = np.zeros(shape)
          signal[ii, jj, kk] = 1.0
          signal = Image(signal, coordmap=coordmap)
          # A filter with coordmap, shape matched to image
          kernel = LinearFilter(
              coordmap, shape, fwhm=randint(50, 100 + 1) / 10.0
          )
          # smoothed normalized 3D array
          ssignal = kernel.smooth(signal).get_fdata()
          ssignal[:] *= kernel.norms[kernel.normalization]
          # 3 points * signal.size array
          I = np.indices(ssignal.shape)
          I.shape = (kernel.coordmap.ndims[0], np.prod(shape))
          # location of maximum in smoothed array
          i, j, k = I[:, np.argmax(ssignal[:].flat)]
          # same place as we put it before smoothing?
          assert (i, j, k) == (ii, jj, kk)
          # get physical points position relative to position of delta
          Z = kernel.coordmap(I.T) - kernel.coordmap([i, j, k])
          _k = kernel(Z)
          _k.shape = ssignal.shape
          assert np.corrcoef(_k[:].flat, ssignal[:].flat)[0, 1] > tol
          assert (_k[:] - ssignal[:]).std() < sdtol
  
          def _indices(i, j, k, axis):
              I = np.zeros((3, 20))
              I[0] += i
              I[1] += j
              I[2] += k
              I[axis] += np.arange(-10, 10)
              return I.T
  
          vx = ssignal[i, j, (k - 10) : (k + 10)]
          xformed_ijk = coordmap([i, j, k])
          vvx = coordmap(_indices(i, j, k, 2)) - xformed_ijk
          assert np.corrcoef(vx, kernel(vvx))[0, 1] > tol
          vy = ssignal[i, (j - 10) : (j + 10), k]
          vvy = coordmap(_indices(i, j, k, 1)) - xformed_ijk
          assert np.corrcoef(vy, kernel(vvy))[0, 1] > tol
          vz = ssignal[(i - 10) : (i + 10), j, k]
          vvz = coordmap(_indices(i, j, k, 0)) - xformed_ijk
          assert np.corrcoef(vz, kernel(vvz))[0, 1] > tol
  
file_path: nipy/nipy/algorithms/tests/test_kernel_smooth.py
imports: import numpy
  import pytest
  from numpy.random import randint
  from numpy.testing import assert_array_almost_equal
  from transforms3d.taitbryan import euler2mat
  from ...None import load_image
  from ...core.api import AffineTransform, Image, compose, drop_io_dim
  from ...testing import anatfile, funcfile
  from ..kernel_smooth import LinearFilter, fwhm2sigma, sigma2fwhm
label_desc: Use image node_id 5 for calling a global function with example usage: test_kernel() and returns: I