fosanalysis
A framework to evaluate distributed fiber optic sensor data
Loading...
Searching...
No Matches
gettingstarted.py
Go to the documentation of this file.
1r"""
2This script shows how to interact with `fosanalysis`.
3It is the resulting script of [Getting Started](doc/GettingStarted.md).
4\author Bertram Richter
5\date 2022
6"""
7
8# Importing necessary modules
9import matplotlib.pyplot as plt
10import fosanalysis as fa
11
12# Global plot settings
13plt.rcParams.update({
14 "svg.fonttype": "none",
15 "font.size": 10,
16 "axes.grid": True,
17 "axes.axisbelow": True,
18})
19
20# Loading data from file
21filepath = "data/demofile.tsv"
22handle = fa.datahandling.filehandler.FileHandler(filepath)
23
24# Retrieving data for one sensor
25x_axis = handle.sensors[0].x_axis
26times, strain_data = handle.get_measurements(handle.sensors[0].channel)
27
28x_axis = strain_data["All"]["x_axis"]
29strains = strain_data["All"]["strain"]
30
31# Generate objects for the preprocessing workflow.
32# Convert strain reading anomalies to dropouts
33maskingobject = fa.preprocessing.masking.GTM(delta_max=400,
34 forward_comparison_range=1,
35 activate_reverse_sweep=False,
36 )
37
38# Combine multiple readings of data into a 1D array.
39aggregateobject = fa.preprocessing.resizing.Aggregate(method="nanmedian")
40
41# Fix missing data by replacing it with plausible data or remove NaN readings.
42#repairobject = fa.preprocessing.repair.NaNFilter()
43repairobject = fa.preprocessing.repair.ScipyInterpolation1D()
44
45# Fix defines how to reduce ths base noise.
46filterobject = fa.preprocessing.filtering.SlidingFilter(radius=5, method="nanmedian")
47
48# Instantiate an object which defines the area of interest.
49cropobject = fa.preprocessing.resizing.Crop(start_pos=3, end_pos=5)
50
51
52tasklist = [
53 maskingobject,
54 aggregateobject,
55 repairobject,
56 filterobject,
57 cropobject,
58]
59
60# Instantiate the workflow object (it will call all task objects one after another).
61preprocessingobject = fa.preprocessing.Preprocessing(tasklist=tasklist)
62
63# Process the raw data according to the ruleset represented by the the preprocesssing object.
64x_processed, times, strain_processed = preprocessingobject.run(x=x_axis, y=times, z=strains)
65
66# Show the data, to visually compare raw to pre-processed data.
67plt.plot(x_axis, strains[0], label="raw")
68plt.plot(x_processed, strain_processed, label="processed")
69plt.legend(loc="best")
70plt.show()
71
72# Instantiate the strain profile object
73sp = fa.crackmonitoring.strainprofile.Concrete(x=x_processed, strain=strain_processed)
74
75# Calculate crack width
76sp.calculate_crack_widths()
77
78# Manually correct cracks:
79# - Remove the 4th and 5th crack (index 3 and 4)
80# - Add a crack at the position 3.7 m
81#
82# The width of the cracks are recalculated automatically.
83sp.delete_cracks(3, 4)
84sp.add_cracks(3.7)
85
86# Get the attributes of the calculated cracks.
87c_w = sp.crack_list.widths
88c_s = sp.crack_list.max_strains
89c_l = sp.crack_list.x_l
90c_loc = sp.crack_list.locations
91c_r = sp.crack_list.x_r
92
93# Plot preparation and plotting to show the result
94fig, ax1 = plt.subplots()
95ax1.set_xlabel("Position x [m]")
96ax1.set_ylabel("Strain [µm/m]")
97ax2 = ax1.twinx()
98ax2.set_ylabel("Crack width [µm]", c="red")
99ax2.tick_params(axis="y", labelcolor="red")
100ax1.plot(sp.x, sp.strain, c="k", label="strain")
101ax1.plot(sp.x, sp.tension_stiffening_values, c="k", ls="--", label="ts")
102ax1.plot(c_loc, c_s, c="k", ls="", marker="v", label="peak")
103ax1.plot(c_l, c_s, c="k", ls="", marker=">", label="left")
104ax1.plot(c_r, c_s, c="k", ls="", marker="<", label="right")
105ax2.plot(c_loc, c_w, c="red", ls="", marker="o", label="crack width")
106h1, l1 = ax1.get_legend_handles_labels()
107h2, l2 = ax2.get_legend_handles_labels()
108ax2.legend(loc="best", handles=h1 + h2, labels=l1 + l2)
109plt.show()