HengJay commited on
Commit
abac731
·
1 Parent(s): 4699f43

Update the new electrode mapping & Plot text label. - 1213

Browse files
app.py CHANGED
@@ -50,11 +50,37 @@ def emg_plot(event_index, event_plot_name, left_std_ratio, left_delta_t, right_s
50
  # Add horizontal and vertical lines to create quadrants
51
  plt.axhline(y=0, color='black', linestyle='--')
52
  plt.axvline(x=0, color='black', linestyle='--')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  # Add title and axis labels
55
  plt.title(f'Muscle Coordination Analysis - {event_index}:{event_plot_name}', fontsize=14)
56
- plt.xlabel('Std Ratio > 3', fontsize=12)
57
- plt.ylabel('Delta T > 0', fontsize=12)
58
 
59
  # Remove axis numbers and labels
60
  ax.set_xticks([])
@@ -63,7 +89,7 @@ def emg_plot(event_index, event_plot_name, left_std_ratio, left_delta_t, right_s
63
  ax.set_yticklabels([])
64
 
65
  # Set plot legend with color
66
- plt.legend(['Left', 'Right'], loc='upper left', fontsize=10)
67
 
68
  # Set the limits of the plot
69
  plt.xlim(-10, 10)
@@ -103,8 +129,8 @@ def main():
103
 
104
  # Load test data button
105
  if st.button('Load Test Data', type="primary"):
106
- st.session_state.emg_data = pd.read_csv('test-1/0-New_Task-recording-0.csv', skiprows=[0,1,3,4])
107
- st.session_state.time_marker = pd.read_csv('test-1/time_marker.csv')
108
  st.success("Test data loaded successfully!")
109
  st.session_state.data_isready = True
110
 
@@ -129,11 +155,11 @@ def main():
129
  # Reset emg data index with Channels
130
  emg_data = st.session_state.emg_data.set_index('Channels')
131
  # Get signal data from difference of emg_data
132
- signal_left_lateral = emg_data['21'] - emg_data['3']
133
- signal_left_medial = emg_data['22'] - emg_data['2']
134
 
135
- signal_right_lateral = emg_data['16'] - emg_data['6']
136
- signal_right_medial = emg_data['17'] - emg_data['5']
137
 
138
  # RMS caculation : Define the moving average window size
139
  N = 25
@@ -149,13 +175,13 @@ def main():
149
  signal_right_medial_RMS = moving_rms(signal_right_medial, N)
150
 
151
  # Time Marker Processing
152
- time_marker = st.session_state.time_marker[['0-New_Task-recording_time(us)', 'name', 'tag']]
153
  time_marker = time_marker.rename(columns={'0-New_Task-recording_time(us)': 'event_time'})
154
 
155
  # Select column value with odd/even index
156
  event_start_times = time_marker.loc[0::2]['event_time'].values.astype(int)
157
  event_end_times = time_marker.loc[1::2]['event_time'].values.astype(int)
158
- event_names = time_marker.loc[0::2]['name'].values
159
 
160
  # Get signal basic 10s std
161
  signal_left_lateral_basics_10s_std = signal_left_lateral_RMS.loc[: 10000000].std()
@@ -173,11 +199,17 @@ def main():
173
  st.write(f"Start time: {float(event_start_time)/1000000: .3f} sec, End time: {float(event_end_time)/1000000: .3f} sec")
174
 
175
  # Get event signal data with event time duration
176
- event_signal_LL = signal_left_lateral_RMS.loc[event_start_time:event_end_time]
177
- event_signal_LM = signal_left_medial_RMS.loc[event_start_time:event_end_time]
 
 
 
 
 
 
178
 
179
- event_signal_RL = signal_right_lateral_RMS.loc[event_start_time:event_end_time]
180
- event_signal_RM = signal_right_medial_RMS.loc[event_start_time:event_end_time]
181
 
182
  # Calculate std ratio
183
  left_event_std = event_signal_LL.std()
 
50
  # Add horizontal and vertical lines to create quadrants
51
  plt.axhline(y=0, color='black', linestyle='--')
52
  plt.axvline(x=0, color='black', linestyle='--')
53
+
54
+ # Add quadrant labels
55
+ # Add styled text labels with colored box
56
+ def add_styled_text(x, y, text, va='bottom'):
57
+ # Create text box style
58
+ bbox_props = dict(
59
+ boxstyle='round,pad=0.5',
60
+ fc='#1f77b4', # 背景顏色(白色)
61
+ ec='#1f77b4', # 邊框顏色(藍色)
62
+ alpha=0.7, # 背景透明度
63
+ lw=1.5 # 邊框寬度
64
+ )
65
+
66
+ plt.text(x, y, text,
67
+ horizontalalignment='center',
68
+ verticalalignment=va,
69
+ bbox=bbox_props,
70
+ color='white',
71
+ fontweight='semibold',
72
+ fontsize=9)
73
+
74
+ # Add styled quadrant labels
75
+ add_styled_text(4, 0.5, "Exertion + / Coordination -", 'bottom')
76
+ add_styled_text(-4, 0.5, "Exertion - / Coordination -", 'bottom')
77
+ add_styled_text(-4, -0.5, "Exertion - / Coordination +", 'top')
78
+ add_styled_text(4, -0.5, "Exertion + / Coordination +", 'top')
79
 
80
  # Add title and axis labels
81
  plt.title(f'Muscle Coordination Analysis - {event_index}:{event_plot_name}', fontsize=14)
82
+ plt.xlabel('Exertion (Std Ratio > 3)', fontsize=12, fontweight='semibold')
83
+ plt.ylabel('Coordination (Delta T > 0)', fontsize=12, fontweight='semibold')
84
 
85
  # Remove axis numbers and labels
86
  ax.set_xticks([])
 
89
  ax.set_yticklabels([])
90
 
91
  # Set plot legend with color
92
+ plt.legend(['Left Swallowing Muscle', 'Right Swallowing Muscle'], loc='upper left', fontsize=10)
93
 
94
  # Set the limits of the plot
95
  plt.xlim(-10, 10)
 
129
 
130
  # Load test data button
131
  if st.button('Load Test Data', type="primary"):
132
+ st.session_state.emg_data = pd.read_csv('test-new/0-New_Task-recording-0.csv', skiprows=[0,1,3,4])
133
+ st.session_state.time_marker = pd.read_csv('test-new/time_marker.csv')
134
  st.success("Test data loaded successfully!")
135
  st.session_state.data_isready = True
136
 
 
155
  # Reset emg data index with Channels
156
  emg_data = st.session_state.emg_data.set_index('Channels')
157
  # Get signal data from difference of emg_data
158
+ signal_left_lateral = emg_data['17'] - emg_data['18']
159
+ signal_left_medial = emg_data['19'] - emg_data['20']
160
 
161
+ signal_right_lateral = emg_data['23'] - emg_data['24']
162
+ signal_right_medial = emg_data['21'] - emg_data['22']
163
 
164
  # RMS caculation : Define the moving average window size
165
  N = 25
 
175
  signal_right_medial_RMS = moving_rms(signal_right_medial, N)
176
 
177
  # Time Marker Processing
178
+ time_marker = st.session_state.time_marker[['0-New_Task-recording_time(us)', 'description', 'tag']]
179
  time_marker = time_marker.rename(columns={'0-New_Task-recording_time(us)': 'event_time'})
180
 
181
  # Select column value with odd/even index
182
  event_start_times = time_marker.loc[0::2]['event_time'].values.astype(int)
183
  event_end_times = time_marker.loc[1::2]['event_time'].values.astype(int)
184
+ event_names = time_marker.loc[0::2]['description'].values
185
 
186
  # Get signal basic 10s std
187
  signal_left_lateral_basics_10s_std = signal_left_lateral_RMS.loc[: 10000000].std()
 
199
  st.write(f"Start time: {float(event_start_time)/1000000: .3f} sec, End time: {float(event_end_time)/1000000: .3f} sec")
200
 
201
  # Get event signal data with event time duration
202
+ mask_LL = (signal_left_lateral_RMS.index >= event_start_time) & (signal_left_lateral_RMS.index <= event_end_time)
203
+ event_signal_LL = signal_left_lateral_RMS.iloc[mask_LL]
204
+
205
+ mask_LM = (signal_left_medial_RMS.index >= event_start_time) & (signal_left_medial_RMS.index <= event_end_time)
206
+ event_signal_LM = signal_left_medial_RMS.iloc[mask_LM]
207
+
208
+ mask_RL = (signal_right_lateral_RMS.index >= event_start_time) & (signal_right_lateral_RMS.index <= event_end_time)
209
+ event_signal_RL = signal_right_lateral_RMS.iloc[mask_RL]
210
 
211
+ mask_RM = (signal_right_medial_RMS.index >= event_start_time) & (signal_right_medial_RMS.index <= event_end_time)
212
+ event_signal_RM = signal_right_medial_RMS.iloc[mask_RM]
213
 
214
  # Calculate std ratio
215
  left_event_std = event_signal_LL.std()
data-processing.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
emg-data-processing.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
test-new/0-New_Task-recording-0.csv ADDED
The diff for this file is too large to render. See raw diff
 
test-new/time_marker.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Abs_time(us),0-New_Task-recording_time(us),topic,type,name,uuid,signal,description,color,order,tag
2
+ 1733899760533486.0,78357902.0,keyboard/c,keyboard,Keyboard,260efabb-3944-448b-88b4-1eef7de020dd,c,Cough,#baeea0,0,start
3
+ 1733899761846583.0,79670999.0,keyboard/c,keyboard,Keyboard,60fe4089-f190-4a34-9b49-7b6392f2dcb9,c,Cough,#baeea0,0,end
4
+ 1733899763403073.0,81227489.0,keyboard/b,keyboard,Keyboard,cb091860-8a06-460d-927d-c2006fa0d764,b,Bite,#fae2a3,1,start
5
+ 1733899764640907.0,82465323.0,keyboard/b,keyboard,Keyboard,72c6fbd9-8c83-48de-a89e-426636805944,b,Bite,#fae2a3,1,end
6
+ 1733899766415311.0,84239727.0,keyboard/s,keyboard,Keyboard,8fa85742-77ec-475c-a6dc-0fd4a986c943,s,Swallow,#fab6b6,2,start
7
+ 1733899767609930.0,85434346.0,keyboard/s,keyboard,Keyboard,8005446f-862c-446b-bc7e-7c428efc1f7a,s,Swallow,#fab6b6,2,end
8
+ 1733899768804131.0,86628547.0,keyboard/s,keyboard,Keyboard,8fa85742-77ec-475c-a6dc-0fd4a986c943,s,Swallow,#fab6b6,3,start
9
+ 1733899770127418.0,87951834.0,keyboard/s,keyboard,Keyboard,8005446f-862c-446b-bc7e-7c428efc1f7a,s,Swallow,#fab6b6,3,end
10
+ 1733899771849409.0,89673825.0,keyboard/s,keyboard,Keyboard,8fa85742-77ec-475c-a6dc-0fd4a986c943,s,Swallow,#fab6b6,4,start
11
+ 1733899773334247.0,91158663.0,keyboard/s,keyboard,Keyboard,8005446f-862c-446b-bc7e-7c428efc1f7a,s,Swallow,#fab6b6,4,end
12
+ 1733899774433363.0,92257779.0,keyboard/c,keyboard,Keyboard,260efabb-3944-448b-88b4-1eef7de020dd,c,Cough,#baeea0,5,start
13
+ 1733899775890252.0,93714668.0,keyboard/c,keyboard,Keyboard,60fe4089-f190-4a34-9b49-7b6392f2dcb9,c,Cough,#baeea0,5,end