Package: csaps
csapsis a Python package for univariate, multivariate and n-dimensional grid data approximation using cubic smoothing splines.
The package can be useful in practical engineering tasks for data approximation and smoothing.InstallingUse pip for installing:pip install -U csapsThe module depends only on NumPy and SciPy. Python 3.6 or above is supported.Simple ExamplesHere is a couple of examples of smoothing data.An univariate data smoothing:importnumpyasnpimportmatplotlib.pyplotaspltfromcsapsimportcsapsnp.random.seed(1234)x=np.linspace(-5.,5.,25)y=np.exp(-(x/2.5)**2)+(np.random.rand(25)-0.2)*0.3xs=np.linspace(x[0],x[-1],150)ys=csaps(x,y,xs,smooth=0.85)plt.plot(x,y,'o',xs,ys,'-')plt.show()A surface data smoothing:importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dfromcsapsimportcsapsnp.random.seed(1234)xdata=[np.linspace(-3,3,41),np.linspace(-3.5,3.5,31)]i,j=np.meshgrid(*xdata,indexing='ij')ydata=(3*(1-j)**2.*np.exp(-(j**2)-(i+1)**2)-10*(j/5-j**3-i**5)*np.exp(-j**2-i**2)-1/3*np.exp(-(j+1)**2-i**2))ydata=ydata+(np.random.randn(*ydata.shape)*0.75)ydata_s=csaps(xdata,ydata,xdata,smooth=0.988)fig=plt.figure(figsize=(7,4.5))ax=fig.add_subplot(111,projection='3d')ax.set_facecolor('none')c=[s['color']forsinplt.rcParams['axes.prop_cycle']]ax.plot_wireframe(j,i,ydata,linewidths=0.5,color=c[0],alpha=0.5)ax.scatter(j,i,ydata,s=10,c=c[0],alpha=0.5)ax.plot_surface(j,i,ydata_s,color=c[1],linewidth=0,alpha=1.0)ax.view_init(elev=9.,azim=290)plt.show()DocumentationMore examples of usage and the full documentation can be found athttps://csaps.readthedocs.io.TestingWe use pytest for testing.cd /path/to/csaps/project/directory
pip install -e .[tests]
pytestAlgorithm and ImplementationcsapsPython package is inspired by MATLABCSAPSfunction that is an implementation of
Fortran routine SMOOTH fromPGS(originally written by Carl de Boor).Also the algothithm implementation in other languages:csaps-rsRust ndarray/sprs based implementationcsaps-cppC++11 Eigen based implementation (incomplete)ReferencesC. de Boor, A Practical Guide to Splines, Springer-Verlag, 1978.LicenseMITChangelogv1.1.0Introduced optionalnormalizedsmoothargument to reduce dependence on xdata and weights#47Update numpy and scipy dependency rangesv1.0.4 (04.05.2021)Bump numpy dependency versionv1.0.3 (01.01.2021)Bump scipy dependency versionBump sphinx dependency version and use m2r2 sphinx extension instead of m2rAdd Python 3.9 to classifiers list and to Travis CISet development status classifier to "5 - Production/Stable"Happy New Year!v1.0.2 (19.07.2020)Fix using 'nu' argument when n-d grid spline evaluating#32v1.0.1 (19.07.2020)Fix n-d grid spline evaluating performance regression#31v1.0.0 (11.07.2020)UsePPolyandNdPPolybase classes from SciPy interpolate module forSplinePPFormandNdGridSplinePPFormrespectively.Remove deprecated classesUnivariateCubicSmoothingSplineandMultivariateCubicSmoothingSplineUpdate the documentationNotesIn this release the spline representation (the array of spline coefficients) has been changed
according toPPoly/NdPPoly.
See SciPyPPolyandNdPPolydocumentation for details.v0.11.0 (28.03.2020)Internal re-designSplinePPFormandNdGridSplinePPFormclasses#17:Removeshapeandaxisproperties and reshaping data in these classesNdGridSplinePPFormcoefficients array for 1D grid now is 1-d instead of 2-dRefactoring the code and decrease memory consumptionAddoverloadtype-hints forcsapsfunction signaturesv0.10.1 (19.03.2020)Fix call ofnumpy.padfunction for numpy <1.17#15v0.10.0 (18.02.2020)Significant performance improvements for make/evaluate splines and memory consumption optimizationChange format for storing spline coefficients (reshape coeffs array) to improve performanceAdd shape property toSplinePPForm/NdGridSplinePPFormand axis property toSplinePPFormFix issues with the smoothing factor in nd-grid case: inverted ordering and unnable to use 0.0 valueUpdate documentationv0.9.0 (21.01.2020)Drop support of Python 3.5weights,smoothandaxisarguments incsapsfunction are keyword-only nowUnivariateCubicSmoothingSplineandMultivariateCubicSmoothingSplineclasses are deprecated
and will be removed in 1.0.0 version. UseCubicSmoothingSplineinstead.v0.8.0 (13.01.2020)Addcsapsfunction that can be used as the main APIRefactor the internal structure of the packageAdd thedocumentationAttentionThis is the last version that supports Python 3.5.
The next versions will support Python 3.6 or above.v0.7.0 (19.09.2019)Add Generic-based type-hints and mypy-compatibilityv0.6.1 (13.09.2019)A slight refactoring and extra data copies removingv0.6.0 (12.09.2019)Add "axis" parameter for univariate/multivariate casesv0.5.0 (10.06.2019)Reorganize the project to package-based structureAdd the interface class for all smoothing spline classesv0.4.2 (07.09.2019)FIX: "smooth" value is 0.0 was not usedv0.4.1 (30.05.2019)First PyPI release