Skip to content

Commit

Permalink
Add external trigger to start run (i.e. for the scanner)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Mar 10, 2017
1 parent 01a6501 commit 66fe7f3
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions visigoth/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

class Experiment(object):

abort_keys = ["escape"]

def __init__(self, arglist=None):

self.arglist = [] if arglist is None else arglist
Expand Down Expand Up @@ -58,7 +60,9 @@ def run(self):
self.initialize_display()
self.initialize_stimuli()

# TODO need to add scanner trigger
# Wait for a trigger to start
if self.p.trigger is not None:
self.wait_for_trigger()

# Wait a certain amount of time before starting the run
# (e.g. for dummy fMRI scans)
Expand Down Expand Up @@ -463,6 +467,23 @@ def initialize_stimuli(self):
# Convet to a Bunch to allow getattr access
self.s = Bunch(stims)

def wait_for_trigger(self):
"""Wait for a trigger key (or an abort)."""
trigger_keys = self.p.trigger
if not isinstance(trigger_keys, (tuple, list)):
trigger_keys = list(trigger_keys)

visual.TextStim(self.win, "Waiting for scanner",
pos=(0, 0), height=1).draw()
self.win.flip()

catch_keys = self.abort_keys + trigger_keys
keys = event.waitKeys(keyList=catch_keys)

if set(keys) & set(self.abort_keys):
self._aborted = True
core.quit()

# ==== Shutdown functions ====

def shutdown_server(self):
Expand Down Expand Up @@ -761,7 +782,7 @@ def flicker(self, stim, duration=.4, rate=10, other_stims=None):

def check_abort(self):
"""Check whether the quit key has been pressed and exit if so."""
if event.getKeys(["escape"]):
if event.getKeys(self.abort_keys):
self._aborted = True
core.quit()
return False
Expand Down Expand Up @@ -817,6 +838,8 @@ def iti_end(self, iti_duration, check_abort=True):
perform_acc_target=None,
perform_rt_target=None,

trigger=None,

run_duration=None,

output_template="data/{subject}/{session}/{time}",
Expand Down

0 comments on commit 66fe7f3

Please sign in to comment.