{ "info": { "author": "Eugene Prilepin", "author_email": "esp.home@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Mathematics", "Topic :: Software Development :: Libraries" ], "description": "# CSAPS: Cubic spline approximation (smoothing)\n\n[![PyPI version](https://img.shields.io/pypi/v/csaps.svg)](https://pypi.python.org/pypi/csaps)\n[![Build status](https://travis-ci.org/espdev/csaps.svg?branch=master)](https://travis-ci.org/espdev/csaps)\n![Supported Python versions](https://img.shields.io/pypi/pyversions/csaps.svg)\n[![License](https://img.shields.io/pypi/l/mpl-events.svg)](LICENSE)\n\nThis module provides cubic smoothing spline for univariate/multivariate/gridded data approximation.\nThe smoothing parameter can be calculated automatically or it can be set manually. \n\nThe smoothing parameter should be in range `[0, 1]` where bounds are:\n* 0: The smoothing spline is the least-squares straight line fit to the data\n* 1: The natural cubic spline interpolant\n\nThe calculation of the smoothing spline requires the solution of a linear system \nwhose coefficient matrix has the form `p*A + (1 - p)*B`, with the matrices `A` and `B` \ndepending on the data sites `X`. The automatically computed smoothing parameter makes \n`p*trace(A) equal (1 - p)*trace(B)`.\n\n## Installation\n\nPython 3.5 or above is supported.\n\n```\npip install csaps\n```\n\nThe module depends only on NumPy and SciPy.\n\nOn Windows we highly recommend to use unofficial builds [NumPy+MKL](https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) \nand [SciPy](https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy) from Christoph Gohlke.\n\n```\n> mkdir depends\n\ndownload numpy (https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy) to \"depends\" directory\ndownload scipy (https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy) to \"depends\" directory\n\n> pip install --find-links depends/ csaps\n```\n\n## Smoothing univariate data\n\nUnivariate data are two vectors: X and Y with the same size. X is data sites, Y is data values.\nFor univariate case X-values must satisfy the condition: `x1 < x2 < ... < xN`.\n\nYou can use `UnivariateCubicSmoothingSpline` class for uivariate data smoothing.\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport csaps\n\nnp.random.seed(1234)\n\nx = np.linspace(-5., 5., 25)\ny = np.exp(-(x/2.5)**2) + (np.random.rand(25) - 0.2) * 0.3\n\nsp = csaps.UnivariateCubicSmoothingSpline(x, y, smooth=0.85)\n\nxs = np.linspace(x[0], x[-1], 150)\nys = sp(xs)\n\nplt.plot(x, y, 'o', xs, ys, '-')\nplt.show()\n```\n\n![csaps1d](https://user-images.githubusercontent.com/1299189/27611703-f3093c14-5b9b-11e7-9f18-6d0c3cc7633a.png)\n\n### Smoothing weighted univariate data\n\nThe algorithm supports weighting. You can set weights vector that will determine \nweights for all data values:\n\n```python\nimport csaps\n\nx = [1., 2., 4., 6.]\ny = [2., 4., 5., 7.]\nw = [0.5, 1, 0.7, 1.2]\n\nsp = csaps.UnivariateCubicSmoothingSpline(x, y, w)\n...\n```\n\n### Smoothing univariate data with vectorization\n\nThe algorithm supports vectorization. You can compute smoothing splines for \n`X`, `Y` data where `X` is data site vector and `Y` is ND-array of data value vectors. \nThe shape of `Y` array must be: `(d0, d1, ..., dN)` where `dN` must equal of `X` vector size.\n\nIn this case the smoothing splines will be computed for all `Y` data vectors at a time.\n\nFor example:\n\n```python\nimport numpy as np\nimport csaps\n\n# data sites\nx = [1, 2, 3, 4]\n\n# two data vectors\ny = np.array([(2, 4, 6, 8), \n (1, 3, 5, 7)])\n\nsp = csaps.UnivariateCubicSmoothingSpline(x, y)\n\nxi = np.linspace(1, 4, 10)\nyi = sp(xi)\n\nprint(yi.shape) # (2, 10)\nassert yi.shape[:-1] == y.shape[:-1]\nassert yi.shape[-1] == xi.size\n```\n\n**Important**:\nThe same weights vector and the same smoothing parameter will be used for all Y data.\n\n## Smoothing multivariate data\n\nWe can easily smooth multivariate data using univariate smoothing spline, vectorization and parametrization.\nWe should define parametric data sites vector `t` with condition `t1 < t2 < ... < tN` and make spline for each dimension `X(t), Y(t), ..., M(t)`.\n\nThe module provides `MultivariateCubicSmoothingSpline` class for this case.\n\nThis class is a simple wrapper and it just automatically computes `t` vector by default and calls `UnivariateCubicSmoothingSpline`:\n\n```python\n# Construct multivariate spline from t and X, Y, Z, ..., M\nsx = UnivariateCubicSmoothingSpline(t, data[x])\nsy = UnivariateCubicSmoothingSpline(t, data[y])\nsz = UnivariateCubicSmoothingSpline(t, data[z])\n...\nsm = UnivariateCubicSmoothingSpline(t, data[m])\n\n# Or the same with using vectorization\nsxyz_m = UnivariateCubicSmoothingSpline(t, data)\n```\n\n### Smoothing 3D noisy parametric curve example\n\nIn this example we make parametric 3D curve from `theta` parameter and compute spline from the same `theta` parameter.\nIn fact we could use `UnivariateCubicSmoothingSpline` with vectorization instead of `MultivariateCubicSmoothingSpline` in this case.\n\n```python\nimport numpy as np\n\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nimport csaps\n\nn = 100\ntheta = np.linspace(-4 * np.pi, 4 * np.pi, n)\nz = np.linspace(-2, 2, n)\nr = z ** 2 + 1\nnp.random.seed(1234)\nx = r * np.sin(theta) + np.random.randn(n) * 0.3\nnp.random.seed(5678)\ny = r * np.cos(theta) + np.random.randn(n) * 0.3\n\ndata = np.vstack((x, y, z))\n\nsp_theta = csaps.MultivariateCubicSmoothingSpline(data, theta, smooth=0.95)\n\n# or the same\n# sp_theta = csaps.UnivariateCubicSmoothingSpline(theta, data, smooth=0.95)\n\ntheta_i = np.linspace(-4 * np.pi, 4 * np.pi, 250)\ndata_i = sp_theta(theta_i)\n\nxi = data_i[0, :]\nyi = data_i[1, :]\nzi = data_i[2, :]\n\nfig = plt.figure()\nax = fig.gca(projection='3d')\nplt.show()\n```\n\n\"2019-04-04_02-28-52\"\n\n## Smoothing ND-gridded data\n\nThe algorithm can make smoothing splines for ND-gridded data approximation.\nIn this case we use coordinatewise smoothing (tensor-product of univariate splines coefficients).\n\nYou can use `NdGridCubicSmoothingSpline` class for ND-gridded data smoothing. \nYou also can set weights and smoothing parameters for each dimension.\n\nCurrently the implementation does not support vectorization for ND-gridded data.\n\n### Smoothing 2D-gridded data (surface) example\n\n```python\nimport numpy as np\n\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nimport csaps\n\nxdata = [np.linspace(-3, 3, 61), np.linspace(-3.5, 3.5, 51)]\ni, j = np.meshgrid(*xdata, indexing='ij')\n\nydata = (3 * (1 - j)**2. * np.exp(-(j**2) - (i + 1)**2)\n - 10 * (j / 5 - j**3 - i**5) * np.exp(-j**2 - i**2)\n - 1 / 3 * np.exp(-(j + 1)**2 - i**2))\n\nnp.random.seed(12345)\nnoisy = ydata + (np.random.randn(*ydata.shape) * 0.75)\n\nsp = csaps.NdGridCubicSmoothingSpline(xdata, noisy, smooth=0.988)\nysmth = sp(xdata)\n\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\n\nax.plot_wireframe(j, i, noisy, linewidths=0.5, color='r')\nax.scatter(j, i, noisy, s=5, c='r')\n\nax.plot_surface(j, i, ysmth, linewidth=0, alpha=1.0)\n\nplt.show()\n```\n\n\"2019-03-22_10-22-59\"\n\n## More examples\n\nPlease look through [csaps.ipynb](examples/csaps.ipynb) file for more examples.\n\n## Testing\n\nWe use pytest and tox (on Travis CI) for testing.\nPlease see [test_csaps.py](tests/test_csaps.py) file.\n\n## Algorithms and implementations\n\n`csaps` is a Python modified port of MATLAB [CSAPS](https://www.mathworks.com/help/curvefit/csaps.html) function that is an implementation of \nFortran routine SMOOTH from [PGS](http://pages.cs.wisc.edu/~deboor/pgs/) (originally written by Carl de Boor).\n\n[csaps-cpp](https://github.com/espdev/csaps-cpp) C++11 Eigen based implementation of the algorithm.\n\n## References\n\nC. de Boor, A Practical Guide to Splines, Springer-Verlag, 1978.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/espdev/csaps", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "csaps", "package_url": "https://pypi.org/project/csaps/", "platform": "", "project_url": "https://pypi.org/project/csaps/", "project_urls": { "Homepage": "https://github.com/espdev/csaps" }, "release_url": "https://pypi.org/project/csaps/0.7.0/", "requires_dist": [ "numpy (>=0.12.1)", "scipy (>=0.19.1)" ], "requires_python": ">=3.5", "summary": "Cubic spline approximation (smoothing)", "version": "0.7.0" }, "last_serial": 5857491, "releases": { "0.4.1": [ { "comment_text": "", "digests": { "md5": "bd654af1e7c7783dbcf6731b4aa6b37d", "sha256": "f5eec410d05814eb04ce3a06829b5478dfedf148d521c0ba2cd9d742964aadfc" }, "downloads": -1, "filename": "csaps-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bd654af1e7c7783dbcf6731b4aa6b37d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 9981, "upload_time": "2019-05-30T00:12:14", "url": "https://files.pythonhosted.org/packages/32/d2/442bd6b9c982d23027fc207ced4c9587de295b413336b50a0fe62ff812a6/csaps-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bfb1360c8a35f33bf04d63221144102c", "sha256": "82a4ffb13c4d0bf57a4f4c1e466ae33d5df1a1b241e8068ff57c43d49c4f9bbd" }, "downloads": -1, "filename": "csaps-0.4.1.tar.gz", "has_sig": false, "md5_digest": "bfb1360c8a35f33bf04d63221144102c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 9573, "upload_time": "2019-05-30T00:12:18", "url": "https://files.pythonhosted.org/packages/6c/96/13fb69852de63eec76d3fb49dbc4187823b1489aee68a3f49227bfff50a2/csaps-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "a775b6f5b63690012952f43dc9f0b109", "sha256": "2d249f741caad4e093acf290d1b953290d44167c1ceb6d08659420d56a84eedb" }, "downloads": -1, "filename": "csaps-0.4.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a775b6f5b63690012952f43dc9f0b109", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 9984, "upload_time": "2019-06-07T01:21:17", "url": "https://files.pythonhosted.org/packages/0d/2e/d2374aa6c03e45e69c400aabb9f969731192e5cb934e6ada6202bc7e9a0f/csaps-0.4.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "70330946fc61803a36ea2072b1834302", "sha256": "43757b0e10804c8a2e5031200f805996900ca5803afba0666ad59b70ffd27c50" }, "downloads": -1, "filename": "csaps-0.4.2.tar.gz", "has_sig": false, "md5_digest": "70330946fc61803a36ea2072b1834302", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 9567, "upload_time": "2019-06-07T01:21:19", "url": "https://files.pythonhosted.org/packages/cd/53/b053c2127daa76a15fda7a39f8bf2ece1ba89a5b16dd9133c638d8811e36/csaps-0.4.2.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "2e195e9bd0affb59d66924c3dc4bf1ce", "sha256": "86ca29de91a6538a8beffe38f5b7f83fcc975bbe37a8d7ad69b3afe95547a214" }, "downloads": -1, "filename": "csaps-0.5.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2e195e9bd0affb59d66924c3dc4bf1ce", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 16012, "upload_time": "2019-06-10T16:50:16", "url": "https://files.pythonhosted.org/packages/87/90/9b3534bc4410c8f3c8b92f325c38ea6fbd27e167c71f01fe8d2d056b80bb/csaps-0.5.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b7697ace2694e348b8a6f16788ba994", "sha256": "857fc985b7a2d13085063cb63070b0ee017093636fc6f32e2a71a917c9d71fc9" }, "downloads": -1, "filename": "csaps-0.5.0.tar.gz", "has_sig": false, "md5_digest": "8b7697ace2694e348b8a6f16788ba994", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 13695, "upload_time": "2019-06-10T16:50:18", "url": "https://files.pythonhosted.org/packages/bc/88/1fd4267acf09f542d71cad1a5a4dd16577400d8fb1fde781c277dbbaeaa0/csaps-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "1a520701dfd4a1da1d661e570d6ab35d", "sha256": "e8b12b2cf9a88b13848453775dbf8910cda6426b89b4402337227ad83d3ab0d7" }, "downloads": -1, "filename": "csaps-0.6.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1a520701dfd4a1da1d661e570d6ab35d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 12449, "upload_time": "2019-09-12T12:17:24", "url": "https://files.pythonhosted.org/packages/c8/32/e583ea8c879ad5e13545d7bd5004d8d8dec06ae3c4c147712468689c262f/csaps-0.6.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "13c6e5fa09b4e3ef95cddb31d1c465c3", "sha256": "a87514949b0813ff114405e5a2d32cbf63dbf525b5e08cb16c9b26894ed59bf0" }, "downloads": -1, "filename": "csaps-0.6.0.tar.gz", "has_sig": false, "md5_digest": "13c6e5fa09b4e3ef95cddb31d1c465c3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 14853, "upload_time": "2019-09-12T12:17:26", "url": "https://files.pythonhosted.org/packages/d4/91/61de775fafe6494bc69da47245bce6d60aee5aa9231644594318127ff6a1/csaps-0.6.0.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "bae1886e33239a486ea7a1efe46cca28", "sha256": "bc7f736f8a2f2a61170b402581919ae32df5977885db8894948ce54e97a91111" }, "downloads": -1, "filename": "csaps-0.6.1-py3-none-any.whl", "has_sig": false, "md5_digest": "bae1886e33239a486ea7a1efe46cca28", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 17364, "upload_time": "2019-09-12T22:41:29", "url": "https://files.pythonhosted.org/packages/8f/b2/67e0f9bd3334629cec307b3a8618f4f2f0438429184a1d9fe63042f5e6c5/csaps-0.6.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e3a61f72447c9ed19b0ba82d33c66ba4", "sha256": "5fda15d0c4063d59a44c1de2ce09a0e7a1bed05d5420054b91ea5465e41e5a5f" }, "downloads": -1, "filename": "csaps-0.6.1.tar.gz", "has_sig": false, "md5_digest": "e3a61f72447c9ed19b0ba82d33c66ba4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 14908, "upload_time": "2019-09-12T22:41:31", "url": "https://files.pythonhosted.org/packages/a3/81/874221c005d77a91f7a42099df6bb7553a73e66b866d55281170f00d0343/csaps-0.6.1.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "fd34d20c69b4224dbe779836bfbb7700", "sha256": "ac940be5f760e1ea7a86c8668b07c319bc9e14d30af50a9b2ad2a208a1ed6be9" }, "downloads": -1, "filename": "csaps-0.7.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fd34d20c69b4224dbe779836bfbb7700", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 13136, "upload_time": "2019-09-19T16:27:35", "url": "https://files.pythonhosted.org/packages/31/44/6f6feb977bde12d92f116da2d65fcd9e60d188f2890e92335870ff8f0176/csaps-0.7.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b66ad57e5a080620f4fded6b0d39128", "sha256": "17ab6c19e1e44ee7d501e0112c4c1559e3f4c5883d61ddce9aba646f310969eb" }, "downloads": -1, "filename": "csaps-0.7.0.tar.gz", "has_sig": false, "md5_digest": "8b66ad57e5a080620f4fded6b0d39128", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 15492, "upload_time": "2019-09-19T16:27:37", "url": "https://files.pythonhosted.org/packages/4f/5e/c95be9fdf8eeb3cf5a0c135820ad0ab731c1eed53227fdf57db0c1744768/csaps-0.7.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fd34d20c69b4224dbe779836bfbb7700", "sha256": "ac940be5f760e1ea7a86c8668b07c319bc9e14d30af50a9b2ad2a208a1ed6be9" }, "downloads": -1, "filename": "csaps-0.7.0-py3-none-any.whl", "has_sig": false, "md5_digest": "fd34d20c69b4224dbe779836bfbb7700", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 13136, "upload_time": "2019-09-19T16:27:35", "url": "https://files.pythonhosted.org/packages/31/44/6f6feb977bde12d92f116da2d65fcd9e60d188f2890e92335870ff8f0176/csaps-0.7.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b66ad57e5a080620f4fded6b0d39128", "sha256": "17ab6c19e1e44ee7d501e0112c4c1559e3f4c5883d61ddce9aba646f310969eb" }, "downloads": -1, "filename": "csaps-0.7.0.tar.gz", "has_sig": false, "md5_digest": "8b66ad57e5a080620f4fded6b0d39128", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 15492, "upload_time": "2019-09-19T16:27:37", "url": "https://files.pythonhosted.org/packages/4f/5e/c95be9fdf8eeb3cf5a0c135820ad0ab731c1eed53227fdf57db0c1744768/csaps-0.7.0.tar.gz" } ] }