3Contains class implementations to remove implausible values from strain data.
4This can be used to remove strain reading anomalies (SRAs) from the data.
10from abc
import abstractmethod
17from .
import filtering
21 Abstract class for anomaly identification.
22 Strain reading anomalies (SRAs) are implausible data points.
23 SRAs are replaced by `NaN` values, effectively marking them as dropouts.
29 make_copy: bool =
True,
30 timespace: str =
None,
31 identify_only: bool =
False,
32 *args, **kwargs) -> np.array:
34 Mask strain reading anomalies with `NaN`s.
35 The strain data is replaced by `NaN` for all entries in the returned array being `True`.
37 \param identify_only If set to true, the array contains boolean
38 values, indicating a SRA by `True` and a valid entry by `False`.
40 \copydetails preprocessing.base.Task.run()
42 SRA_array = np.logical_not(np.isfinite(z))
44 x, y, SRA_array = super().
run(x, y, z,
52 z[SRA_array] = float(
"nan")
59 *args, **kwargs) -> tuple:
61 Estimate, which entries are strain reading anomalies, in 1D.
62 \copydetails preprocessing.base.Task._run_1d()
63 \param SRA_array Array of boolean values indicating SRAs by `True` and a valid entries by `False`.
64 This function returns the `SRA_array` instead of the `z` array.
73 *args, **kwargs) -> tuple:
75 \copydoc preprocessing.base.Task._run_2d()
76 \param SRA_array Array of boolean values indicating SRAs by `True` and a valid entries by `False`.
77 This function returns the `SRA_array` instead of the `z` array.
79 return x, y, SRA_array
85 timespace: str =
None,
86 *args, **kwargs) -> tuple:
88 Estimate, which entries are strain reading anomalies, in 2D.
89 \copydoc preprocessing.base.Task._map_2d()
90 \param SRA_array Array of boolean values indicating SRAs by `True` and a valid entries by `False`.
91 This function returns the `SRA_array` instead of the `z` array.
93 timespace = timespace
if timespace
is not None else self.timespace
94 if self.timespace.lower() ==
"1d_space":
95 for row_id, (row, SRA_row)
in enumerate(zip(z, SRA_array)):
96 x, SRA_array[row_id] = self.
_run_1d(x, row, SRA_array=SRA_row, *args, **kwargs)
97 elif self.timespace.lower() ==
"1d_time":
98 for col_id, (column, SRA_column)
in enumerate(zip(z.T, SRA_array.T)):
99 y, SRA_array.T[col_id] = self.
_run_1d(y, column, SRA_array=SRA_column, *args, **kwargs)
100 return x, y, SRA_array
104 The geometric threshold method (GTM) identifies SRAs by comparing the strain increments to a threshold.
105 The implementation is improved upon the algorithm presentend in \cite Bado_2021_Postprocessingalgorithmsfor.
106 Each entry is compared to the most recent entry accepted as plausible.
107 If the strain increment \f$\Delta_{\mathrm{max}}\f$ is exceeded,
108 the entry of the current index will be converted to a dropout by setting it to `NaN`.
109 Dropouts creating a geometrical distance greater than \f$\Delta_{\mathrm{max}}\f$,
110 would result in contigous dropout fields of extended length.
111 To avoid those dopout field, the current entry is additionally compared to its next finite neighbors.
112 The neighbor comparison uses a variable for the range,
113 which allows the user to set amount of neighbors to be compared.
114 Additional fine tuning can be performed by setting a percentage tolerance,
115 which allows a fraction of total neighbor comparisons to exceed \f$\Delta_{\mathrm{max}}\f$.
118 delta_max: float = 400.0,
119 forward_comparison_range: int = 1,
120 tolerance: float = 0.0,
121 to_left: bool =
False,
122 activate_reverse_sweep: bool =
True,
125 Construct a GTM object.
126 \param delta_max \copybrief delta_max For more, see \ref delta_max.
127 \param forward_comparison_range \copybrief forward_comparison_range For more, see \ref forward_comparison_range.
128 \param tolerance \copybrief tolerance For more, see \ref tolerance.
129 \param to_left \copybrief to_left For more, see \ref to_left.
130 \param activate_reverse_sweep \copybrief activate_reverse_sweep For more, see \ref activate_reverse_sweep.
131 \param *args Additional positional arguments, will be passed to the superconstructor.
132 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
135 assert delta_max > 0,
"Acceptable maximum strain increment (delta_max) must be greater than zero!"
136 assert forward_comparison_range >= 0,
"Number of neighbor to compare (forward_comparison_range) must not be negative!"
137 assert tolerance >= 0,
"Acceptable tolerance ratio of neighbors exceeding delta_max must be greater or equal to zero!"
180 Evaluate, if the candidate keeps its SRA flag by comparing it to
181 its succeeding neighbors. The candidate keeps its flag, if
183 r_{\mathrm{tol}} \cdot n_{\mathrm{tot}} < n_{\mathrm{ex}}
185 with the \ref tolerance ratio \f$r_{\mathrm{tol}}\f$,
186 the number of considered succeeding neighbors \f$n_{\mathrm{tot}}\f$,
187 which is the minimum of \ref forward_comparison_range and the
188 remaining elements to the end of the the `z` array, and
189 the number of considered neighbors \f$n_{\mathrm{ex}}\f$,
190 whose absolute difference to the candidate exceeds \ref delta_max.
191 \param z Array of strain data.
192 \param to_left \copybrief to_left For more, see \ref to_left.
193 \param index Current index of the flagged entry.
194 \return Returns, whether the candidate keeps ist SRA flag.
199 actual_neighbor_number = 0
201 n_i, neighbor = misc.next_finite_neighbor(array=z,
204 recurse=nth_neighbor)
208 actual_neighbor_number = actual_neighbor_number + 1
209 if abs(z[index] - neighbor) > self.
delta_max:
210 exceeding_amount = exceeding_amount + 1
211 if actual_neighbor_number == 0:
213 return (actual_neighbor_number * self.
tolerance < exceeding_amount)
218 start_index: int =
None,
219 end_index: int =
None,
220 to_left: bool =
None,
221 reverse_state: bool =
False,
222 *args, **kwargs) -> np.array:
224 Flag SRAs between the start and the end index (inclusive).
225 \param x Array of measuring point positions in accordance to `z`.
226 \param z Array of strain data in accordance to `x`.
227 \param SRA_array Array of boolean values indicating SRAs by `True` and a valid entries by `False`.
228 \param start_index Starting index of the method to filter the array.
229 The starting index is assumed not to be an anomalous reading.
230 \param end_index Last index to check in this sweep.
231 \param to_left \copybrief to_left For more, see \ref to_left.
232 \param reverse_state Switch indicating if the sweep method is currently reverse sweeping to set direction.
233 Default value is `False`.
234 Setting this switch to `True` supresses recursion.
235 \param *args Additional positional arguments, ignored.
236 \param **kwargs Additional keyword arguments, ignored.
238 to_left = to_left
if to_left
is not None else self.
to_left
242 start_index = start_index
if start_index
is not None else len(z)-1
243 end_index = end_index-1
if end_index
is not None else -1
246 start_index = start_index
if start_index
is not None else 0
247 end_index = end_index+1
if end_index
is not None else len(z)
248 index_last_trusted = start_index
250 for index
in range(start_index, end_index, step):
252 if not np.isnan(candidate):
254 flag = (abs(candidate - z[index_last_trusted]) > self.
delta_max
258 SRA_array[index]= flag
260 index_last_trusted = index
266 if (
not reverse_state
268 and abs(index - index_last_trusted) > 1):
273 end_index=index_last_trusted,
282 *args, **kwargs)->tuple:
284 GTM has no true 2D operation mode.
285 Set \ref timespace to `"1d_space"`!
287 raise NotImplementedError(
"GTM does not support true 2D operation. Please use `timepace='1d_space'` instead.")
291 Class for outlier detection an cancellation based on the outlier
292 specific correction procedure (OSCP) as originally presented in
293 \cite Ismail_2010_Anoutliercorrection and \cite Ismail_2014_EvaluationOutlierSpecific.
294 The outlier detection is a two stage algorithm.
295 The first stage, the detection of outlier candidates is based on the
296 height difference of a pixel to the median height of its surrounding.
297 If this height difference of a pixel exceeds a \ref threshold it is
298 marked as an outlier candidate.
299 The \ref threshold can be estimated from the data, based on the change
300 rate of the cumulated density function of all differences in the data.
301 In the second stage, groups are formed, limited by large differences
302 in-between two pixels, (like a simple edge detection).
303 The threshold for the difference is estimated like in the first stage.
304 The members of the groups are then assigned outlier or normal status.
305 Groups consisting of outlier candidates only are considered outlier.
306 All other groups are considered normal data.
307 Finally, all outliers are converted to `NaN`.
311 threshold: float =
None,
312 delta_s: float =
None,
313 n_quantile: int = 50,
314 min_quantile: float = 0.5,
315 timespace: str =
"1d_space",
318 Construct an instance of the class.
319 \param max_radius \copybrief max_radius \copydetails max_radius
320 \param delta_s \copybrief delta_s \copydetails delta_s
321 \param n_quantile \copybrief n_quantile \copydetails n_quantile
322 \param threshold \copybrief threshold \copydetails threshold
323 \param min_quantile \copybrief min_quantile \copydetails min_quantile
324 \param timespace \copybrief timespace \copydetails timespace
325 \param *args Additional positional arguments, will be passed to the superconstructor.
326 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
328 super().
__init__(timespace=timespace, *args, **kwargs)
329 assert delta_s
is not None or threshold
is not None,
"Either delta_s or threshold must be set!"
363 *args, **kwargs) -> tuple:
365 Estimate which entries are strain reading anomalies in 1D.
366 \copydetails AnomalyMasker._run_1d()
376 *args, **kwargs) -> tuple:
378 Estimate which entries are strain reading anomalies in 2D.
379 \copydetails AnomalyMasker._run_2d()
383 return x, y, SRA_array
386 Detect outlier candidates in the given strain data.
387 This is the first phase according to \cite Ismail_2010_Anoutliercorrection.
388 For each radius \f$r \in [1, r_{\mathrm{max}}]\f$, the relative
389 height of all pixels is compared to the \ref threshold.
390 \param z Array containing strain data.
391 \param SRA_array Array indicating, outlier condidates.
392 \return Returns an updated `SRA_array`, with outlier candidates.
397 candidate_array = height_array > threshold
398 SRA_array = np.logical_or(SRA_array, candidate_array)
402 This is the second phase of the algorithm according to
403 \cite Ismail_2010_Anoutliercorrection, adapted for 1D operation.
404 Outlier candidates are verified as SRAs, by building groups, which
405 are bordered by large enough increments between neighboring entries.
406 The increment threshold is estimated by \ref _get_threshold().
408 Three different types of groups are possible:
409 1. normal pixels only,
410 2. mixed normal pixels and outlier candidates,
411 3. outlier candidates only.
413 Groups of the third type are considered outliers.
414 Outlier candidates in mixed groups are reaccepted as normal data.
416 \param z Array containing strain data.
417 \param SRA_array Array indicating, outlier condidates.
418 \return Returns an updated `SRA_array` with the identified SRAs.
420 height_array = np.abs(misc.nan_diff(z, axis=0))
422 group_boundaries = np.argwhere(np.greater(height_array, threshold))
424 for boundary
in group_boundaries:
426 group = SRA_array[i_prev:i]
427 group[:] = np.all(group)
429 group = SRA_array[i_prev:
None]
430 group[:] = np.all(group)
434 This is the second phase of the algorithm according to
435 \cite Ismail_2010_Anoutliercorrection, adapted for 2D operation.
436 \copydetails _verify_candidates_1d()
438 Adaptation to a 2D takes some more steps, because the building of
439 the groups is not as straight-forward as in 1D.
440 This is not described in \cite Ismail_2010_Anoutliercorrection
441 and \cite Ismail_2014_EvaluationOutlierSpecific, so a detailed
442 description of the taken approach is provided here.
443 The detection of group boundaries is separated for each direction.
444 Once along the space axis and once along the time axis separately,
445 increments are calculated and the increment threshold is estimated
446 by \ref _get_threshold().
447 The next step (still separated for each direction) is generating
448 groups of indices by iterating over the arrays indices.
449 A new group is started if
450 - the current index is contained in the set of group boundaries
451 (indices of the group's start) or
452 - a new row (or column) is started (that is the end of the array
453 in this direction is reached and the iteration resumes with
454 the first entry of the next line.
456 After all such groups are stored in a single list, the groups of
457 indices are merged using \ref _merge_groups(), until only pairwise
458 distinct groups are left.
459 If a pixel is contained in two groups, those groups are connected
461 This results in non-rectangular shaped groups being built.
463 Finally, only groups containing candidates only are verified as SRA.
466 for fast_axis, length
in enumerate(z.shape):
467 slow_axis = fast_axis -1
469 height_array = np.abs(misc.nan_diff(z, axis=fast_axis))
472 group_boundaries = np.argwhere(np.greater(height_array, threshold))
474 offset = np.zeros(len(z.shape), dtype=int)
475 offset[fast_axis] += 1
476 group_boundaries = group_boundaries + offset
477 group_boundaries = {tuple(boundary)
for boundary
in group_boundaries}
479 for slow
in range(z.shape[slow_axis]):
481 index[slow_axis] = slow
482 for fast
in range(z.shape[fast_axis]):
483 index[fast_axis] = fast
484 if tuple(index)
in group_boundaries:
485 group_list.append(group)
487 group.add(tuple(index))
488 group_list.append(group)
491 for group
in final_groups:
493 group_indices = tuple(np.array(list(group)).T)
495 SRA_array[group_indices] = np.all(SRA_array[group_indices])
499 Get the height difference to the local vicinity of all the pixels.
500 The median height is retrieved by \ref filtering.SlidingFilter.
501 The local vicinity is determined by the inradius \f$r\f$ or the
502 quadratic sliding window (see \ref filtering.SlidingFilter.radius).
503 Then, the absolute difference between the array of the median and
504 and the pixels's values is returned.
505 \param z Array containing strain data.
506 \param radius Inradius of the sliding window.
511 timespace=self.timespace)
512 x_tmp, y_tmp, median_array = local_height_calc.run(
517 return np.abs(z - median_array)
520 Get quantiles of the the given data (including finite values only).
521 Only quantiles above \ref min_quantile are returned.
522 If \ref n_quantile is `None`, the upper part (> \ref min_quantile)
523 of the sorted values is returned.
524 Else, the upper part is resampled into \ref n_quantile + 1 points.
525 \param values Array, for which to calculate the quantiles.
529 return cdf, np.nanquantile(values, cdf)
531 clean = values[np.isfinite(values)]
532 sorted_heights = np.sort(clean, axis=
None)
533 length = sorted_heights.shape[0]
534 first_index = np.floor(length*self.
min_quantile).astype(int)
535 cdf = np.linspace(1/length, 1, length)
536 return cdf[first_index:
None], sorted_heights[first_index:
None]
539 Estimate the anomaly threshold from the data.
540 The threshold \f$t\f$ is set to the point, where the cumulated
541 density function is leveled out. That is, whre the required
542 increase in value per increase in quantile exceeds \ref delta_s.
543 If \ref threshold is set to `None` it is determined from the
544 data and \ref delta_s, else it is simply returned.
545 \param values Array, from which to estimate the threshold.
550 change_rate = np.diff(quantiles)/np.diff(cdf)
551 is_over_threshold = np.greater(change_rate, self.
delta_s)
552 threshold_index = np.argmax(is_over_threshold)
553 if not np.any(is_over_threshold):
555 threshold = quantiles[threshold_index]
559 Merge all groups in the input that have at least one pairwise common entry.
560 Each group is a `set` of `tuple` standing for the strain array indices.
561 The result is a list of pairwise distinct groups, equivalent to the input.
562 \param initial_groups List of input groups (`set`s of `tuples`s).
565 initial_groups = copy.deepcopy(initial_groups)
566 while(initial_groups):
567 group_1 = initial_groups.pop()
568 merge_required = len(initial_groups) > 0
569 while merge_required:
570 merge_required =
False
571 for group_2
in copy.deepcopy(initial_groups):
572 if group_1.intersection(group_2):
573 merge_required =
True
574 initial_groups.remove(group_2)
575 group_1.update(group_2)
576 result.append(group_1)
581 Abstract base class for outlier detection by different kinds of z-scores.
582 After calculating the z-score by the given \ref _get_z_score(), SRAs
583 are identified by comparing the strain increments to a \ref threshold.
584 The algorithms only make sense for sufficient measuring values (not NaN).
585 An overview of all z-score calculations can be found at
586 https://towardsdatascience.com/removing-spikes-from-raman-spectra-8a9fdda0ac22
589 threshold: float = 3.5,
590 timespace: str =
"1d_space",
593 Construct an instance of the class.
594 \param threshold \copydoc threshold
595 \param timespace \copybrief timespace \copydetails timespace
596 \param *args Additional positional arguments, will be passed to the superconstructor.
597 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
599 super().
__init__(timespace=timespace, *args, **kwargs)
607 *args, **kwargs) -> tuple:
609 Estimate which entries are strain reading anomalies in 1D.
610 \copydetails AnomalyMasker._run_1d()
620 *args, **kwargs) -> tuple:
622 Estimate which entries are strain reading anomalies in 2D.
623 \copydetails AnomalyMasker._run_2d()
627 return x, y, SRA_array
630 Mask entries as SRA, whose z-scores exceed \ref threshold.
631 \param z_score Array containing the z-score values.
632 \return Boolean array with values as outlier mask.
634 mask = np.array(np.abs(z_score) > self.
threshold)
639 Calculate the z-score for the given array.
640 Sub-classes need to provide a meaningful implementation.
642 raise NotImplementedError()
646 Class for the standard z-score approach for spike detection.
647 Describing a data point in terms of its relationship to the mean and
648 standard deviation of strain values.
649 The method can be mainly used for constant (noise) signals.
650 See \cite Iglewicz_Hoaglin_1993_How_to_detect_and_handle_outliers.
654 Calculates the z-score of the given strain array with mean and standard deviation.
655 \param z Array containing strain data.
656 \return Returns a z-score array.
660 z_score = (z - mean) / stdev
665 Class for the modified z-score approach for spike detection.
666 This method uses the median and the median absolute deviation
667 rather than the mean and standard deviation.
668 The multiplier 0.6745 is the 0.75th quantile of the standard normal distribution.
669 Disadvantage: Peaks can also detect as strain reading anomaly.
670 See \cite Iglewicz_Hoaglin_1993_How_to_detect_and_handle_outliers.
674 Calculates the modified z-score of the given strain array.
675 \param z Array containing strain data.
676 \return Returns an array modified z-score.
678 median_value = np.nanmedian(z)
679 mad_array = np.nanmedian(np.abs(z - median_value))
680 z_score = 0.6745 * ((z - median_value) / mad_array)
685 Class that calculates the modified zscore over a moving window.
686 The window is defined by the given radius and has a width of \f$2r+1\f$.
687 The median will be calculated only for the current vicinity.
691 threshold: float = 3.5,
692 timespace: str =
"1d_space",
695 Construct an instance of the class.
696 \param radius \copybrief radius \copydetails radius
697 \param threshold \copydoc threshold
698 \param timespace \copybrief timespace \copydetails timespace
699 \param *args Additional positional arguments, will be passed to the superconstructor.
700 \param **kwargs Additional keyword arguments, will be passed to the superconstructor.
702 super().
__init__(timespace=timespace, threshold=threshold, *args, **kwargs)
709 Calculates the modified z-score with the absolute deviation of current vicinity.
710 If the MAD is zero, the mean of the absolute deviation will be used.
711 \param z Array containing strain data.
712 \return Returns an array modified z-score.
715 median_array = np.nanmedian(z)
717 median_array = windows.sliding_window_function(z, self.
radius, np.nanmedian)
718 values = z - median_array
719 ad_values = np.abs(values)
720 mad = np.nanmedian(ad_values)
722 factor = mad / 0.6745
724 factor = np.nanmean(ad_values) / 0.7979
725 z_score = values / factor
730 The Whitaker & Hayes algorithm uses the high intensity and small width of spikes.
731 Therefore it uses the difference between a strain value and the next value.
732 The algorithm presented in \cite Whitaker_2018_ASimpleAlgorithmDespiking.
736 Calculates the difference between the current strain
737 and the following strain of the given strain array.
738 \param z Array containing strain data.
739 \return Returns an array delta strain.
741 delta_s = misc.nan_diff_1d(z)
742 delta_s = np.insert(delta_s, 0, np.nan)
746 Calculates the modified z-score of the given strain array.
747 It uses the median and median absolute deviation.
748 The multiplier 0.6745 is the 0.75th quartile of the standard normal distribution.
749 \param z Array containing strain data.
750 \return Returns an array modified z-score.
753 median_value = np.nanmedian(delta_s)
754 mad_array = np.nanmedian(np.abs(delta_s - median_value))
755 z_score = 0.6745 * ((delta_s - median_value) / mad_array)
Abstract base class for filter classes, based on sliding windows.
Abstract class for anomaly identification.
np.array run(self, np.array x, np.array y, np.array z, bool make_copy=True, str timespace=None, bool identify_only=False, *args, **kwargs)
Mask strain reading anomalies with NaNs.
tuple _run_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, *args, **kwargs)
Native two-dimensional operation implementation.
tuple _run_1d(self, np.array x, np.array z, np.array SRA_array, *args, **kwargs)
Estimate, which entries are strain reading anomalies, in 1D.
tuple _map_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, str timespace=None, *args, **kwargs)
Estimate, which entries are strain reading anomalies, in 2D.
The geometric threshold method (GTM) identifies SRAs by comparing the strain increments to a threshol...
tuple _run_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, *args, **kwargs)
GTM has no true 2D operation mode.
to_left
Switch for the direction of operation.
bool _compare_forward(self, np.array z, int index, bool to_left)
Evaluate, if the candidate keeps its SRA flag by comparing it to its succeeding neighbors.
np.array _run_1d(self, np.array x, np.array z, np.array SRA_array, int start_index=None, int end_index=None, bool to_left=None, bool reverse_state=False, *args, **kwargs)
Flag SRAs between the start and the end index (inclusive).
delta_max
Maximum plausible absolute strain increment in [µm/m].
tolerance
Tolerance ratio for the forward comparison to reaccept a candidate.
activate_reverse_sweep
Switch to activate the reverse sweep.
forward_comparison_range
Number of neighbors to consider in the forward neighbor comparison.
__init__(self, float delta_max=400.0, int forward_comparison_range=1, float tolerance=0.0, bool to_left=False, bool activate_reverse_sweep=True, *args, **kwargs)
Construct a GTM object.
Class for the modified z-score approach for spike detection.
np.array _get_z_score(self, np.array z)
Calculates the modified z-score of the given strain array.
Class for outlier detection an cancellation based on the outlier specific correction procedure (OSCP)...
np.array _outlier_candidates(self, z, SRA_array)
Detect outlier candidates in the given strain data.
delta_s
Setting for the threshold estimation.
np.array _verify_candidates_2d(self, z, SRA_array)
This is the second phase of the algorithm according to ismail_2010_anoutliercorrection,...
threshold
Relative height threshold above which a pixel is flagged as SRA.
tuple _run_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, *args, **kwargs)
Estimate which entries are strain reading anomalies in 2D.
n_quantile
Granularity for the threshold estimation resampling.
float _get_threshold(self, np.array values)
Estimate the anomaly threshold from the data.
list _merge_groups(self, initial_groups)
Merge all groups in the input that have at least one pairwise common entry.
max_radius
The radius of the largest sliding window used in the outlier candidate detection stage determines th...
tuple _run_1d(self, np.array x, np.array z, np.array SRA_array, *args, **kwargs)
Estimate which entries are strain reading anomalies in 1D.
min_quantile
The quantile, from which the cumulated density function of relative heights is kept for threshold est...
__init__(self, int max_radius, float threshold=None, float delta_s=None, int n_quantile=50, float min_quantile=0.5, str timespace="1d_space", *args, **kwargs)
Construct an instance of the class.
np.array _verify_candidates_1d(self, z, SRA_array)
This is the second phase of the algorithm according to ismail_2010_anoutliercorrection,...
tuple _get_quantiles(self, np.array values)
Get quantiles of the the given data (including finite values only).
np.array _get_median_heights(self, z, radius)
Get the height difference to the local vicinity of all the pixels.
Class that calculates the modified zscore over a moving window.
int radius
Inradius of the sliding window.
np.array _get_z_score(self, np.array z)
Calculates the modified z-score with the absolute deviation of current vicinity.
__init__(self, int radius=0, float threshold=3.5, str timespace="1d_space", *args, **kwargs)
Construct an instance of the class.
The Whitaker & Hayes algorithm uses the high intensity and small width of spikes.
np.array _get_z_score(self, np.array z)
Calculates the modified z-score of the given strain array.
np.array _get_delta_strain(self, np.array z)
Calculates the difference between the current strain and the following strain of the given strain arr...
Abstract base class for outlier detection by different kinds of z-scores.
np.array _get_z_score(self, np.array z)
Calculate the z-score for the given array.
tuple _run_2d(self, np.array x, np.array y, np.array z, np.array SRA_array, *args, **kwargs)
Estimate which entries are strain reading anomalies in 2D.
threshold
Relative height threshold above which a pixel is flagged as SRA.
tuple _run_1d(self, np.array x, np.array z, np.array SRA_array, *args, **kwargs)
Estimate which entries are strain reading anomalies in 1D.
np.array _get_outlier_mask(self, np.array z_score)
Mask entries as SRA, whose z-scores exceed threshold.
__init__(self, float threshold=3.5, str timespace="1d_space", *args, **kwargs)
Construct an instance of the class.
Class for the standard z-score approach for spike detection.
np.array _get_z_score(self, np.array z)
Calculates the z-score of the given strain array with mean and standard deviation.
This intermediate class indicates, that a sub-class is implementing a task.
Contains utility modules with general pupose.