Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2015 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/66b01a1b3deb0db6dfcc to your computer and use it in GitHub Desktop.
Save anonymous/66b01a1b3deb0db6dfcc to your computer and use it in GitHub Desktop.
# Replace run() for loop object with our own methods
import random
import openexp
import types
# Modified copy of original run() method
def new_MyLoop_run(self):
self.set_item_onset()
# generate cycle numbers (custom)
# come up with an order of IDs from the table
# First 32 are experiment, rest are filler
# 2*11, 3*10, 4*10 plus 1*3 at start = 32 filler sequences
n_filler_seq = [2]*11 + [3]*10 + [4]*10
random.shuffle(n_filler_seq)
n_filler_seq = [3] + n_filler_seq
test_ids = range(0,32)
filler_ids = range(32,128)
l = []
for n_filler in n_filler_seq:
for _ in range(n_filler):
l.append(filler_ids.pop(random.randrange(len(filler_ids))))
l.append(test_ids.pop(random.randrange(len(test_ids))))
# Create a keyboard to flush responses between cycles
self._keyboard = openexp.keyboard.keyboard(self.experiment)
# Make sure the item to run exists
if self.item not in self.experiment.items:
raise osexception( \
u"Could not find item '%s', which is called by loop item '%s'" \
% (self.item, self.name))
# And run!
_item = self.experiment.items[self.item]
while len(l) > 0:
cycle = l.pop(0)
self.apply_cycle(cycle)
self.experiment.set(u'repeat_cycle', 0)
_item.prepare()
_item.run()
test_obj = exp.items["MyLoop"]
test_obj.run = types.MethodType(new_MyLoop_run, test_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment