3Contains functionality for integrating discretized funtions.
15 Object to integrate a function \f$y = f(x)\f$ given by discrete argument data \f$x\f$ and associated values \f$y\f$.
18 interpolation: str =
"trapezoidal",
21 Constructs an Integrator object.
22 \param interpolation \copybrief interpolation For more, see \ref interpolation.
23 \param *args Additional positional arguments, will be passed to the superconstructor.
24 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
36 interpolation: str =
None,
37 *args, **kwargs) -> np.array:
39 Calculates the antiderivative \f$F(x) = \int f(x) dx + C\f$ to the given function over the given segment (indicated by `start_index` and `end_index`).
40 The given values are assumed to be preprocessed (`NaN`s are stripped already).
41 \param x_values List of x-positions \f$x\f$.
42 \param y_values List of y-values \f$y\f$ matching \f$x\f$.
43 \param initial The interpolation constant \f$C\f$.
44 \param interpolation \copybrief interpolation Defaults to \ref interpolation. For more, see \ref interpolation.
45 \param *args Additional positional arguments, will be passed to the called integration function.
46 \param **kwargs Additional keyword arguments, will be passed to the called integration function.
48 interpolation = interpolation
if interpolation
is not None else self.
interpolation
50 if interpolation ==
"trapezoidal":
51 return scipy.integrate.cumulative_trapezoid(y=y_values, x=x_values, initial=initial, *args, **kwargs)
53 raise RuntimeError(
"No such option '{}' known for `interpolation`.".format(interpolation))
57 start_index: int =
None,
58 end_index: int =
None,
60 interpolation: str =
None,
61 *args, **kwargs) -> float:
63 Calculates integral over the given segment (indicated by `start_index` and `end_index`) \f$F(x)|_{a}^{b} = \int_{a}^{b} f(x) dx + C\f$.
64 The given values are assumed to be preprocessed (`NaN`s are stripped already).
65 \param x_values List of x-positions \f$x\f$.
66 \param y_values List of y-values \f$y\f$ matching \f$x\f$.
67 \param start_index Index, where the integration should start (index of \f$a\f$). Defaults to the first item of `x_values` (`0`).
68 \param end_index Index, where the integration should stop (index of \f$b\f$). This index is included. Defaults to the first item of `x_values` (`len(x_values) -1`).
69 \param initial The interpolation constant \f$C\f$.
70 \param interpolation \copybrief interpolation For more, see \ref interpolation.
71 \param *args Additional positional arguments, will be passed to the called integration function.
72 \param **kwargs Additional keyword arguments, will be passed to the called integration function.
74 interpolation = interpolation
if interpolation
is not None else self.
interpolation
75 start_index = start_index
if start_index
is not None else 0
76 end_index = end_index
if end_index
is not None else len(x_values) - 1
77 x_segment = x_values[start_index:end_index+1]
78 y_segment = y_values[start_index:end_index+1]
80 if interpolation ==
"trapezoidal":
81 return scipy.integrate.trapezoid(y=y_segment, x=x_segment, *args, **kwargs) + initial
83 raise RuntimeError(
"No such option '{}' known for `interpolation`.".format(interpolation))
This intermediate class indicates, that a sub-class is implementing a task.
Object to integrate a function given by discrete argument data and associated values .
interpolation
Algorithm, which should be used to interpolate between data points.
__init__(self, str interpolation="trapezoidal", *args, **kwargs)
Constructs an Integrator object.
float integrate_segment(self, np.array x_values, np.array y_values, int start_index=None, int end_index=None, float initial=0.0, str interpolation=None, *args, **kwargs)
Calculates integral over the given segment (indicated by start_index and end_index) .
np.array antiderivative(self, np.array x_values, np.array y_values, float initial=0.0, str interpolation=None, *args, **kwargs)
Calculates the antiderivative to the given function over the given segment (indicated by start_index...