From 354ff609e5469b376ed2e77d061330eb0e566280 Mon Sep 17 00:00:00 2001 From: Giovanni Beltrame Date: Tue, 23 Jul 2024 15:15:22 -0400 Subject: [PATCH] Added sham condition for the SpindleStimulator --- portiloop/src/capture.py | 4 +++- portiloop/src/simple_gui/simple_gui.py | 16 ++++++++-------- portiloop/src/stimulation.py | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/portiloop/src/capture.py b/portiloop/src/capture.py index 860828c..bf983d0 100644 --- a/portiloop/src/capture.py +++ b/portiloop/src/capture.py @@ -141,7 +141,7 @@ def start_capture( } # print(f"DEBUG: Portiloop ID: {PORTILOOP_ID}") lsl_streamer = LSLStreamer(streams, capture_dictionary['nb_channels'], capture_dictionary['frequency'], id=PORTILOOP_ID) if capture_dictionary['lsl'] else Dummy() - stimulator = stimulator_cls(soundname=capture_dictionary['detection_sound'], lsl_streamer=lsl_streamer) if capture_dictionary['stimulate'] else Dummy() + stimulator = stimulator_cls(soundname=capture_dictionary['detection_sound'], lsl_streamer=lsl_streamer,sham=not capture_dictionary['stimulate']) # Initialize filtering pipeline if filter: fp = FilterPipeline(nb_channels=capture_dictionary['nb_channels'], @@ -265,6 +265,8 @@ def start_capture( detection_signal = detector.detect(filtered_point) # Stimulate stim = stimulator.stimulate(detection_signal) + if stim is None: + stim = detection_signal if capture_dictionary['detect']: detection_buffer += stim diff --git a/portiloop/src/simple_gui/simple_gui.py b/portiloop/src/simple_gui/simple_gui.py index a03b40f..d92d120 100644 --- a/portiloop/src/simple_gui/simple_gui.py +++ b/portiloop/src/simple_gui/simple_gui.py @@ -143,16 +143,16 @@ def start(self): if self.stim_on: self.run_dict['stimulate'] = True - if self.stimulator_type == 'Spindle': - self.stimulator_cls = SleepSpindleRealTimeStimulator - if self.stim_delay != 0: - self.run_dict['stim_delay'] = int(self.stim_delay) / 1000 - elif self.stimulator_type == 'Interval': - self.stimulator_cls = AlternatingStimulator - self.run_dict['detect'] = False else: self.run_dict['stimulate'] = False - self.stimulator_cls = None + + if self.stimulator_type == 'Spindle': + self.stimulator_cls = SleepSpindleRealTimeStimulator + if self.stim_delay != 0: + self.run_dict['stim_delay'] = int(self.stim_delay) / 1000 + elif self.stimulator_type == 'Interval': + self.stimulator_cls = AlternatingStimulator + self.run_dict['detect'] = False if self.lsl: self.run_dict['lsl'] = True diff --git a/portiloop/src/stimulation.py b/portiloop/src/stimulation.py index 96330f9..187afad 100644 --- a/portiloop/src/stimulation.py +++ b/portiloop/src/stimulation.py @@ -45,7 +45,7 @@ def test_stimulus(self): # Example implementation for sleep spindles class SleepSpindleRealTimeStimulator(Stimulator): - def __init__(self, soundname=None, lsl_streamer=Dummy()): + def __init__(self, soundname=None, lsl_streamer=Dummy(),sham=False): """ params: stimulation_delay (float): simple delay between a detection and a stimulation @@ -62,6 +62,7 @@ def __init__(self, soundname=None, lsl_streamer=Dummy()): self.wait_t = 0.4 # 400 ms self.delayer = None self.lsl_streamer = lsl_streamer + self.sham = sham # Initialize Alsa stuff # Open WAV file and set PCM device @@ -133,7 +134,7 @@ def stimulate(self, detection_signal): # Send the LSL marer for the fast stimulation self.send_stimulation("FAST_STIM", False) else: - self.send_stimulation("STIM", True) + self.send_stimulation("STIM", not self.sham) self.last_detected_ts = ts else: