3Contains class definitions for Crack and CrackList.
16 A Crack object presents a crack in concrete with its properties.
17 The attributes of a Crack object are additionally exposed in a
18 special `dict`-like interface
19 The `dict`-like interface should be preferred over calling the
21 Querying an unset (or nonexistant) attribute using the `dict`-like
22 interface returns `None` without raising an error.
23 Hence, attributes explicitely set to `None` or nonexitant report the same.
24 In this context, `None` means "N/A, no answer or not available".
27 location: float =
None,
31 max_strain: float =
None,
35 Constructs a Crack object.
36 \param location \copybrief location For more, see \ref location.
37 \param index \copybrief index For more, see \ref index.
38 \param x_l \copybrief x_l For more, see \ref x_l.
39 \param x_r \copybrief x_r For more, see \ref x_r.
40 \param max_strain \copybrief max_strain For more, see \ref max_strain.
41 \param width \copybrief width For more, see \ref width.
42 \param **kwargs Additional keyword arguments, stored as attributes ().
57 for key, value
in kwargs.items():
60 return getattr(self, key,
None)
62 return setattr(self, key, value)
71 Returns the length of the transfer length.
74 return self[
"x_r"] - self[
"x_l"]
79 r""" Distance from the crack position to the left-hand side end of its transfer length. """
81 return self[
"location"] - self[
"x_l"]
86 r""" Distance from the crack position to the right-hand side end of its transfer length. """
88 return self[
"x_r"] - self[
"location"]
94 Returns the absolute influence segment of the crack.
97 return self[
"x_l"], self[
"x_r"]
103 List of crack objects.
107 Constructs a CrackList.
108 \param crack_list Data, from which the CrackList is constructed.
110 - any number of \ref Crack objects,
111 - \ref Crack objects wrapped in a `list`, `tuple` or `set`,
112 - \ref CrackList object (same as above)
114 if len(crack_list) == 1
and hasattr(crack_list[0],
"__iter__"):
115 crack_list = crack_list[0]
116 assert all([isinstance(entry, Crack)
for entry
in crack_list]) \
117 or len(crack_list) == 0,
"At least one entry is not a Crack!"
121 r""" Returns a list with the left-hand side border of transfer length of all cracks. """
125 r""" Returns a list with the right-hand side border of transfer length of all cracks. """
129 r""" Returns a list with the locations of all cracks. """
133 r""" Returns a list with the peak strains of all cracks. """
137 r""" Returns a list with the widths of all cracks. """
141 Extract a list of values from the given attribute of all cracks.
142 \param attribute Name of the attribute to extract.
143 If the attribute of the crack object is not set, `None` is reported instead.
145 return [crack[attribute]
for crack
in self]
149 method: str =
"nearest",
150 make_copy: bool =
True,
151 placeholder: bool =
False,
154 Get a list of \ref Crack according to the given list of positions `locations` and the `method`.
155 \param locations Locations along the sensor to get cracks at.
156 \param tol Tolerance in location difference, to take a Crack into account.
157 Only used with `method = "nearest"`.
158 Defaults to `None`, which is turned off.
159 \param method Method how the cracks are selected.
161 - `"nearest"` (default): adds the crack to the CrackList,
162 for which the distance between the location of the crack
163 and the entry in `locations` is the smallest among all cracks.
164 - `"lt"`: returns the first crack, for which holds:
165 \f$x_{\mathrm{t,l}} < x \leq x_{\mathrm{t,r}}\f$.
166 \param make_copy If set to `True`, independent copies are returned.
168 \param placeholder Switch to report `None`, when no suitable Crack is found.
169 Defaults to `False`, which is no replacement.
170 \return Returns a \ref CrackList.
173 if method ==
"nearest":
175 crack_locations = np.array([entry
if entry
is not None else float(
"nan")
for entry
in crack_locations])
176 if not np.any(np.isfinite(crack_locations)):
177 return selected_crack_list
178 for loc
in locations:
179 dist = np.array(np.abs(loc - crack_locations))
180 min_index = np.nanargmin(dist)
181 if tol
is None or dist[min_index] <= tol:
182 selected_crack_list.append(self[min_index])
184 selected_crack_list.append(
None)
186 for loc
in locations:
190 if crack[
"x_l"] < loc <= crack[
"x_r"]:
195 if found_crack
is not None or placeholder:
196 selected_crack_list.append(found_crack)
198 raise ValueError(
"`method` '{}' unknown for getting a crack from CrackList.".format(method))
200 return copy.deepcopy(selected_crack_list)
202 return selected_crack_list
204 attribute: str =
"location",
205 minimum: float = -np.inf,
206 maximum: float = np.inf,
207 make_copy: bool =
True,
210 Get a list of \ref Crack objects according to the given attribute.
211 \param attribute Name of the relevant attribute.
212 \param minimum Threshold for the minimum accepted value of the attribute.
213 \param maximum Threshold for the maximum accepted value of the attribute.
214 \param make_copy if true, a deepcopy of the CrackList is returned.
215 \return Returns a \ref CrackList.
216 If no crack satisfies the condition, an empty CrackList is returned.
221 if minimum <= crack[attribute] <= maximum:
222 selected_crack_list.append(crack)
226 return copy.deepcopy(selected_crack_list)
228 return selected_crack_list
231 make_copy: bool =
True,
234 Get a list of \ref Crack whose `attribute` is None.
235 \param attribute Name of the relevant attribute.
236 \param make_copy If true, a deepcopy of the CrackList is returned.
237 \return Returns a \ref CrackList.
238 If no crack satisfies the condition, an empty CrackList is returned.
242 for i, attr
in enumerate(crack_attribute):
244 selected_crack_list.append(self[i])
246 return copy.deepcopy(selected_crack_list)
248 return selected_crack_list
251 make_copy: bool =
True,
254 Sets the attribute to `None` for each \ref Crack object contained.
257 new_cracklist = copy.deepcopy(self)
258 for crack_object
in new_cracklist:
259 del crack_object[attribute]
262 for crack_object
in self:
263 del crack_object[attribute]
265 def sort(self, attribute: str =
"location"):
267 Sort the list of \ref Crack according to the given attribute.
268 \param attribute Name of the relevant attribute.
271 index_list = np.argsort(orig_order)
272 self.
__init__(*(self[i]
for i
in index_list))
A Crack object presents a crack in concrete with its properties.
__init__(self, float location=None, int index=None, float x_l=None, float x_r=None, float max_strain=None, float width=None, **kwargs)
Constructs a Crack object.
lt_r(self)
Distance from the crack position to the right-hand side end of its transfer length.
__setitem__(self, key, value)
index
Position index in the sanitized measurement data of strainprofile.StrainProfile (e....
segment(self)
Returns the absolute influence segment of the crack.
lt(self)
Returns the length of the transfer length.
x_r
Absolute location right-hand side end of its transfer length.
lt_l(self)
Distance from the crack position to the left-hand side end of its transfer length.
x_l
Absolute location left-hand side end of its transfer length.
max_strain
The strain in the fibre-optical sensor at the location.
location
Absolute location (e.g.,\ in meters) along the fibre optical sensor.
width
The opening width of the crack.
list get_attribute_list(self, str attribute)
Extract a list of values from the given attribute of all cracks.
sort(self, str attribute="location")
Sort the list of Crack according to the given attribute.
list widths(self)
Returns a list with the widths of all cracks.
list max_strains(self)
Returns a list with the peak strains of all cracks.
list locations(self)
Returns a list with the locations of all cracks.
get_cracks_attribute_by_range(self, str attribute="location", float minimum=-np.inf, float maximum=np.inf, bool make_copy=True)
Get a list of Crack objects according to the given attribute.
list x_r(self)
Returns a list with the right-hand side border of transfer length of all cracks.
list x_l(self)
Returns a list with the left-hand side border of transfer length of all cracks.
get_cracks_attribute_is_none(self, str attribute, bool make_copy=True)
Get a list of Crack whose attribute is None.
get_cracks_by_location(self, *tuple locations, float tol=None, str method="nearest", bool make_copy=True, bool placeholder=False)
__init__(self, *crack_list)
Constructs a CrackList.
clear_attribute(self, str attribute, bool make_copy=True)
Sets the attribute to None for each Crack object contained.