code: def fwhm_kernel(kernel):
      
      n = len(kernel)
      if n % 2 == 0:
          raise ValueError('only works with odd number of pixels in kernel!')
      max_flux = kernel[int((n-1)/2), int((n-1)/2)]
      I_2 = max_flux/2.
      I_r = kernel[int((n-1)/2), int((n-1)/2):]
      r = np.linspace(0, (n-1)/2, int((n + 1) / 2))
      for i in range(1, len(r)):
          if I_r[i] < I_2:
              fwhm_2 = (I_2 - I_r[i-1])/(I_r[i] - I_r[i-1]) + r[i-1]
              return fwhm_2 * 2
      raise ValueError('The kernel did not drop to half the max value - fwhm not determined!')
docs: computes the full width at half maximum of a (PSF) kernel
      :param kernel: (psf) kernel, 2d numpy array
      :return: fwhm in units of pixels