Skip to content

Commit b60ca6e

Browse files
committed
counterbalance CAB
1 parent 0af8cf8 commit b60ca6e

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# CogBatt general imports for running and organizing the experiment.
1414
import config as CogBatt_config
1515
from utils import retrieve_worker_id, \
16-
get_blocks_to_run, upload_block
16+
get_blocks_to_run, upload_block, sid_evenness
1717
import version
1818

1919
# Various task imports
@@ -92,6 +92,9 @@
9292
else:
9393
raise NotImplementedError
9494

95+
# get subject id odd or even to counterbalance CAB
96+
flip_CAB = Func(sid_evenness, Ref.object(exp)._subject).result
97+
9598
with Parallel():
9699
with Serial(blocking=False):
97100
# Log all of the info about the subject and the CogBatt version
@@ -182,7 +185,8 @@
182185
task_dir=taskdir,
183186
sub_dir=Ref.object(exp)._subject_dir,
184187
block=exp.block_number,
185-
happy_mid=False)
188+
happy_mid=False,
189+
flip_resp=flip_CAB)
186190
with Elif(exp.task_name == "rdm"):
187191
Wait(.5)
188192
RDMExp(RDM_config,

tasks/AssBind/main.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@
3636
@Subroutine
3737
def AssBindExp(self, config, sub_dir, task_dir=None, block=0,
3838
reminder_only=False, pulse_server=None, shuffle=False,
39-
conditions=None, happy_mid=False):
40-
TRIAL_REMIND_TEXT_L = "%s <-- %s" % (config.RESP_KY[0], list(config.RESP_KEYS.keys())[
41-
list(config.RESP_KEYS.values()).index(config.RESP_KY[0])])
42-
TRIAL_REMIND_TEXT_R = "%s --> %s" % (list(config.RESP_KEYS.keys())[list(
43-
config.RESP_KEYS.values()).index(config.RESP_KY[1])], config.RESP_KY[1])
39+
conditions=None, happy_mid=False, flip_resp=False):
40+
if flip_resp:
41+
resp_keys = {
42+
'old': config.RESP_KEYS['new'],
43+
'new': config.RESP_KEYS['old'],
44+
}
45+
else:
46+
resp_keys = config.RESP_KEYS
47+
TRIAL_REMIND_TEXT_L = "%s <-- %s" % (config.RESP_KY[0], list(resp_keys.keys())[
48+
list(resp_keys.values()).index(config.RESP_KY[0])])
49+
TRIAL_REMIND_TEXT_R = "%s --> %s" % (list(resp_keys.keys())[list(
50+
resp_keys.values()).index(config.RESP_KY[1])], config.RESP_KY[1])
4451
if task_dir is not None:
4552
config.TASK_DIR = task_dir
4653

@@ -207,7 +214,7 @@ def AssBindExp(self, config, sub_dir, task_dir=None, block=0,
207214
Wait(0.2)
208215
response = GetResponse(keys=config.RESP_KY,
209216
base_time=left_image.appear_time['time'],
210-
correct_resp=Ref.getitem(config.RESP_KEYS,
217+
correct_resp=Ref.getitem(resp_keys,
211218
trial.current['resp_correct']))
212219

213220
# present frame around images to indicate response
@@ -236,7 +243,9 @@ def AssBindExp(self, config, sub_dir, task_dir=None, block=0,
236243
block=block,
237244
trial_id=trial.i,
238245
fmri_tr_time=self.trkp_press_time,
239-
eeg_pulse_time=self.eeg_pulse_time)
246+
eeg_pulse_time=self.eeg_pulse_time,
247+
old_key=resp_keys['old'],
248+
new_key=resp_keys['new'])
240249
Wait(.5)
241250
HappyQuest(task='CAB', block_num=block, trial_num=trial.i)
242251

utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,33 @@ def _read_exe_worker_id() -> dict[str, str]:
265265
return {"status": "error", "content": str(e)}
266266

267267

268+
def sid_evenness(sid):
269+
# make sure the input is a string
270+
sid = str(sid)
271+
# initialize val so we can later catch if it never got set
272+
val = None
273+
# loop through the SID backwards looking for something that
274+
# ord will return a value on
275+
# I'm using a naked except because I don't care how ord fails
276+
for char in sid[::-1]:
277+
try:
278+
val = ord(char)
279+
break
280+
except:
281+
continue
282+
# if for some reason ord works on nothing in sid
283+
# then just use the length
284+
# if all SIDs are the same length, this'll be a problem
285+
# but I really don't expect to get this far
286+
# and we'll keep an eye on use of this in the data
287+
if val is None:
288+
val = len(sid)
289+
290+
if val % 2 == 0:
291+
return True
292+
else:
293+
return False
294+
268295

269296
if __name__ == "__main__":
270297
upload_block(worker_id='123456',

0 commit comments

Comments
 (0)