code: def gaussian_filter1d_ppxf(spec, sig):
      
      sig = sig.clip(0.01)  # forces zero sigmas to have 0.01 pixels
      p = int(np.ceil(np.max(3*sig)))
      m = 2*p + 1  # kernel size
      x2 = np.linspace(-p, p, m)**2
  
      n = spec.size
      a = np.zeros((m, n))
      # fig, ax = plt.subplots(1, 1, figsize=(16, 10))
  
      for j in range(m):   # Loop over the small size of the kernel
          #print j, n-m+j+1
          indices = n-m+j+1
          a[j,:] = spec
          a[j, p:-p] = spec[j:n-m+j+1]
          # ax.plot(waveData, a[j,:], label=j)
  
      # ax.update({'xlabel': 'Wavelength (nm)', 'ylabel': 'Flux (normalised)'})
      # ax.legend()
      # plt.show()
  
      gau = np.exp(-x2[:, None]/(2*sig**2))
      gau /= np.sum(gau, 0)[None, :]  # Normalize kernel
  
      conv_spectrum = np.sum(a*gau, 0)
  
      return conv_spectrum
docs: Convolve a spectrum by a Gaussian with different sigma for every pixel.
      If all sigma are the same this routine produces the same output as
      scipy.ndimage.gaussian_filter1d, except for the border treatment.
      Here the first/last p pixels are filled with zeros.
      When creating a template library for SDSS data, this implementation
      is 60x faster than a naive for loop over pixels.
  
      :param spec: vector with the spectrum to convolve
      :param sig: vector of sigma values (in pixels) for every pixel
      :return: spec convolved with a Gaussian with dispersion sig