Skip to main content

csaps

PyPI version Supported Python versions GitHub Actions (Tests) Documentation Status Coverage Status License

csaps is 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.

Installing

Use pip for installing:

pip install -U csaps

or Poetry:

poetry add csaps

The module depends only on NumPy and SciPy. Python 3.10 or above is supported.

Simple Examples

Here is a couple of examples of smoothing data.

An univariate data smoothing:

import numpy as np
import matplotlib.pyplot as plt

from csaps import csaps

np.random.seed(1234)

x = np.linspace(-5., 5., 25)
y = np.exp(-(x/2.5)**2) + (np.random.rand(25) - 0.2) * 0.3
xs = np.linspace(x[0], x[-1], 150)

ys = csaps(x, y, xs, smooth=0.85)

plt.plot(x, y, 'o', xs, ys, '-')
plt.show()

univariate

A surface data smoothing:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from csaps import csaps

np.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'] for s in plt.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()

surface

Documentation

More examples of usage and the full documentation can be found at https://csaps.readthedocs.io.

Development

We use Poetry to manage the project:

git clone https://github.com/espdev/csaps.git
cd csaps
poetry install -E docs

Also, install pre-commit hooks:

poetry run pre-commit install

Testing and Linting

We use pytest for testing and ruff/mypy for linting. Use poethepoet to run tests and linters:

poetry run poe test
poetry run poe check

Algorithm and Implementation

csaps Python package is inspired by MATLAB CSAPS function that is an implementation of Fortran routine SMOOTH from PGS (originally written by Carl de Boor).

Also, the algothithm implementation in other languages:

  • csaps-rs Rust ndarray/sprs based implementation
  • csaps-cpp C++11 Eigen based implementation (incomplete)

References

C. de Boor, A Practical Guide to Splines, Springer-Verlag, 1978.

License

MIT

Metadata

Release files for csaps 1.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csaps 1.3.3
File Size Uploaded
csaps-1.3.3.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for csaps 1.3.3
File Interpreter ABI Platform
csaps-1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / csaps-1.3.3.tar.gz

Download URL csaps-1.3.3.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ac89c597c4e6b5d53d17acac1283453ea4eab23a7f4e31bf1db8cad0a10dec19
BLAKE2b-256 checksum
How to use checksums
d43afe35895aa266d02db8418db543b6b967e466a9e3e510524a01fa07ba02bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2025.

Transparency log

Release files / csaps-1.3.3-py3-none-any.whl

Download URL csaps-1.3.3-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
844d1d1258b9fc23a7be08d92bd6f5a33b7eac9c13a9df61569b2b033aa6ca44
BLAKE2b-256 checksum
How to use checksums
8b419d387a411700cdb21613a9a90b45febcad6fd583cad069d5e60de33d71af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.3 This release

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page