Skip to content

Commit

Permalink
Added sham condition for the SpindleStimulator
Browse files Browse the repository at this point in the history
  • Loading branch information
beltrame committed Jul 23, 2024
1 parent 9ef5b4d commit 354ff60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion portiloop/src/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions portiloop/src/simple_gui/simple_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions portiloop/src/stimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 354ff60

Please sign in to comment.