def _do_lorentzian_fit(freqs, signal, bounds=None):
   """

   Helper function, so that Lorentzian fit can be generalized to different
   frequency scales (Hz and ppm).
   
   """
   # Use the signal for a rough estimate of the parameters for initialization:
   max_idx = np.argmax(np.real(signal))
   max_sig = np.max(np.real(signal))
   initial_f0 = freqs[max_idx]
   half_max_idx = np.argmin(np.abs(np.real(signal) - max_sig/2))
   initial_hwhm = np.abs(initial_f0 - freqs[half_max_idx])
   # Everything should be treated as real, except for the phase!
   initial_ph = np.angle(signal[signal.shape[-1]/2.])

   initial_off = np.min(np.real(signal))
   initial_drift = 0
   initial_a = (np.sum(np.real(signal)[max_idx:max_idx +
                              np.abs(half_max_idx)*2]) ) * 2

   initial = (initial_f0,
              initial_a,
              initial_hwhm,
              initial_ph,
              initial_off,
              initial_drift)

   params, _ = lsq.leastsqbound(mopt.err_func, initial,
                                args=(freqs, np.real(signal), ut.lorentzian),
                                bounds=bounds)
   return params
def _do_lorentzian_fit ( freqs , signal , bounds = None ) : max_idx = np . argmax ( np . real ( signal ) ) max_sig = np . max ( np . real ( signal ) ) initial_f0 = freqs [ max_idx ] half_max_idx = np . argmin ( np . abs ( np . real ( signal ) - max_sig / 2 ) ) initial_hwhm = np . abs ( initial_f0 - freqs [ half_max_idx ] ) initial_ph = np . angle ( signal [ signal . shape [ - 1 ] / 2. ] ) initial_off = np . min ( np . real ( signal ) ) initial_drift = 0 initial_a = ( np . sum ( np . real ( signal ) [ max_idx : max_idx + np . abs ( half_max_idx ) * 2 ] ) ) * 2 initial = ( initial_f0 , initial_a , initial_hwhm , initial_ph , initial_off , initial_drift ) params , _ = lsq . leastsqbound ( mopt . err_func , initial , args = ( freqs , np . real ( signal ) , ut . lorentzian ) , bounds = bounds ) return params
Helper function, so that Lorentzian fit can be generalized to different
   frequency scales (Hz and ppm).