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–2026
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, data = handle.get_measurements(handle.sensors[0].channel)
27x_axis = data['All'].get('x_axis', [])
28strain = data['All'].get('strain', [])
29
30# Generate objects for the preprocessing workflow.
31# Convert strain reading anomalies to dropouts
32maskingobject = fa.preprocessing.masking.GTM(delta_max=400,
33 forward_comparison_range=1,
34 activate_reverse_sweep=False,
35 )
36
37# Combine multiple readings of data into a 1D array.
38aggregateobject = fa.preprocessing.resizing.Aggregate(method="nanmedian")
39
40# Fix missing data by replacing it with plausible data or remove NaN readings.
41#repairobject = fa.preprocessing.repair.NaNFilter()
42repairobject = fa.preprocessing.repair.ScipyInterpolation1D()
43
44# Fix defines how to reduce ths base noise.
45filterobject = fa.preprocessing.filtering.SlidingFilter(radius=5, method="nanmedian")
46
47# Instantiate an object which defines the area of interest.
48cropobject = fa.preprocessing.resizing.Crop(start_pos=3, end_pos=5)
49
50
51tasklist = [
52 maskingobject,
53 aggregateobject,
54 repairobject,
55 filterobject,
56 cropobject,
57]
58
59# Instantiate the workflow object (it will call all task objects one after another).
60preprocessingobject = fa.preprocessing.Preprocessing(tasklist=tasklist)
61
62# Process the raw data according to the ruleset represented by the the preprocesssing object.
63x_processed, times, strain_processed = preprocessingobject.run(x=x_axis, y=times, z=strain)
64
65# Show the data, to visually compare raw to pre-processed data.
66plt.plot(x_axis, strain[0], label="raw")
67plt.plot(x_processed, strain_processed, label="processed")
68plt.legend(loc="best")
69plt.show()
70
71# Instantiate the strain profile object
72sp = fa.crackmonitoring.strainprofile.Concrete(x=x_processed, strain=strain_processed)
73
74# Calculate crack width
75sp.calculate_crack_widths()
76
77# Manually correct cracks:
78# - Remove the 4th and 5th crack (index 3 and 4)
79# - Add a crack at the position 3.7 m
80#
81# The width of the cracks are recalculated automatically.
82sp.delete_cracks(3, 4)
83sp.add_cracks(3.7)
84
85# Get the attributes of the calculated cracks.
86c_w = sp.crack_list.widths
87c_s = sp.crack_list.max_strains
88c_l = sp.crack_list.x_l
89c_loc = sp.crack_list.locations
90c_r = sp.crack_list.x_r
91
92# Plot preparation and plotting to show the result
93fig, ax1 = plt.subplots()
94ax1.set_xlabel("Position x [m]")
95ax1.set_ylabel("Strain [µm/m]")
96ax2 = ax1.twinx()
97ax2.set_ylabel("Crack width [µm]", c="red")
98ax2.tick_params(axis="y", labelcolor="red")
99ax1.plot(sp.x, sp.strain, c="k", label="strain")
100ax1.plot(sp.x, sp.tension_stiffening_values, c="k", ls="--", label="ts")
101ax1.plot(c_loc, c_s, c="k", ls="", marker="v", label="peak")
102ax1.plot(c_l, c_s, c="k", ls="", marker=">", label="left")
103ax1.plot(c_r, c_s, c="k", ls="", marker="<", label="right")
104ax2.plot(c_loc, c_w, c="red", ls="", marker="o", label="crack width")
105h1, l1 = ax1.get_legend_handles_labels()
106h2, l2 = ax2.get_legend_handles_labels()
107ax2.legend(loc="best", handles=h1 + h2, labels=l1 + l2)
108plt.show()