fosanalysis
A framework to evaluate distributed fiber optic sensor data
Loading...
Searching...
No Matches
separation.py
Go to the documentation of this file.
2r"""
3Contains functionality to separate cracks and set transfer lengths.
4\author Bertram Richter
5\date 2022
6"""
7
8import copy
9import numpy as np
10
11from fosanalysis import utils
12
13from . import cracks
14
16 r"""
17 Assigns the transfer length to a all \ref cracks.Crack objects in a \ref cracks.CrackList.
18 """
19 def __init__(self, **methods: dict):
20 r"""
21 Constructs a CrackLength object.
22 \param methods \copybrief methods For more, see \ref methods.
23 """
24
47 self.methods = methods if methods else {"min": True, "length": 0.2, "reset": "inner"}
48 def _first_index_leq_threshold(self, data, threshold) -> int:
49 r"""
50 Return the index of the first entry in `data`, that is less or equal than the given threshold and `None`, if no entry fulfills this condition.
51 """
52 for i, x in enumerate(data):
53 if x <= threshold:
54 return i
55 return None
56 def run(self,
57 x,
58 strain,
59 crack_list: cracks.CrackList) -> cracks.CrackList:
60 r"""
61 Estimates the transfer length of all cracks according to \ref methods.
62 Limits that are `None` are replaced by \f$-\infty\f$ for the left and \f$\infty\f$ right limit prior to the assignments
63 \param x Positional x values.
64 \param strain List of strain values.
65 \param crack_list \ref cracks.CrackList with \ref cracks.Crack objects, that already have assigned locations.
66 \return Returns a \ref cracks.CrackList object.
67 """
68 crack_list.sort()
69 for crack in crack_list:
70 crack.x_l = crack.x_l if crack.x_l is not None else -np.inf
71 crack.x_r = crack.x_r if crack.x_r is not None else np.inf
72 methods = copy.deepcopy(self.methods)
73 reset = methods.pop("reset", None)
74 if reset is not None:
75 for i, crack in enumerate(crack_list):
76 if i < len(crack_list)-1 or reset == "all":
77 crack.x_r = np.inf
78 if i > 0 or reset == "all":
79 crack.x_l = -np.inf
80 for method, value in methods.items():
81 for i, crack in enumerate(crack_list):
82 if method == "middle":
83 if i > 0:
84 middle = (crack_list[i-1].location + crack.location)/2
85 crack.x_l = max(middle, crack.x_l)
86 crack_list[i-1].x_r = min(middle, crack_list[i-1].x_r)
87 elif method == "min":
88 if i > 0:
89 left_peak_index = crack_list[i-1].index
90 right_peak_index = crack.index
91 left_valley = strain[left_peak_index:right_peak_index]
92 min_index = np.argmin(left_valley) + left_peak_index
93 crack.x_l = max(x[min_index], crack.x_l)
94 crack_list[i-1].x_r = min(x[min_index], crack_list[i-1].x_r)
95 elif method == "threshold":
96 left_peak_index = crack_list[i-1].index if i > 1 else 0
97 right_peak_index = crack.index[i+1] if i < len(x) - 1 else len(len(x) - 1)
98 left_valley = strain[left_peak_index:crack.index+1].reverse()
99 right_valley = strain[crack.index:right_peak_index+1]
100 l_index = self._first_index_leq_threshold(left_valley, value)
101 r_index = self._first_index_leq_threshold(right_valley, value)
102 if l_index is not None:
103 crack.x_l = x[crack.index - l_index]
104 if r_index is not None:
105 crack.x_r = x[crack.index + r_index]
106 elif method == "length":
107 crack.x_l = max(crack.location - value, crack.x_l)
108 crack.x_r = min(crack.location + value, crack.x_r)
109 else:
110 raise ValueError("No such option '{}' known for `method`.".format(method))
111 return crack_list
Assigns the transfer length to a all cracks.Crack objects in a cracks.CrackList.
Definition separation.py:15
cracks.CrackList run(self, x, strain, cracks.CrackList crack_list)
Estimates the transfer length of all cracks according to methods.
Definition separation.py:59
__init__(self, **dict methods)
Constructs a CrackLength object.
Definition separation.py:19
int _first_index_leq_threshold(self, data, threshold)
Return the index of the first entry in data, that is less or equal than the given threshold and None,...
Definition separation.py:48
methods
Dictionary of methods to restrict the effective lengths of a crack with their respective options.
Definition separation.py:47
This intermediate class indicates, that a sub-class is implementing a task.
Definition base.py:26