pwtools.num.order_similar¶
- pwtools.num.order_similar(arr, repeat=1, order=2)[source]¶
Band ordering algorithm. Uses up to quadradic extrapolation. Handles crossing points.
This can be used to order dispersion plots, for instance.
- Parameters:
arr (2d array (npoints, ndim)) – ndim 1d data streams with npoints each.
repeat (int) – 1: run 1 time, N: run recursively N times
order (int) – Order of extrapolation: 0 = next similar point, 1 = linear using the two last points, 2 = quadratic using the 3 last points
- Returns:
arr2 – Array with ordered data series.
- Return type:
like arr
Notes
The more points, the better. The first 1-2 steps should start smoothly or the algo will get confused. If you don’t get all crossing points resolved, try
repeat > 1
. But if the algo placed points from different data streams into one, you are lost. Then you can only use more points to make the extrapolation more precise.Examples
>>> import numpy as np >>> from pwtools import mpl, num >>> plt = mpl.plt >>> x = np.linspace(0,10,200) >>> a = np.array([np.sin(0.5*x), ... 1.2*np.cos(2*x), ... np.sin(2.5*(x-1.5)), ... 0.2*np.sin(x-1.1), ... 0.3*np.sin(x-1.1), ... ]).T >>> for ai in a: ... np.random.shuffle(ai) >>> plt.figure(); plt.plot(a); plt.title('raw data') >>> aa = num.order_similar(a, repeat=1, order=2) >>> plt.figure(); plt.plot(aa); plt.title('sorted, repeat=1, order=2') >>> aa = num.order_similar(a, repeat=2, order=1) >>> plt.figure(); plt.plot(aa); plt.title('sorted, repeat=2, order=1') >>> plt.show()