MiloSobral commited on
Commit
804607c
·
1 Parent(s): 1737659

Added overlap feature between IRL and IRL online

Browse files
portiloop/src/demo/offline.py CHANGED
@@ -146,9 +146,11 @@ def run_offline(xdf_file, detect_filter_opts, threshold, channel_num, freq, dete
146
  # Output the data to a csv file
147
  np.savetxt("output.csv", data_whole, delimiter=",", header=",".join(columns), comments="")
148
 
 
149
 
150
  output_table = compute_output_table(
151
- data_whole[:, columns.index("online_stimulations")] if online_detection else data_whole[:, columns.index("online_stimulations_portiloop")],
 
152
  data_whole[:, columns.index("lacourse_spindles")] if lacourse else None,
153
  data_whole[:, columns.index("wamsley_spindles")] if wamsley else None,)
154
 
 
146
  # Output the data to a csv file
147
  np.savetxt("output.csv", data_whole, delimiter=",", header=",".join(columns), comments="")
148
 
149
+ # Compute the overlap of online stimulations with the
150
 
151
  output_table = compute_output_table(
152
+ data_whole[:, columns.index("online_stimulations")],
153
+ data_whole[:, columns.index("online_stimulations_portiloop")],
154
  data_whole[:, columns.index("lacourse_spindles")] if lacourse else None,
155
  data_whole[:, columns.index("wamsley_spindles")] if wamsley else None,)
156
 
portiloop/src/demo/utils.py CHANGED
@@ -211,7 +211,14 @@ def offline_filter(signal, freq):
211
 
212
  return signal
213
 
214
- def compute_output_table(online_stimulation, lacourse_spindles, wamsley_spindles):
 
 
 
 
 
 
 
215
  # Count the number of spindles detected by each method
216
  online_stimulation_count = np.sum(online_stimulation)
217
  if lacourse_spindles is not None:
@@ -224,12 +231,11 @@ def compute_output_table(online_stimulation, lacourse_spindles, wamsley_spindles
224
  # Count how many spindles were detected by both online and wamsley
225
  both_online_wamsley = sum([1 for index, spindle in enumerate(online_stimulation) if spindle == 1 and wamsley_spindles[index] == 1])
226
 
227
-
228
-
229
  # Create markdown table with the results
230
- table = "| Method | Detected spindles | Overlap with Portiloop |\n"
231
  table += "| --- | --- | --- |\n"
232
- table += f"| Online | {online_stimulation_count} | {online_stimulation_count} |\n"
 
233
  if lacourse_spindles is not None:
234
  table += f"| Lacourse | {lacourse_spindles_count} | {both_online_lacourse} |\n"
235
  if wamsley_spindles is not None:
 
211
 
212
  return signal
213
 
214
+ def compute_output_table(irl_online_stimulations, online_stimulation, lacourse_spindles, wamsley_spindles, time_overlap_s=2.0):
215
+
216
+
217
+ # Count the number of spindles in this run which overlap with spindles found IRL
218
+ irl_spindles_count = sum(irl_online_stimulations)
219
+ both_online_irl = sum([1 for index, spindle in enumerate(online_stimulation)\
220
+ if spindle == 1 and 1 in irl_online_stimulations[index - int((time_overlap_s / 2) * 250):index + int((time_overlap_s / 2) * 250)]])
221
+
222
  # Count the number of spindles detected by each method
223
  online_stimulation_count = np.sum(online_stimulation)
224
  if lacourse_spindles is not None:
 
231
  # Count how many spindles were detected by both online and wamsley
232
  both_online_wamsley = sum([1 for index, spindle in enumerate(online_stimulation) if spindle == 1 and wamsley_spindles[index] == 1])
233
 
 
 
234
  # Create markdown table with the results
235
+ table = "| Method | # of Detected spindles | Overlap with Online (in tool) |\n"
236
  table += "| --- | --- | --- |\n"
237
+ table += f"| Online in Tool | {online_stimulation_count} | {online_stimulation_count} |\n"
238
+ table += f"| Online detection IRL | {irl_spindles_count} | {both_online_irl} |\n"
239
  if lacourse_spindles is not None:
240
  table += f"| Lacourse | {lacourse_spindles_count} | {both_online_lacourse} |\n"
241
  if wamsley_spindles is not None: