Milo Sobral commited on
Commit
95e2338
·
1 Parent(s): 86081f4

Added a table tyo summarize output

Browse files
portiloop/src/demo/demo.py CHANGED
@@ -33,7 +33,9 @@ def main():
33
  # Frequency
34
  freq = gr.Dropdown(choices=["100", "200", "250", "256", "500", "512", "1000", "1024"], value="250", label="Sampling Frequency (Hz)", interactive=True)
35
 
36
- output_array = gr.File(label="Output CSV File")
 
 
37
 
38
  run_inference = gr.Button(value="Run Inference")
39
  run_inference.click(
@@ -44,7 +46,7 @@ def main():
44
  threshold,
45
  detect_channel,
46
  freq],
47
- outputs=[output_array])
48
 
49
  demo.queue()
50
  demo.launch(share=False)
 
33
  # Frequency
34
  freq = gr.Dropdown(choices=["100", "200", "250", "256", "500", "512", "1000", "1024"], value="250", label="Sampling Frequency (Hz)", interactive=True)
35
 
36
+ with gr.Row():
37
+ output_array = gr.File(label="Output CSV File")
38
+ output_table = gr.Markdown(label="Output Table")
39
 
40
  run_inference = gr.Button(value="Run Inference")
41
  run_inference.click(
 
46
  threshold,
47
  detect_channel,
48
  freq],
49
+ outputs=[output_array, output_table])
50
 
51
  demo.queue()
52
  demo.launch(share=False)
portiloop/src/demo/offline.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  from portiloop.src.detection import SleepSpindleRealTimeDetector
4
  plt.switch_backend('agg')
5
  from portiloop.src.processing import FilterPipeline
6
- from portiloop.src.demo.utils import xdf2array, offline_detect, offline_filter, OfflineSleepSpindleRealTimeStimulator
7
  import gradio as gr
8
 
9
 
@@ -115,6 +115,12 @@ def run_offline(xdf_file, detect_filter_opts, threshold, channel_num, freq):
115
  print("Saving output...")
116
  # Output the data to a csv file
117
  np.savetxt("output.csv", data_whole, delimiter=",", header=",".join(columns), comments="")
 
 
 
 
 
 
118
 
119
  print("Done!")
120
- return "output.csv"
 
3
  from portiloop.src.detection import SleepSpindleRealTimeDetector
4
  plt.switch_backend('agg')
5
  from portiloop.src.processing import FilterPipeline
6
+ from portiloop.src.demo.utils import compute_output_table, xdf2array, offline_detect, offline_filter, OfflineSleepSpindleRealTimeStimulator
7
  import gradio as gr
8
 
9
 
 
115
  print("Saving output...")
116
  # Output the data to a csv file
117
  np.savetxt("output.csv", data_whole, delimiter=",", header=",".join(columns), comments="")
118
+
119
+
120
+ output_table = compute_output_table(
121
+ data_whole[:, columns.index("online_stimulations")] if online_detection else data_whole[:, columns.index("online_stimulations_portiloop")],
122
+ data_whole[:, columns.index("lacourse_spindles")] if lacourse else None,
123
+ data_whole[:, columns.index("wamsley_spindles")] if wamsley else None,)
124
 
125
  print("Done!")
126
+ return "output.csv", output_table
portiloop/src/demo/utils.py CHANGED
@@ -130,3 +130,22 @@ def offline_filter(signal, freq):
130
  signal = detrend(signal)
131
 
132
  return signal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  signal = detrend(signal)
131
 
132
  return signal
133
+
134
+ def compute_output_table(online_stimulation, lacourse_spindles, wamsley_spindles):
135
+ # Count the number of spindles detected by each method
136
+ online_stimulation_count = np.sum(online_stimulation)
137
+ lacourse_spindles_count = sum([1 for index, spindle in enumerate(lacourse_spindles) if spindle == 1 and lacourse_spindles[index - 1] == 0])
138
+ wamsley_spindles_count = sum([1 for index, spindle in enumerate(wamsley_spindles) if spindle == 1 and wamsley_spindles[index - 1] == 0])
139
+
140
+ # Count how many spindles were detected by both online and lacourse
141
+ both_online_lacourse = sum([1 for index, spindle in enumerate(online_stimulation) if spindle == 1 and lacourse_spindles[index] == 1])
142
+ # Count how many spindles were detected by both online and wamsley
143
+ both_online_wamsley = sum([1 for index, spindle in enumerate(online_stimulation) if spindle == 1 and wamsley_spindles[index] == 1])
144
+
145
+ # Create markdown table with the results
146
+ table = "| Method | Detected spindles | Overlap with Portiloop |\n"
147
+ table += "| --- | --- | --- |\n"
148
+ table += f"| Online | {online_stimulation_count} | {online_stimulation_count} |\n"
149
+ table += f"| Lacourse | {lacourse_spindles_count} | {both_online_lacourse} |\n"
150
+ table += f"| Wamsley | {wamsley_spindles_count} | {both_online_wamsley} |\n"
151
+ return table