Package: rdp-quick
rdp-quickThe Ramer-Douglas-Peucker algorithm can be used to decimate a curve into a similar curve with fewer points. (https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm)There are several python implementations of the Ramer-Douglas-Peucker algorithm, however, they can be slow
for large datasetsIn this library the Ramer-Douglas-Peucker is implemented using Numba (with eager compilation and cache) to speed up the algorithmFor very large sets starting we know that there will be sub-windows so we have functions to create more initial windows to speed up futher.
These include setting the number of windows, setting the number of points per window and computing the curvature of the route to determine starting windowsBasic usageSetuppip install rdp-quickSingle WindowThe simplest usage is to start with one window using the start and end point.fromrdp_quickimportrdp_single_initial_windowimportnumpyasnpnum_osc=20points_per_osc=200epsilon=0.01print("building points")n_pts=num_osc*points_per_oscx=np.arange(n_pts)/n_pts*num_osc*2.0*np.piy=np.sin(x)p=np.vstack([x,y]).astype(float).transpose()down_sampled_p=rdp_single_initial_window(p,epsilon)print(down_sampled_p.shape,p.shape)Using Curvature to InitialiseA more advanced method is to first compute the curvature and find peaks and use these peaks to define the initial windowsFor large datasets this should be much quicker than the basic usageThis method uses numpy gradient and scipy.signal find_peaks. Both these methods can use a number of named arguments.If you want to set these use the input dictionariesgradient_nargsandfind_peaks_nargsinrdp_windows_from_curvaturefromrdp_quickimportrdp_windows_from_curvatureimportnumpyasnpnum_osc=20points_per_osc=200epsilon=0.01print("building points")n_pts=num_osc*points_per_oscx=np.arange(n_pts)/n_pts*num_osc*2.0*np.piy=np.sin(x)p=np.vstack([x,y]).astype(float).transpose()down_sampled_p=rdp_windows_from_curvature(p,epsilon)print(down_sampled_p.shape,p.shape)Define Initial Number of Points Per WindowA simpler way of creating initial windows is to define the number of points per window.  The algorithm will then create
windows of this length (it may shorten or extend to better match the number of points) to initialise the algorith with.
Note: this will be faster that the basic usage, but may not be as optimumfromrdp_quickimportrdp_points_per_windowimportnumpyasnpnum_osc=20points_per_osc=200epsilon=0.01print("building points")n_pts=num_osc*points_per_oscx=np.arange(n_pts)/n_pts*num_osc*2.0*np.piy=np.sin(x)p=np.vstack([x,y]).astype(float).transpose()down_sampled_p=rdp_points_per_window(p,epsilon,points_per_osc)print(down_sampled_p.shape,p.shape)Define Initial Number of WindowsA simpler way of creating initial windows is to define the number of inital windows.  The algorithm will then create
this number of windows to initialise the algorith with.
Note: this will be faster that the basic usage, but may not be as optimumfromrdp_quickimportrdp_num_windowsimportnumpyasnpnum_osc=20points_per_osc=200epsilon=0.01print("building points")n_pts=num_osc*points_per_oscx=np.arange(n_pts)/n_pts*num_osc*2.0*np.piy=np.sin(x)p=np.vstack([x,y]).astype(float).transpose()down_sampled_p=rdp_num_windows(p,epsilon,num_osc)print(down_sampled_p.shape,p.shape)exampleshttps://github.com/DrJohnDale/rdp-quick/blob/main/example.pyhttps://github.com/DrJohnDale/rdp-quick/blob/main/example_curvature.pyDevelopmentClone the repoCreate virtual envpip install -r requirements.txtpip install -r requirements_test_and_dev.txtUse run_test.bat or run_text.sh to run the testsRun examples to see usage