Unwrap by changing deltas between values to 2*pi complement. Unwrap radian phase `p` by changing absolute jumps greater than `discont` to their 2*pi complement along the given axis. Parameters ---------- p : array_like Input array. discont : float, optional
(p, discont=pi, axis=-1)
| 1470 | |
| 1471 | @array_function_dispatch(_unwrap_dispatcher) |
| 1472 | def unwrap(p, discont=pi, axis=-1): |
| 1473 | """ |
| 1474 | Unwrap by changing deltas between values to 2*pi complement. |
| 1475 | |
| 1476 | Unwrap radian phase `p` by changing absolute jumps greater than |
| 1477 | `discont` to their 2*pi complement along the given axis. |
| 1478 | |
| 1479 | Parameters |
| 1480 | ---------- |
| 1481 | p : array_like |
| 1482 | Input array. |
| 1483 | discont : float, optional |
| 1484 | Maximum discontinuity between values, default is ``pi``. |
| 1485 | axis : int, optional |
| 1486 | Axis along which unwrap will operate, default is the last axis. |
| 1487 | |
| 1488 | Returns |
| 1489 | ------- |
| 1490 | out : ndarray |
| 1491 | Output array. |
| 1492 | |
| 1493 | See Also |
| 1494 | -------- |
| 1495 | rad2deg, deg2rad |
| 1496 | |
| 1497 | Notes |
| 1498 | ----- |
| 1499 | If the discontinuity in `p` is smaller than ``pi``, but larger than |
| 1500 | `discont`, no unwrapping is done because taking the 2*pi complement |
| 1501 | would only make the discontinuity larger. |
| 1502 | |
| 1503 | Examples |
| 1504 | -------- |
| 1505 | >>> phase = np.linspace(0, np.pi, num=5) |
| 1506 | >>> phase[3:] += np.pi |
| 1507 | >>> phase |
| 1508 | array([ 0. , 0.78539816, 1.57079633, 5.49778714, 6.28318531]) |
| 1509 | >>> np.unwrap(phase) |
| 1510 | array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) |
| 1511 | |
| 1512 | """ |
| 1513 | p = asarray(p) |
| 1514 | nd = p.ndim |
| 1515 | dd = diff(p, axis=axis) |
| 1516 | slice1 = [slice(None, None)]*nd # full slices |
| 1517 | slice1[axis] = slice(1, None) |
| 1518 | slice1 = tuple(slice1) |
| 1519 | ddmod = mod(dd + pi, 2*pi) - pi |
| 1520 | _nx.copyto(ddmod, pi, where=(ddmod == -pi) & (dd > 0)) |
| 1521 | ph_correct = ddmod - dd |
| 1522 | _nx.copyto(ph_correct, 0, where=abs(dd) < discont) |
| 1523 | up = array(p, copy=True, dtype='d') |
| 1524 | up[slice1] = p[slice1] + ph_correct.cumsum(axis) |
| 1525 | return up |
| 1526 | |
| 1527 | |
| 1528 | def _sort_complex(a): |