bletl.splines
- class bletl.splines.UnivariateCubicSmoothingSpline(xdata: ndarray | Sequence[Number], ydata: ndarray | Sequence, weights: ndarray | Sequence[Number] | None = None, smooth: float | None = None, axis: int = -1, normalizedsmooth: bool = False)
Bases:
CubicSmoothingSpline
Overrides csaps type to align its API with the scipy.interpolate splines.
- Attributes:
smooth
Returns the smoothing factor
spline
Returns the spline description in SplinePPForm instance
Methods
__call__
(x[, nu, extrapolate])Evaluate the spline at some coordinates.
derivative
([order, epsilon])Returns the derivative of the spline.
- derivative(order: int = 1, *, epsilon=0.001) Callable[[ndarray], ndarray]
Returns the derivative of the spline.
- Parameters:
- orderint
Order of derivative.
- epsilonfloat
Epsilon to calculate derivative by difference quotient.
- Returns:
- derivativecallable
A function that can be called with a numpy array of coordinates at which to apply the difference quotient derivative calculation.
- bletl.splines.get_crossvalidated_spline(x: ndarray, y: ndarray, k_folds: int = 5, method: str = 'us', bounds: Tuple[float, float] = (0.001, 1)) UnivariateCubicSmoothingSpline | UnivariateSpline
Returns spline with k-fold crossvalidated smoothing factor
- Parameters:
- xnumpy.ndarray
Time vector
- ynumpy.ndarray
Value vector
- k_foldsint
Number of splits used for cross-validation.
- methodstr
- Kind of spline.
Choices: “ucss” UnivariateCubicSmoothingSpline, “us” UnivariateSpline
- boundstuple
Lower and upper bound for the smoothing factor. Must not exceed the [0, 1] interval.
- Returns:
- splineUnivariateCubicSmoothingSpline or scipy.interpolate.UnivariateSpline
Spline of the specified method fitted to the data. Its optimal smoothing factor is determined by k-fold crossvalidation.
- bletl.splines.get_mue(bsdata: FilterTimeSeries, wells: Sequence[str] | str = 'all', blank: float | str | Dict[str, float] = 'first', k_folds: int = 5, method: str = 'us', last_cycle: int | None = None)
Approximation of specific growth rate over time via spline approximation using splines with k-fold cross validated smoothing factor
- Parameters:
- bsdataFilterTimeSeries
FilterTimeSeries containing timepoints and backscatter data.
- wells‘all’ or list
List of wells to calculate specific growth rate for. ‘all’ calculates for all wells.
- blank‘first’, float or dict
Blanks to use for specific growth rate calculation. Options: - ‘first’: Use first data point. - float: Apply this blank value to all wells. - dict: Containing well id as key and scalar or vector as blank value(s) for the respective well.
- k_foldsint
“k”s for cross-validation.
- methodstr
Kind of Spline. Choices: “ucss” UnivariateCubicSmoothingSpline, “us” UnivariateSpline
- last_cycleint, optional
Ignores data after last_cycle
- Returns:
- filtertimeseriesFilterTimeSeries
FilterTimeSeries with specific growth rate over time.
- Raises:
- ValueError
If blanks are not provided for every well, of if an invalid blank option is passed.
- bletl.splines.get_multiple_splines(fts: FilterTimeSeries, wells: Sequence[str], k_folds: int = 5, method: str = 'us', last_cycle: int | None = None) List[Tuple[str, UnivariateCubicSmoothingSpline | UnivariateSpline]]
Returns multiple splines with k-fold crossvalidated smoothing factor
- Parameters:
- ftsFilterTimeSeries
FilterTimeSeries containing timepoints and observed data-
- wellslist of str
Wells to fit splines to.
- k_foldsint
“k”s for cross-validation
- methodstr
Kind of spline. Choices: “ucss” UnivariateCubicSmoothingSpline, “us” UnivariateSpline
- Returns:
- splinesdict
Dict with {well:spline} for each well of “wells”