code: def convolve(data, kernel, method='scipy'):
      r
  
      if data.ndim != kernel.ndim:
          raise ValueError('Data and kernel must have the same dimensions.')
  
      if method not in ('astropy', 'scipy'):
          raise ValueError('Invalid method. Options are "astropy" or "scipy".')
  
      if not import_astropy:  # pragma: no cover
          method = 'scipy'
  
      if method == 'astropy':
          return convolve_fft(data, kernel, boundary='wrap', crop=False,
                              nan_treatment='fill', normalize_kernel=False)
  
      elif method == 'scipy':
          return scipy.signal.fftconvolve(data, kernel, mode='same')
docs: r"""Convolve data with kernel
  
      This method convolves the input data with a given kernel using FFT and
      is the default convolution used for all routines
  
      Parameters
      ----------
      data : np.ndarray
          Input data array, normally a 2D image
      kernel : np.ndarray
          Input kernel array, normally a 2D kernel
      method : str {'astropy', 'scipy'}, optional
          Convolution method (default is 'scipy')
  
      Returns
      -------
      np.ndarray convolved data
  
      Raises
      ------
      ValueError
          If `data` and `kernel` do not have the same number of dimensions
      ValueError
          If `method` is not 'astropy' or 'scipy'
  
      Notes
      -----
      The convolution methods are:
  
          'astropy':
              Uses the astropy.convolution.convolve_fft method provided in
              Astropy (http://www.astropy.org/)
  
          'scipy':
              Uses the scipy.signal.fftconvolve method provided in SciPy
              (https://www.scipy.org/)
  
      Examples
      --------
      >>> from math.convolve import convolve
      >>> import numpy as np
      >>> a = np.arange(9).reshape(3, 3)
      >>> b = a + 10
      >>> convolve(a, b)
      array([[ 534.,  525.,  534.],
             [ 453.,  444.,  453.],
             [ 534.,  525.,  534.]])
  
      >>> convolve(a, b, method='scipy')
      array([[  86.,  170.,  146.],
             [ 246.,  444.,  354.],
             [ 290.,  494.,  374.]])