BSplineBasis   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A functions_factory() 0 7 1
A derivatives_factory() 0 7 1
A fit() 0 4 1
A _basis_spline_factory() 0 4 1
1
"""
2
Class for approximating the solution to two-point boundary value problems using
3
B-splines as basis functions.
4
5
@author: davidrpugh
6
7
"""
8
import functools
9
10
from scipy import interpolate
11
12
from . import basis_functions
13
14
15
class BSplineBasis(basis_functions.BasisFunctionLike):
16
17
    @staticmethod
18
    def _basis_spline_factory(coef, degree, knots, der, ext):
19
        """Return a B-Spline given some coefficients."""
20
        return functools.partial(interpolate.splev, tck=(knots, coef, degree), der=der, ext=ext)
21
22
    @classmethod
23
    def derivatives_factory(cls, coef, degree, knots, ext, **kwargs):
24
        """
25
        Given some coefficients, return a the derivative of a B-spline.
26
27
        """
28
        return cls._basis_spline_factory(coef, degree, knots, 1, ext)
29
30
    @classmethod
31
    def fit(cls, *args, **kwargs):
32
        """Possibly just wrap interpolate.splprep?"""
33
        return interpolate.splprep(*args, **kwargs)
34
35
    @classmethod
36
    def functions_factory(cls, coef, degree, knots, ext, **kwargs):
37
        """
38
        Given some coefficients, return a B-spline.
39
40
        """
41
        return cls._basis_spline_factory(coef, degree, knots, 0, ext)
42