class_docstr: A class to implement some FFT smoothers for Image objects.
  By default, this does a Gaussian kernel smooth. More choices
  would be better!
class_docstr_tok: ["A","class","to","implement","some","FFT","smoothers","for","Image","objects",".","By","default",",","this","does","a","Gaussian","kernel","smooth",".","More","choices","would","be","better","!"]
docstr: Apply smoothing to `inimage`
  
  Parameters
  ----------
  inimage : ``Image``
     The image to be smoothed.  Should be 3D.
  clean : bool, optional
     Should we call ``nan_to_num`` on the data before smoothing?
  is_fft : bool, optional
     Has the data already been fft'd?
  
  Returns
  -------
  s_image : `Image`
     New image, with smoothing applied
docstr_tok: ["Apply","smoothing","to","`","inimage","`","Parameters","--","--","--","--","--","inimage",":","``","Image","``","The","image","to","be","smoothed",".","Should","be","3D",".","clean",":","bool",",","optional","Should","we","call","``","nan_to_num","``","on","the","data","before","smoothing","?","is_fft",":","bool",",","optional","Has","the","data","already","been","fft","'d","?","Returns","--","--","--","-","s_image",":","`","Image","`","New","image",",","with","smoothing","applied"]
code: def smooth(self, inimage, clean=False, is_fft=False):
      """Apply smoothing to `inimage`
  
      Parameters
      ----------
      inimage : ``Image``
         The image to be smoothed.  Should be 3D.
      clean : bool, optional
         Should we call ``nan_to_num`` on the data before smoothing?
      is_fft : bool, optional
         Has the data already been fft'd?
  
      Returns
      -------
      s_image : `Image`
         New image, with smoothing applied
      """
      if inimage.ndim == 4:
          # we need to generalize which axis to iterate over.  By
          # default it should probably be the last.
          raise NotImplementedError(
              "Smoothing volumes in a 4D series "
              "is broken, pending a rethink"
          )
          _out = np.zeros(inimage.shape)
          # iterate over the first (0) axis - this is confusing - see
          # above
          nslice = inimage.shape[0]
      elif inimage.ndim == 3:
          nslice = 1
      else:
          raise NotImplementedError("expecting either 3 or 4-d image")
      in_data = inimage.get_fdata()
      for _slice in range(nslice):
          if in_data.ndim == 4:
              data = in_data[_slice]
          elif in_data.ndim == 3:
              data = in_data[:]
          if clean:
              data = np.nan_to_num(data)
          if not is_fft:
              data = self._presmooth(data)
          data *= self.fkernel
          data = fft.irfftn(data) / self.norms[self.normalization]
          gc.collect()
          _dslice = [slice(0, self.bshape[i], 1) for i in range(3)]
          if self.scale != 1:
              data = self.scale * data[_dslice]
          if self.location != 0.0:
              data += self.location
          gc.collect()
          # Write out data
          if in_data.ndim == 4:
              _out[_slice] = data
          else:
              _out = data
          _slice += 1
      gc.collect()
      slicer = tuple(
          slice(
              self._kernel.shape[i] // 2,
              self.bshape[i] + self._kernel.shape[i] // 2,
          )
          for i in range(len(self.bshape))
      )
      _out = _out[slicer]
      if inimage.ndim == 3:
          return Image(_out, coordmap=self.coordmap)
      else:
          # This does not work as written.  See above
          concat_affine = AffineTransform.identity("concat")
          return Image(
              _out, coordmap=product(self.coordmap, concat_affine)
          )
  
file_path: nipy/nipy/algorithms/kernel_smooth.py
imports: import gc
  import numpy
  import numpy.linalg
  from numpy import fft
  from nipy.core.api import AffineTransform, Image
  from nipy.core.reference.coordinate_map import product
  from nipy.utils import seq_prod
label_desc: Use image node_id 5 for calling the LinearFilter obj's underlying member method code with example usage: obj.smooth(inimage, clean, is_fft) and returns: Image, Image