| 1 |
Metadata-Version: 2.3 |
| 2 |
Name: csaps |
| 3 |
Version: 1.3.3 |
| 4 |
Summary: Cubic spline approximation (smoothing) |
| 5 |
License: MIT |
| 6 |
Keywords: cubic,spline,approximation,smoothing,interpolation,csaps |
| 7 |
Author: Evgeny Prilepin |
| 8 |
Author-email: [email protected] |
| 9 |
Requires-Python: >=3.10 |
| 10 |
Classifier: Development Status :: 5 - Production/Stable |
| 11 |
Classifier: Intended Audience :: Developers |
| 12 |
Classifier: Intended Audience :: Science/Research |
| 13 |
Classifier: License :: OSI Approved :: MIT License |
| 14 |
Classifier: Programming Language :: Python |
| 15 |
Classifier: Programming Language :: Python :: 3 |
| 16 |
Classifier: Programming Language :: Python :: 3.10 |
| 17 |
Classifier: Programming Language :: Python :: 3.11 |
| 18 |
Classifier: Programming Language :: Python :: 3.12 |
| 19 |
Classifier: Programming Language :: Python :: 3.13 |
| 20 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 21 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 22 |
Classifier: Topic :: Scientific/Engineering |
| 23 |
Classifier: Topic :: Scientific/Engineering :: Mathematics |
| 24 |
Classifier: Topic :: Software Development :: Libraries |
| 25 |
Requires-Dist: numpy (>=1.26.2) ; python_version >= "3.12" |
| 26 |
Requires-Dist: numpy ; python_version < "3.12" |
| 27 |
Requires-Dist: scipy (>=1.11.4) ; python_version >= "3.12" |
| 28 |
Requires-Dist: scipy ; python_version < "3.12" |
| 29 |
Requires-Dist: typing-extensions |
| 30 |
Project-URL: Documentation, https://csaps.readthedocs.io |
| 31 |
Project-URL: Homepage, https://github.com/espdev/csaps |
| 32 |
Project-URL: Repository, https://github.com/espdev/csaps |
| 33 |
Description-Content-Type: text/markdown |
| 34 |
|
| 35 |
<p align="center"> |
| 36 |
<a href="https://github.com/espdev/csaps"><img src="https://user-images.githubusercontent.com/1299189/76571441-8d97e400-64c8-11ea-8c05-58850f8311a1.png" alt="csaps" width="400" /></a><br> |
| 37 |
</p> |
| 38 |
|
| 39 |
<p align="center"> |
| 40 |
<a href="https://pypi.python.org/pypi/csaps"><img src="https://img.shields.io/pypi/v/csaps.svg" alt="PyPI version" /></a> |
| 41 |
<a href="https://pypi.python.org/pypi/csaps"><img src="https://img.shields.io/pypi/pyversions/csaps.svg" alt="Supported Python versions" /></a> |
| 42 |
<a href="https://github.com/espdev/csaps"><img src="https://github.com/espdev/csaps/workflows/main/badge.svg" alt="GitHub Actions (Tests)" /></a> |
| 43 |
<a href="https://csaps.readthedocs.io/en/latest/?badge=latest"><img src="https://readthedocs.org/projects/csaps/badge/?version=latest" alt="Documentation Status" /></a> |
| 44 |
<a href="https://coveralls.io/github/espdev/csaps?branch=master"><img src="https://coveralls.io/repos/github/espdev/csaps/badge.svg?branch=master" alt="Coverage Status" /></a> |
| 45 |
<a href="https://choosealicense.com/licenses/mit/"><img src="https://img.shields.io/pypi/l/csaps.svg" alt="License" /></a> |
| 46 |
</p> |
| 47 |
|
| 48 |
**csaps** is a Python package for univariate, multivariate and n-dimensional grid data approximation using cubic smoothing splines. |
| 49 |
The package can be useful in practical engineering tasks for data approximation and smoothing. |
| 50 |
|
| 51 |
## Installing |
| 52 |
|
| 53 |
Use pip for installing: |
| 54 |
|
| 55 |
``` |
| 56 |
pip install -U csaps |
| 57 |
``` |
| 58 |
|
| 59 |
or Poetry: |
| 60 |
|
| 61 |
``` |
| 62 |
poetry add csaps |
| 63 |
``` |
| 64 |
|
| 65 |
The module depends only on NumPy and SciPy. Python 3.10 or above is supported. |
| 66 |
|
| 67 |
## Simple Examples |
| 68 |
|
| 69 |
Here is a couple of examples of smoothing data. |
| 70 |
|
| 71 |
An univariate data smoothing: |
| 72 |
|
| 73 |
```python |
| 74 |
import numpy as np |
| 75 |
import matplotlib.pyplot as plt |
| 76 |
|
| 77 |
from csaps import csaps |
| 78 |
|
| 79 |
np.random.seed(1234) |
| 80 |
|
| 81 |
x = np.linspace(-5., 5., 25) |
| 82 |
y = np.exp(-(x/2.5)**2) + (np.random.rand(25) - 0.2) * 0.3 |
| 83 |
xs = np.linspace(x[0], x[-1], 150) |
| 84 |
|
| 85 |
ys = csaps(x, y, xs, smooth=0.85) |
| 86 |
|
| 87 |
plt.plot(x, y, 'o', xs, ys, '-') |
| 88 |
plt.show() |
| 89 |
``` |
| 90 |
|
| 91 |
<p align="center"> |
| 92 |
<img src="https://user-images.githubusercontent.com/1299189/72231304-cd774380-35cb-11ea-821d-d5662cc1eedf.png" alt="univariate" /> |
| 93 |
<p/> |
| 94 |
|
| 95 |
A surface data smoothing: |
| 96 |
|
| 97 |
```python |
| 98 |
import numpy as np |
| 99 |
import matplotlib.pyplot as plt |
| 100 |
from mpl_toolkits.mplot3d import Axes3D |
| 101 |
|
| 102 |
from csaps import csaps |
| 103 |
|
| 104 |
np.random.seed(1234) |
| 105 |
xdata = [np.linspace(-3, 3, 41), np.linspace(-3.5, 3.5, 31)] |
| 106 |
i, j = np.meshgrid(*xdata, indexing='ij') |
| 107 |
ydata = (3 * (1 - j)**2. * np.exp(-(j**2) - (i + 1)**2) |
| 108 |
- 10 * (j / 5 - j**3 - i**5) * np.exp(-j**2 - i**2) |
| 109 |
- 1 / 3 * np.exp(-(j + 1)**2 - i**2)) |
| 110 |
ydata = ydata + (np.random.randn(*ydata.shape) * 0.75) |
| 111 |
|
| 112 |
ydata_s = csaps(xdata, ydata, xdata, smooth=0.988) |
| 113 |
|
| 114 |
fig = plt.figure(figsize=(7, 4.5)) |
| 115 |
ax = fig.add_subplot(111, projection='3d') |
| 116 |
ax.set_facecolor('none') |
| 117 |
c = [s['color'] for s in plt.rcParams['axes.prop_cycle']] |
| 118 |
ax.plot_wireframe(j, i, ydata, linewidths=0.5, color=c[0], alpha=0.5) |
| 119 |
ax.scatter(j, i, ydata, s=10, c=c[0], alpha=0.5) |
| 120 |
ax.plot_surface(j, i, ydata_s, color=c[1], linewidth=0, alpha=1.0) |
| 121 |
ax.view_init(elev=9., azim=290) |
| 122 |
|
| 123 |
plt.show() |
| 124 |
``` |
| 125 |
|
| 126 |
<p align="center"> |
| 127 |
<img src="https://user-images.githubusercontent.com/1299189/72231252-7a9d8c00-35cb-11ea-8890-487b8a7dbd1d.png" alt="surface" /> |
| 128 |
<p/> |
| 129 |
|
| 130 |
## Documentation |
| 131 |
|
| 132 |
More examples of usage and the full documentation can be found at https://csaps.readthedocs.io. |
| 133 |
|
| 134 |
## Development |
| 135 |
|
| 136 |
We use Poetry to manage the project: |
| 137 |
|
| 138 |
``` |
| 139 |
git clone https://github.com/espdev/csaps.git |
| 140 |
cd csaps |
| 141 |
poetry install -E docs |
| 142 |
``` |
| 143 |
|
| 144 |
Also, install pre-commit hooks: |
| 145 |
|
| 146 |
``` |
| 147 |
poetry run pre-commit install |
| 148 |
``` |
| 149 |
|
| 150 |
## Testing and Linting |
| 151 |
|
| 152 |
We use pytest for testing and ruff/mypy for linting. |
| 153 |
Use `poethepoet` to run tests and linters: |
| 154 |
|
| 155 |
``` |
| 156 |
poetry run poe test |
| 157 |
poetry run poe check |
| 158 |
``` |
| 159 |
|
| 160 |
## Algorithm and Implementation |
| 161 |
|
| 162 |
**csaps** Python package is inspired by MATLAB [CSAPS](https://www.mathworks.com/help/curvefit/csaps.html) function that is an implementation of |
| 163 |
Fortran routine SMOOTH from [PGS](http://pages.cs.wisc.edu/~deboor/pgs/) (originally written by Carl de Boor). |
| 164 |
|
| 165 |
Also, the algothithm implementation in other languages: |
| 166 |
|
| 167 |
* [csaps-rs](https://github.com/espdev/csaps-rs) Rust ndarray/sprs based implementation |
| 168 |
* [csaps-cpp](https://github.com/espdev/csaps-cpp) C++11 Eigen based implementation (incomplete) |
| 169 |
|
| 170 |
## References |
| 171 |
|
| 172 |
C. de Boor, A Practical Guide to Splines, Springer-Verlag, 1978. |
| 173 |
|
| 174 |
## License |
| 175 |
|
| 176 |
[MIT](https://choosealicense.com/licenses/mit/) |
| 177 |
|