3Contains the base class for all preprocessing classes.
9from abc
import abstractmethod
14from fosanalysis
import utils
18 Abstract base class for preprocessing classes.
24 Construct an instance of the class.
25 As this is an abstract class, it may not be instantiated directly itself.
26 \param *args Additional positional arguments, will be passed to the superconstructor.
27 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
35 make_copy: bool =
True,
36 *args, **kwargs) -> tuple:
38 Each preprocessing.Base object has a `run()` method to carry out
39 the preprocessing task and return the preprocessed data.
40 \param x Array of measuring point positions.
41 \param y Array of time stamps.
42 \param z Array of strain data in accordance to `x` and `y`.
43 \param make_copy Switch, whether a deepcopy of the passed data should be done.
45 \param *args Additional positional arguments to customize the behaviour.
46 \param **kwargs Additional keyword arguments to customize the behaviour.
47 \return Returns a tuple like `(x, y, z)`.
48 They correspond to the input variables of the same name.
49 Each of those might be changed.
51 x, y, z = [np.array(data)
for data
in [x, y, z]]
53 x, y, z = [copy.deepcopy(data)
for data
in [x, y, z]]
58 Abstract base class for preprocessing task classes.
61 timespace: str =
"1d_space",
64 Construct an instance of the class.
65 As this is an abstract class, it may not be instantiated directly itself.
66 \param timespace \copybrief timespace For more, see \ref timespace.
67 \param *args Additional positional arguments, will be passed to the superconstructor.
68 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
85 make_copy: bool =
True,
86 timespace: str =
None,
87 *args, **kwargs) -> tuple:
89 Each preprocessing.Task object has a `run()` method.
90 The actual operations are reimplemented in \ref _run_1d() and \ref _run_2d().
91 This method decides based on the argument, how is operated over the data.
92 If `z` is a 1D array, the array to pass to \ref _run_1d() is determined:
93 1. Use `x` as the coordinate data, if it matches the shape of `z`.
94 2. Use `y` as the coordinate data, if it matches the shape of `z`.
95 3. Generate an array with indices of the shape of `z`.
97 If `z` is a 2D array, three option are available, based on `timespace`:
98 \copydetails timespace
100 \param x Array of measuring point positions.
101 \param y Array of time stamps.
102 \param z Array of strain data in accordance to `x` and `y`.
103 \param timespace \copybrief timespace For more, see \ref timespace.
104 Defaults to \ref timespace.
105 \param make_copy Switch, whether a deepcopy of the passed data should be done.
107 \param *args Additional positional arguments to customize the behaviour.
108 Will be passed to the chosen method to call.
109 \param **kwargs Additional keyword arguments to customize the behaviour.
110 Will be passed to the chosen method to call.
111 \return Returns a tuple like `(x, y, z)`.
112 They correspond to the input variables of the same name.
113 Each of those might be changed.
115 timespace = timespace
if timespace
is not None else self.
timespace
116 x, y, z = super().
run(x, y, z, make_copy=make_copy, *args, **kwargs)
119 x_dim = x.shape == z.shape
120 y_dim = y.shape == z.shape
123 x = np.arange(z.shape[0])
126 y = np.arange(z.shape[0])
129 x, z = self.
_run_1d(x, z, *args, **kwargs)
131 y, z = self.
_run_1d(y, z, *args, **kwargs)
133 x_tmp = np.arange(z.shape[0])
134 x_tmp, z = self.
_run_1d(x_tmp, z, *args, **kwargs)
137 x_dim = (x.ndim == 1
and x.shape[0] == z.shape[1])
138 y_dim = (y.ndim == 1
and y.shape[0] == z.shape[0])
141 x = np.arange(z.shape[1])
142 timespace =
"1d_time"
145 y = np.arange(z.shape[0])
146 timespace =
"1d_space"
147 if not x_dim
and not y_dim:
148 raise ValueError(
"Could not decide the 1D operation mode, as both x and y are None")
149 if timespace.lower() ==
"2d":
150 x, y, z = self.
_run_2d(x, y, z, *args, **kwargs)
152 x, y, z = self.
_map_2d(x, y, z, timespace=timespace, *args, **kwargs)
154 raise ValueError(
"Dimension of z ({}) non-conformant!".format(z.ndim))
164 *args, **kwargs) -> tuple:
166 Reimplementations describe a one-dimensional operation.
167 This operation might be applied to on a 2D array by \ref _map_2d().
168 This function is called, if:
170 - \ref timespace is set to `"1d_space"` or `"1d_time"`.
171 \param x Array of coordinate positions.
172 Dependent on \ref timespace it may hold:
173 - `x`: sensor coordinates, (`timespace = "1d_space"`)
174 - `y`: time data (`timespace = "1d_time"`)
175 - indices, if none of both previous options match the `z`'s shape.
176 \param z Array of strain data in accordance to `x` and `y`.
177 \param *args Additional positional arguments to customize the behaviour.
178 \param **kwargs Additional keyword arguments to customize the behaviour.
179 \return Returns a tuple like `(x, z)`.
180 They correspond to the input variables of the same name.
181 Each of those might be changed.
183 raise NotImplementedError()
188 *args, **kwargs) -> tuple:
190 Native two-dimensional operation implementation.
191 Needs to be reimplemented by sub-classes.
192 This function is only called, if `z` is 2D and \ref timespace is `"2D"`.
193 \param x Array of measuring point positions.
194 \param y Array of time stamps.
195 \param z Array of strain data in accordance to `x` and `y`.
196 \param *args Additional positional arguments to customize the behaviour.
197 \param **kwargs Additional keyword arguments to customize the behaviour.
198 \return Returns a tuple like `(x, y, z)`.
199 They correspond to the input variables of the same name.
200 Each of those might be changed.
202 raise NotImplementedError()
207 timespace: str =
None,
208 *args, **kwargs) -> tuple:
210 Apply the 1D operation along either the space or time timespace.
211 Used for carrying out 1D-only algorithms on a 2D array row- or column-wise.
212 \param x Array of measuring point positions.
213 \param y Array of time stamps.
214 \param z Array of strain data in accordance to `x` and `y`.
215 \param timespace \copybrief timespace For more, see \ref timespace.
216 Defaults to \ref timespace.
217 \param *args Additional positional arguments to customize the behaviour.
218 Will be passed to the chosen method to call.
219 \param **kwargs Additional keyword arguments to customize the behaviour.
220 Will be passed to the chosen method to call.
221 \return Returns a tuple like `(x, y, z)`.
222 They correspond to the input variables of the same name.
223 Each of those might be changed.
225 timespace = timespace
if timespace
is not None else self.
timespace
229 if timespace.lower() ==
"1d_space":
230 for row_id, row
in enumerate(z):
231 x_new, z_row = self.
_run_1d(x, row, *args, **kwargs)
233 z_new = np.array(z_new)
234 elif timespace.lower() ==
"1d_time":
235 for col_id, column
in enumerate(z.T):
236 y_new, z_col = self.
_run_1d(y, column, *args, **kwargs)
238 z_new = np.array(z_new).T
240 raise ValueError(
"No such option for timespace known: '{}'.".format(timespace))
241 return x_new, y_new, z_new
Abstract base class for preprocessing classes.
__init__(self, *args, **kwargs)
Construct an instance of the class.
tuple run(self, np.array x=None, np.array y=None, np.array z=None, bool make_copy=True, *args, **kwargs)
Each preprocessing.Base object has a run() method to carry out the preprocessing task and return the ...
Abstract base class for preprocessing task classes.
tuple run(self, np.array x=None, np.array y=None, np.array z=None, bool make_copy=True, str timespace=None, *args, **kwargs)
Each preprocessing.Task object has a run() method.
tuple _map_2d(self, np.array x, np.array y, np.array z, str timespace=None, *args, **kwargs)
Apply the 1D operation along either the space or time timespace.
__init__(self, str timespace="1d_space", *args, **kwargs)
Construct an instance of the class.
tuple _run_1d(self, np.array x, np.array z, *args, **kwargs)
Reimplementations describe a one-dimensional operation.
tuple _run_2d(self, np.array x, np.array y, np.array z, *args, **kwargs)
Native two-dimensional operation implementation.
timespace
Indicator, which approach is used for operations on a 2d array.
This intermediate class indicates, that a sub-class is implementing a task.