title: Fixing phase unwrapping errors in Numpy
body: <p>I have a series of unwrapped phases, with some unwrapping errors that consist of a jump of +/- a multiple of Pi:</p>
  
  <pre><code>import numpy
  a = numpy.array([0.5, 1.3, 2.4, 10.3, 10.8, 10.2, 7.6, 3.2, 2.9])
  </code></pre>
  
  <p>In this example there is a first jump of 2 cycles between 2.4 and 10.3, and a jump of -1 cycle between 7.6 and 3.2. I want to remove the jumps. The catch is that when you remove a jump, you need to increase or decrease the rest of the series accordingly, not just the value where the jump occurs.</p>
  
  <p>Is there a cleaner way (no/less loops, faster) of doing this:</p>
  
  <pre><code>jumpsexist = 1
  while jumpsexist:
      # Look for absolute differences greater than Pi
      jump = numpy.abs((numpy.roll(a,-1) -a)) &gt; numpy.pi
      if jump[:-1].any():
          # Find the index of the first jump
          jumpind = numpy.argmax(jump) + 1
          # Calculate the number of cycles in that jump
          cycles = ((a[jumpind] - a[jumpind- 1]) / numpy.pi).astype("Int8")
          # Remove the cycles
          a[jumpind:] -= cycles * numpy.pi
      else:
          break
  </code></pre>