code: def field2ap_corr(field):
      
      phase = unwrap.unwrap_phase(np.angle(field), seed=47)
      samples = []
      samples.append(phase[:, :3].flatten())
      samples.append(phase[:, -3:].flatten())
      samples.append(phase[:3, 3:-3].flatten())
      samples.append(phase[-3:, 3:-3].flatten())
      pha_offset = np.median(np.hstack(samples))
      num_2pi = np.round(pha_offset / (2 * np.pi))
      phase -= num_2pi * 2 * np.pi
      ampli = np.abs(field)
      return ampli, phase
docs: Determine amplitude and offset-corrected phase from a field
  
      The phase jumps sometimes appear after phase unwrapping.
  
      Parameters
      ----------
      field: 2d complex np.ndarray
          Complex input field
  
      Returns
      -------
      amp: 2d real np.ndarray
          Amplitude data
      pha: 2d real np.ndarray
          Phase data, corrected for 2PI offsets