Skip to content

Commit 4016446

Browse files
authored
Merge pull request #100 from espdev/docs-extrapolation
Add extrapolation section to tutorial documentation
2 parents 0522ebd + 1bef7ad commit 4016446

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

csaps/_sspumv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ def __repr__(self) -> str: # pragma: no cover
7878

7979

8080
class CubicSmoothingSpline(
81-
ISmoothingSpline[SplinePPForm, float, UnivariateDataType, int, Union[bool, Literal['periodic']]],
81+
ISmoothingSpline[
82+
SplinePPForm,
83+
float,
84+
UnivariateDataType,
85+
int,
86+
Union[bool, Literal['periodic']],
87+
]
8288
):
8389
"""Cubic smoothing spline
8490

docs/tutorial.rst

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ Let's show it on a simple example.
368368
yi1_n = csaps(x1, y, xi1, smooth=0.8, normalizedsmooth=True)
369369
yi2_n = csaps(x2, y, xi2, smooth=0.8, normalizedsmooth=True)
370370

371-
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(8, 6))
371+
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(10, 6))
372372
ax1.plot(x1, y, 'o', xi1, yi1, '-')
373373
ax2.plot(x2, y, 'o', xi2, yi2, '-')
374374
ax3.plot(x1, y, 'o', xi1, yi1_n, '-')
@@ -406,14 +406,50 @@ The example for univariate data:
406406
yi1 = spline(xi1)
407407
yi2 = spline(xi2)
408408

409-
f, (ax1, ax2) = plt.subplots(2, 1, figsize=(5, 6))
409+
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
410410
ax1.plot(x, y, 'o', xi1, yi1, '.-')
411411
ax2.plot(x, y, 'o', xi2, yi2, '.-')
412412

413413
ax1.set_title('20 evaluated points')
414414
ax2.set_title('50 evaluated points')
415415

416416

417+
.. _tutorial-extrapolation:
418+
419+
Extrapolation
420+
~~~~~~~~~~~~~
421+
422+
Spline values can be evaluated out-of-bounds input X-values (the input grid) based on first and last intervals.
423+
These values will be extrapolated. The ``extrapolate`` parameter in the spline evaluation method is used for this.
424+
Extrapolation can be used for all evaluated splines: univariate, multivariate and N-D grid.
425+
426+
Here is an example for univariate data:
427+
428+
.. plot::
429+
430+
x, y = univariate_data()
431+
xi = np.linspace(x[0] - 2.0, x[-1] + 2.0, 50)
432+
433+
s1 = csaps(x, y, smooth=0.85)
434+
s2 = csaps(x, y, smooth=0.85)
435+
436+
yi1 = s1(xi, extrapolate=True)
437+
yi2 = s2(xi, extrapolate='periodic')
438+
439+
_, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
440+
ax1.plot(x, y, 'o:', xi, yi1, '.-')
441+
ax2.plot(x, y, 'o:', xi, yi2, '.-')
442+
443+
ax1.set_title('extrapolate=True')
444+
ax2.set_title('extrapolate="periodic"')
445+
446+
.. attention::
447+
448+
How we can see ``'periodic'`` extrapolation method works incorrectly with the spline. There is a discontinuity.
449+
This can be fixed in the future. Please see `the issue <https://github.com/espdev/csaps/issues/46>`_ for details.
450+
So don't use this method for now if you need extrapolation.
451+
452+
417453
.. _tutorial-analysis:
418454

419455
Analysis

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "csaps"
3-
version = "1.3.2"
3+
version = "1.3.3.dev0"
44
description = "Cubic spline approximation (smoothing)"
55
authors = ["Evgeny Prilepin <esp.home@gmail.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)