docs: def _compute_deviations(self, sample, n):
          """
          Compute deviations from a perfect ellipse, based on the
          amplitudes and errors for harmonic "n". Note that we first
          subtract the first and second harmonics from the raw data.
          """
  
          try:
              coeffs = fit_first_and_second_harmonics(self.sample.values[0],
                                                      self.sample.values[2])
              coeffs = coeffs[0]
              model = first_and_second_harmonic_function(self.sample.values[0],
                                                         coeffs)
              residual = self.sample.values[2] - model
  
              c = fit_upper_harmonic(residual, sample.values[2], n)
              covariance = c[1]
              ce = np.diagonal(covariance)
              c = c[0]
  
              a = c[1] / self.sma / sample.gradient
              b = c[2] / self.sma / sample.gradient
  
              # this comes from the old code. Likely it was based on
              # empirical experience with the STSDAS task, so we leave
              # it here without too much thought.
              gre = self.grad_r_error if self.grad_r_error is not None else 0.64
  
              a_err = abs(a) * np.sqrt((ce[1] / c[1])**2 + gre**2)
              b_err = abs(b) * np.sqrt((ce[2] / c[2])**2 + gre**2)
  
          except Exception:    # we want to catch everything
              a = b = a_err = b_err = None
  
          return a, b, a_err, b_err