3Contains class implementations, for strain function repair algorithms.
4Those can be used to attempt the reconstruction of more or less heavily destroyed strain profiles.
10from abc
import abstractmethod
14import scipy.interpolate
21 Base class for algorithms to replace/remove missing data with plausible values.
22 The sub-classes will take data containing dropouts (`NaN`s) and will return dropout-free data.
23 This is done by replacing the dropouts by plausible values and/or removing dropouts.
24 Because the shape of the arrays might be altered, \ref run() expects
26 - `x`: array of the the positional data along the sensor.
27 - `y`: array of the time stamps, and
28 - `z`: array of the strain data.
33 A filter, that removes any columns from a given number of data sets (matrix), that contain `not a number` entries.
39 Construct an instance of the class.
40 \param axis \copydoc axis
41 \param *args Additional positional arguments, will be passed to the superconstructor.
42 \param **kwargs Additional keyword arguments will be passed to the superconstructor.
56 make_copy: bool =
True,
57 *args, **kwargs) -> tuple:
59 From the given `z` array, all columns or rows (depending on `axis`),
60 which contain contain `NaN`.
61 Corresponding entries of the coordinate vector (`x` or `y`) are removed aswell.
62 \param x Array of measuring point positions.
63 \param y Array of time stamps.
64 \param z Array of strain data in accordance to `x` and `y`.
65 \param axis \copydoc axis
66 \param make_copy Switch, whether a deepcopy of the passed data should be done.
68 \param *args Additional positional arguments to customize the behaviour.
69 \param **kwargs Additional keyword arguments to customize the behaviour.
70 \return Returns a tuple like `(x, y, z)`.
71 They correspond to the input variables of the same name
72 without columns or rows (depending on `axis`) containing `NaN`s.
74 axis = axis
if axis
is not None else self.
axis
75 x, y, z = super().
run(x, y, z, make_copy=make_copy, *args, **kwargs)
77 keep_array = np.isfinite(z)
80 keep_array = np.all(np.isfinite(z), axis=axis)
81 keep_indices = np.arange(keep_array.shape[0])[keep_array]
82 z = np.take(z.T, keep_indices, axis=axis).T
83 if axis == 0
and x.ndim == 1:
85 if axis == 1
and y.ndim == 1:
91 Replace dropouts (`NaN`s) with values interpolated by the given method.
92 The following steps are carried out:
93 1. The `NaN` values are removed using \ref NaNFilter.
94 Hence, an extra dropout removal before is not beneficial.
95 2. An interpolation function is calulated based on the dropout-free `x` and `z`.
96 3. The interpolation function is evaluated on the original `x`.
98 This is a wrapper for \ref fosanalysis.utils.interpolation.scipy_interpolate1d().
101 method: str =
"Akima1DInterpolator",
102 method_kwargs: dict =
None,
105 Construct an ScipyInterpolation1D object.
106 \param method \copydoc method
107 \param method_kwargs \copydoc method_kwargs
108 \param *args Additional positional arguments, will be passed to the superconstructor.
109 \param **kwargs Additional keyword arguments will be passed to the superconstructor.
139 timespace: str =
None,
140 make_copy: bool =
True,
142 method_kwargs: dict =
None,
143 *args, **kwargs) -> tuple:
145 \copydoc ScipyInterpolation1D
146 \copydetails preprocessing.base.Task.run()
147 \param method \copydoc method
148 \param method_kwargs \copydoc method_kwargs
150 return super().
run(x, y, z,
154 method_kwargs=method_kwargs,
160 method_kwargs: dict =
None,
161 *args, **kwargs) -> tuple:
163 Replace dropouts (`NaN`s) with values interpolated by the given method.
164 \param x Array of measuring point positions in accordance to `z`.
165 \param z Array of strain data in accordance to `x`.
166 \param method \copydoc method
167 \param method_kwargs \copydoc method_kwargs
168 \param *args Additional positional arguments, ignored.
169 \param **kwargs Additional keyword arguments, ignored.
170 \return Returns a tuple of like `(x, z)` of `np.array`s of the same shape.
172 method = method
if method
is not None else self.
method
173 method_kwargs = method_kwargs
if method_kwargs
is not None else self.
method_kwargs
174 method_kwargs = method_kwargs
if method_kwargs
is not None else {}
175 x_clean, y_clean, z_clean = self.
nanfilter.
run(x,
None, z)
176 z_new = scipy_interpolate1d(
188 *args, **kwargs) -> tuple:
190 ScipyInterpolation1D has no true 2D operation mode.
191 Set \ref timespace to `"1d_space"`!
193 raise NotImplementedError(
"ScipyInterpolation1D does not support true 2D operation. Please use `timepace='1d_space'` instead.")
Abstract base class for preprocessing classes.
Abstract base class for preprocessing task classes.
A filter, that removes any columns from a given number of data sets (matrix), that contain not a numb...
axis
Axis of slices to be removed, if they contain any NaNs.
tuple run(self, np.array x, np.array y, np.array z, int axis=None, bool make_copy=True, *args, **kwargs)
From the given z array, all columns or rows (depending on axis), which contain contain NaN.
__init__(self, int axis=0, *args, **kwargs)
Construct an instance of the class.
Base class for algorithms to replace/remove missing data with plausible values.
Replace dropouts (NaNs) with values interpolated by the given method.
tuple _run_1d(self, np.array x, np.array z, str method=None, dict method_kwargs=None, *args, **kwargs)
Replace dropouts (NaNs) with values interpolated by the given method.
tuple _run_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, *args, **kwargs)
ScipyInterpolation1D has no true 2D operation mode.
method_kwargs
This dictionary contains optional keyword arguments for method.
__init__(self, str method="Akima1DInterpolator", dict method_kwargs=None, *args, **kwargs)
Construct an ScipyInterpolation1D object.
method
Name of the interpolation function to use.
nanfilter
NaNFilter object used to temporarily remove NaNs.
tuple run(self, np.array x, np.array y, np.array z, str timespace=None, bool make_copy=True, str method=None, dict method_kwargs=None, *args, **kwargs)
Replace dropouts (NaNs) with values interpolated by the given method.
Contains functionality for interpolating data.