Spaces:
Build error
Build error
arcan3
commited on
Commit
·
29afbe3
1
Parent(s):
80be153
added the extra plots
Browse files- .gitignore +1 -0
- app.py +5 -6
- funcs/plot_func.py +48 -2
- funcs/processor.py +4 -3
- test_plot.py +0 -40
.gitignore
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
# Byte-compiled / optimized / DLL files
|
2 |
*.zip
|
|
|
3 |
Data-*
|
4 |
drive-*
|
5 |
__pycache__/
|
|
|
1 |
# Byte-compiled / optimized / DLL files
|
2 |
*.zip
|
3 |
+
*.png
|
4 |
Data-*
|
5 |
drive-*
|
6 |
__pycache__/
|
app.py
CHANGED
@@ -19,7 +19,6 @@ with gr.Blocks(title='Cabasus') as cabasus_sensor:
|
|
19 |
repeat_process = gr.Button('Restart process')
|
20 |
with gr.Row():
|
21 |
leg_dropdown = gr.Dropdown(choices=['GZ1', 'GZ2', 'GZ3', 'GZ4'], label='select leg', value='GZ1')
|
22 |
-
|
23 |
with gr.Row():
|
24 |
plot_box_leg = gr.Plot(label="Filtered Signal Plot")
|
25 |
plot_box_overlay = gr.Plot(label="Overlay Signal Plot")
|
@@ -29,16 +28,16 @@ with gr.Blocks(title='Cabasus') as cabasus_sensor:
|
|
29 |
|
30 |
with gr.Row():
|
31 |
plot_slice_leg = gr.Plot(label="Sliced Signal Plot")
|
32 |
-
|
33 |
|
34 |
with gr.Row():
|
35 |
animation = gr.PlayableVideo(label="Animated horse steps")
|
36 |
|
37 |
slices_per_leg = gr.Textbox(label="Number of slices found per LEG")
|
38 |
|
39 |
-
csv_file_box.change(process_data, inputs=[csv_file_box, slice_size_slider, sample_rate, window_size_slider], outputs=[processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg,
|
40 |
-
leg_dropdown.change(plot_sensor_data_from_json, inputs=[json_file_box, leg_dropdown, slice_slider], outputs=[plot_box_leg, plot_slice_leg,
|
41 |
-
repeat_process.click(process_data, inputs=[csv_file_box, slice_size_slider, sample_rate, window_size_slider], outputs=[processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg,
|
42 |
-
slice_slider.change(plot_sensor_data_from_json, inputs=[json_file_box, leg_dropdown, slice_slider], outputs=[plot_box_leg, plot_slice_leg,
|
43 |
|
44 |
cabasus_sensor.queue(concurrency_count=2).launch(debug=True)
|
|
|
19 |
repeat_process = gr.Button('Restart process')
|
20 |
with gr.Row():
|
21 |
leg_dropdown = gr.Dropdown(choices=['GZ1', 'GZ2', 'GZ3', 'GZ4'], label='select leg', value='GZ1')
|
|
|
22 |
with gr.Row():
|
23 |
plot_box_leg = gr.Plot(label="Filtered Signal Plot")
|
24 |
plot_box_overlay = gr.Plot(label="Overlay Signal Plot")
|
|
|
28 |
|
29 |
with gr.Row():
|
30 |
plot_slice_leg = gr.Plot(label="Sliced Signal Plot")
|
31 |
+
get_all_slice = gr.Plot(label="Real Signal Plot")
|
32 |
|
33 |
with gr.Row():
|
34 |
animation = gr.PlayableVideo(label="Animated horse steps")
|
35 |
|
36 |
slices_per_leg = gr.Textbox(label="Number of slices found per LEG")
|
37 |
|
38 |
+
csv_file_box.change(process_data, inputs=[csv_file_box, slice_size_slider, sample_rate, window_size_slider], outputs=[processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice])
|
39 |
+
leg_dropdown.change(plot_sensor_data_from_json, inputs=[json_file_box, leg_dropdown, slice_slider], outputs=[plot_box_leg, plot_slice_leg, get_all_slice])
|
40 |
+
repeat_process.click(process_data, inputs=[csv_file_box, slice_size_slider, sample_rate, window_size_slider], outputs=[processed_file_box, json_file_box, slices_per_leg, plot_box_leg, plot_box_overlay, slice_slider, plot_slice_leg, get_all_slice])
|
41 |
+
slice_slider.change(plot_sensor_data_from_json, inputs=[json_file_box, leg_dropdown, slice_slider], outputs=[plot_box_leg, plot_slice_leg, get_all_slice])
|
42 |
|
43 |
cabasus_sensor.queue(concurrency_count=2).launch(debug=True)
|
funcs/plot_func.py
CHANGED
@@ -3,6 +3,7 @@ import matplotlib
|
|
3 |
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
|
|
6 |
import matplotlib.pyplot as plt
|
7 |
|
8 |
matplotlib.use('Agg')
|
@@ -58,7 +59,8 @@ def plot_sensor_data_from_json(json_file, sensor, slice_select=1):
|
|
58 |
plt.legend()
|
59 |
plt.tight_layout()
|
60 |
|
61 |
-
|
|
|
62 |
|
63 |
def plot_overlay_data_from_json(json_file, sensors, use_precise_timestamp=False):
|
64 |
# Read the JSON file
|
@@ -114,4 +116,48 @@ def plot_slices(original_signal, imputed_signal, precise_slice_points, normal_sl
|
|
114 |
plt.ylabel("Signal Amplitude")
|
115 |
plt.title("Imputed Signal and Slice Points")
|
116 |
|
117 |
-
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
+
import seaborn as sns
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
9 |
matplotlib.use('Agg')
|
|
|
59 |
plt.legend()
|
60 |
plt.tight_layout()
|
61 |
|
62 |
+
|
63 |
+
return fig, fig1, plot_other_sensor_with_same_timestamp(json_file, sensor, slice_select)
|
64 |
|
65 |
def plot_overlay_data_from_json(json_file, sensors, use_precise_timestamp=False):
|
66 |
# Read the JSON file
|
|
|
116 |
plt.ylabel("Signal Amplitude")
|
117 |
plt.title("Imputed Signal and Slice Points")
|
118 |
|
119 |
+
return True
|
120 |
+
|
121 |
+
def plot_other_sensor_with_same_timestamp(json_file, sensor, slice_select):
|
122 |
+
# Read the JSON file
|
123 |
+
try:
|
124 |
+
with open(json_file, "r") as f:
|
125 |
+
slices = json.load(f)
|
126 |
+
except:
|
127 |
+
with open(json_file.name, "r") as f:
|
128 |
+
slices = json.load(f)
|
129 |
+
|
130 |
+
# Concatenate the slices and create a new timestamp series with 20ms intervals
|
131 |
+
timestamps = []
|
132 |
+
sensor_data = []
|
133 |
+
slice_item = []
|
134 |
+
|
135 |
+
for slice_count, slice_dict in enumerate(slices):
|
136 |
+
if slice_count+1 == slice_select:
|
137 |
+
|
138 |
+
start_timestamp = slice_dict["timestamp"]
|
139 |
+
|
140 |
+
for slist in slice_dict.keys():
|
141 |
+
if slist[-1] != sensor[-1]:
|
142 |
+
continue
|
143 |
+
|
144 |
+
slice_length = len(slice_dict[slist])
|
145 |
+
|
146 |
+
slice_timestamps = [start_timestamp + 20 * i for i in range(slice_length)]
|
147 |
+
timestamps.extend(slice_timestamps)
|
148 |
+
sensor_data.extend(slice_dict[slist])
|
149 |
+
|
150 |
+
slice_item.extend([slist]*len(slice_timestamps))
|
151 |
+
|
152 |
+
# Create a DataFrame with the sensor data
|
153 |
+
data = pd.DataFrame({'data': sensor_data, 'sensor': slice_item, 'time': timestamps})
|
154 |
+
|
155 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
156 |
+
ax = sns.lineplot(data, x='time', y='data', hue='sensor')
|
157 |
+
|
158 |
+
plt.xlabel("Timestamp")
|
159 |
+
plt.ylabel(sensor)
|
160 |
+
plt.legend()
|
161 |
+
plt.tight_layout()
|
162 |
+
|
163 |
+
return fig
|
funcs/processor.py
CHANGED
@@ -77,10 +77,11 @@ def process_data(input_file, slice_size=64, min_slice_size=16, sample_rate=20, w
|
|
77 |
file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
|
78 |
|
79 |
# get the plot automatically
|
80 |
-
sensor_fig, slice_fig,
|
81 |
overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"], use_precise_timestamp=True)
|
82 |
|
83 |
-
#
|
84 |
|
85 |
|
86 |
-
|
|
|
|
77 |
file, len_ = slice_csv_to_json('output.csv', slice_size, min_slice_size, sample_rate, window_size=window_size)
|
78 |
|
79 |
# get the plot automatically
|
80 |
+
sensor_fig, slice_fig, get_all_slice = plot_sensor_data_from_json(file, "GZ1")
|
81 |
overlay_fig = plot_overlay_data_from_json(file, ["GZ1", "GZ2", "GZ3", "GZ4"], use_precise_timestamp=True)
|
82 |
|
83 |
+
# plot all the curves from the timestep
|
84 |
|
85 |
|
86 |
+
|
87 |
+
return 'output.csv', file, f'{len_}', sensor_fig, overlay_fig, gr.Slider.update(interactive=True, maximum=len_, minimum=1, value=1), slice_fig, get_all_slice
|
test_plot.py
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
import matplotlib.pyplot as plt
|
2 |
-
import json
|
3 |
-
import pandas as pd
|
4 |
-
import numpy as np
|
5 |
-
|
6 |
-
plt.style.use('ggplot')
|
7 |
-
|
8 |
-
def plot_overlay_data_from_json(json_file, sensors, use_precise_timestamp=False, slice_select=1):
|
9 |
-
# Read the JSON file
|
10 |
-
with open(json_file, "r") as f:
|
11 |
-
slices = json.load(f)
|
12 |
-
|
13 |
-
# Set up the colormap
|
14 |
-
cmap = plt.get_cmap('viridis')
|
15 |
-
|
16 |
-
# Create subplots for each sensor
|
17 |
-
fig, axs = plt.subplots(len(sensors), 1, figsize=(12, 2 * len(sensors)), sharex=True)
|
18 |
-
|
19 |
-
for idx, sensor in enumerate(sensors):
|
20 |
-
# Plot the overlay of the slices
|
21 |
-
for slice_idx, slice_dict in enumerate(slices):
|
22 |
-
slice_length = len(slice_dict[sensor])
|
23 |
-
|
24 |
-
# Create timestamp array starting from 0 for each slice
|
25 |
-
slice_timestamps = [20 * i for i in range(slice_length)]
|
26 |
-
sensor_data = slice_dict[sensor]
|
27 |
-
|
28 |
-
data = pd.DataFrame({sensor: sensor_data}, index=slice_timestamps)
|
29 |
-
color = cmap(slice_idx / len(slices))
|
30 |
-
|
31 |
-
axs[idx].plot(data[sensor], color=color, label=f'Slice {slice_idx + 1}')
|
32 |
-
|
33 |
-
axs[idx].set_ylabel(sensor)
|
34 |
-
|
35 |
-
axs[-1].set_xlabel("Timestamp")
|
36 |
-
axs[0].legend()
|
37 |
-
|
38 |
-
return fig
|
39 |
-
|
40 |
-
plot_overlay_data_from_json('output.json', ["GZ1", "GZ2", "GZ3", "GZ4"], 4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|