-
Notifications
You must be signed in to change notification settings - Fork 0
/
smell_experiment_main.py
2086 lines (1902 loc) · 101 KB
/
smell_experiment_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Codemap
#port settings -- 106
#odor list -- 119
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2020.2.4),
on Oct 20, 2020, at 15:35
If you publish work using this script the most relevant publication is:
Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
PsychoPy2: Experiments in behavior made easy Behav Res 51: 195.
https://doi.org/10.3758/s13428-018-01193-y
"""
#comment1:
from __future__ import absolute_import, division
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
from psychopy.hardware import keyboard
from psychopy import gui
from colorama import init, Fore, Style, Back
init(autoreset=True)
#image_for_study="stimulus/bsbtbzrc.jpeg"
study_order=[0,1,2,3]
keys=['up','right','down','left']
pressedCorrect_counter = 0
#comment2
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
psychopyVersion = '2020.2.4'
expName = 'smell_experiment_main' # from the Builder filename that created this script
keys_experiment = ['name', 'age', 'sex', 'session', 'emulate']
myDlg = gui.Dlg(title="CUBE: The Smell Experiment")
myDlg.addText('Subject info')
myDlg.addField('Name:')
myDlg.addField('Age:', 21)
myDlg.addField('Sex:', choices=['Female', 'Male'])
myDlg.addText('Additional Info')
myDlg.addField('Session:', 1)
myDlg.addField('Emulate:', initial=False, tip="Check the box to run experiment offline.")
ok_data = myDlg.show() # show dialog and wait for OK or Cancel
# dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=True, title=expName)
if myDlg.OK == False:
core.quit() # user pressed cancel
else:
print(ok_data)
expInfo = {key:value for key, value in zip(keys_experiment, ok_data)}
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
isEmulate = expInfo['emulate'] # store bool value
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['name'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='/Users/gric-gosha/Desktop/PsychoPy_env',
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
frameTolerance = 0.001 # how close to onset before 'same' frame
# Start Code - component code to be run before the window creation
# Setup the Window. Sreen=1 to run on the projector
win = visual.Window(
size=(612, 384), fullscr=True, screen=0,
winType='pyglet', allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard()
# Initialize components for Routine "code_initial"
code_initialClock = core.Clock()
"""
"""
#comment2end
import random
import serial
from time import sleep
#port settings
settings = {"port": "COM6",
"baudrate": 115200,
"timeout": 1}
#randomize random
random.seed()
#initialize list for smells
smells=[1,2,3,4]
#initialize odor list
odor_keys_list = ['4', '5', '7', '8']
#create odor counter
odor_dict = {key: 0 for key in odor_keys_list}
#initialize list for symbols
symbols_set=['t','s','c','z']
#shuffle order of symbols
random.shuffle(symbols_set)
#initialise dict for symbols
symbols={}
for i in range(4):
symbols[i]=symbols_set[i]
#set study_number
study_number = 0
#set test_number
test_number = 0
#set trial_number
trial_number = 0
#set limiter for each stimulus
limit_study = 1
limit_test = 1
fixation_point_duration = 2.000000
fixation_point_duration_green = 10.000000
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def eject(smell_correct):
"""Eject the stimulus given selected odor. See params in serial.Serial() documentation."""
msg = "w" + odor_keys_list[smell_correct] + ";" + " 1\n"
ser.write(msg.encode())
print("The following command has been sent: \n" + ">" + msg)
print("The answer is: ")
print(ser.readline().decode("ascii"))
def close_current_capsule(smell_correct):
"""Stop the last stimulus. See params in serial.Serial() documentation."""
msg = "w" + odor_keys_list[smell_correct] + ";" + " 0\n"
ser.write(msg.encode())
print("The following command has been sent: \n" + ">" + msg)
print("The answer is: ")
print(ser.readline().decode("ascii"))
if isEmulate:
print(Fore.GREEN + "Initialized successfully as EMULATOR.")
else:
print(Fore.GREEN + "Initialized successfully.")
print("limit_study =", limit_study)
print("limit_test =", limit_test)
print(Fore.YELLOW + "fixation_point_duration =", fixation_point_duration)
#open port
continueRoutine = True
while continueRoutine and not isEmulate:
try:
ser = serial.Serial(**settings)
print(Fore.GREEN + "The port has been opened. May the experiment begin!")
break
except (FileNotFoundError, serial.SerialException):
print(Fore.RED + "Arduino connection error. Double check the COM-port!")
askedInput = str(input(">>>Want to start over? Type Y or N:\n")).lower()
if askedInput == "y":
continue
elif askedInput == "n":
print("Finishing experiment...")
core.quit()
else:
print(Fore.YELLOW + "Didn't get your input. Try Y or N next time." + "\n" + Fore.MAGENTA + "Trying to open the port now...")
# Initialize components for Routine "Welcome_screen"
Welcome_screenClock = core.Clock()
text_welcome_screen = visual.TextStim(win=win, name='text_welcome_screen',
text='Для начала эксперимента\nнажмите на кнопку',
font='Arial',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
key_resp = keyboard.Keyboard()
# Initialize components for Routine "Start_trial_screen"
Start_trial_screenClock = core.Clock()
background_start_trial_screen = visual.Rect(
win=win, name='background_start_trial_screen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
text__for_start_trial_screen = visual.TextStim(win=win, name='text__for_start_trial_screen',
text='Задержите дыхание на выдохе\n\nНажмите на кнопку\nдля подачи аромата',
font='Arial',
pos=(0, -0.15), height=0.05, wrapWidth=None, ori=0,
color='black', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
image_MARK = visual.ImageStim(
win=win,
name='image_MARK',
image='gesture-press.png', mask=None,
ori=0, pos=(0.0, 0.15), size=(0.3, 0.3),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=-3.0)
key_resp_for_start_trial = keyboard.Keyboard()
# Initialize components for Routine "Pause_screen"
Pause_screenClock = core.Clock()
backgound_for_pause_creen = visual.Rect(
win=win, name='backgound_for_pause_creen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "code_study"
code_studyClock = core.Clock()
# Initialize components for Routine "Smell_creen_with_code"
Smell_creen_with_codeClock = core.Clock()
background_for_smell_screen = visual.Rect(
win=win, name='background_for_smell_screen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "Smell_creen_with_code_green"
Smell_creen_with_code_greenClock = core.Clock()
background_for_smell_screen = visual.Rect(
win=win, name='background_for_smell_screen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "study_trial"
study_trialClock = core.Clock()
polygon_study_background = visual.Rect(
win=win, name='polygon_study_background',
width=(2,2)[0], height=(2,2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor='white', lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
image_study = visual.ImageStim(
win=win,
name='image_study',
image='sin', mask=None,
ori=0, pos=(0, 0), size=(1.5, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=True, depth=-1.0)
key_resp_study_trial = keyboard.Keyboard()
# Initialize components for Routine "codeStudy_Finished"
codeStudy_FinishedClock = core.Clock()
# Initialize components for Routine "blank_500"
blank_500Clock = core.Clock()
polygon_blank_500 = visual.Rect(
win=win, name='polygon_blank_500',
width=(2,2)[0], height=(2,2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor='white', lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "second_start__screen"
second_start__screenClock = core.Clock()
text_second_start = visual.TextStim(win=win, name='text_second_start',
text='Обучающая сессия завершена\n\nНажмите на кнопку для продолжения',
font='Arial',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
key_resp_second_start = keyboard.Keyboard()
# Initialize components for Routine "Start_trial_screen"
Start_trial_screenClock = core.Clock()
background_start_trial_screen = visual.Rect(
win=win, name='background_start_trial_screen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
text__for_start_trial_screen = visual.TextStim(win=win, name='text__for_start_trial_screen',
text='Задержите дыхание на выдохе\n\nНажмите на кнопку\nдля подачи аромата',
font='Arial',
pos=(0, -0.15), height=0.05, wrapWidth=None, ori=0,
color='black', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
image_MARK = visual.ImageStim(
win=win,
name='image_MARK',
image='gesture-press.png', mask=None,
ori=0, pos=(0.0, 0.15), size=(0.3, 0.3),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=True, flipVert=False,
texRes=128, interpolate=True, depth=-3.0)
key_resp_for_start_trial = keyboard.Keyboard()
# Initialize components for Routine "Pause_screen"
Pause_screenClock = core.Clock()
backgound_for_pause_creen = visual.Rect(
win=win, name='backgound_for_pause_creen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "code_test"
code_testClock = core.Clock()
# Initialize components for Routine "Smell_creen_with_code"
Smell_creen_with_codeClock = core.Clock()
background_for_smell_screen = visual.Rect(
win=win, name='background_for_smell_screen',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
fixation_point_during_smell = visual.TextStim(win=win, name='fixation_point_during_smell',
text='+',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='red', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
fixation_point_during_smell_green = visual.TextStim(win=win, name='fixation_point_during_smell_green',
text='+',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='green', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
# Initialize components for Routine "test_trial"
test_trialClock = core.Clock()
background_test_trail = visual.Rect(
win=win, name='background_test_trail',
width=(2, 2)[0], height=(2, 2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor=[1,1,1], lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
image_test = visual.ImageStim(
win=win,
name='image_test',
image='sin', mask=None,
ori=0, pos=(0, 0), size=(1.5, 0.85),
color=[1,1,1], colorSpace='rgb', opacity=1,
flipHoriz=False, flipVert=False,
texRes=512, interpolate=True, depth=-1.0)
key_resp_test_trial = keyboard.Keyboard()
# Initialize components for Routine "codeTest_Finished"
codeTest_FinishedClock = core.Clock()
# Initialize components for Routine "blank_500"
blank_500Clock = core.Clock()
polygon_blank_500 = visual.Rect(
win=win, name='polygon_blank_500',
width=(2,2)[0], height=(2,2)[1],
ori=0, pos=(0, 0),
lineWidth=1, lineColor='white', lineColorSpace='rgb',
fillColor='white', fillColorSpace='rgb',
opacity=1, depth=0.0, interpolate=True)
# Initialize components for Routine "end_screen"
end_screenClock = core.Clock()
text_end_screen = visual.TextStim(win=win, name='text_end_screen',
text='Эксперимент завершен\n\nСпасибо!\nОставайтесь в кресле',
font='Arial',
pos=(0, 0), height=0.05, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
key_resp_2 = keyboard.Keyboard()
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
# ------Prepare to start Routine "code_initial"-------
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
code_initialComponents = []
for thisComponent in code_initialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
code_initialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "code_initial"-------
while continueRoutine:
# get current time
t = code_initialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=code_initialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in code_initialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "code_initial"-------
for thisComponent in code_initialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "code_initial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "Welcome_screen"-------
continueRoutine = True
# update component parameters for each repeat
key_resp.keys = []
key_resp.rt = []
_key_resp_allKeys = []
# keep track of which components have finished
Welcome_screenComponents = [text_welcome_screen, key_resp]
for thisComponent in Welcome_screenComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Welcome_screenClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "Welcome_screen"-------
while continueRoutine:
# get current time
t = Welcome_screenClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=Welcome_screenClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text_welcome_screen* updates
if text_welcome_screen.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text_welcome_screen.frameNStart = frameN # exact frame index
text_welcome_screen.tStart = t # local t and not account for scr refresh
text_welcome_screen.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text_welcome_screen, 'tStartRefresh') # time at next scr refresh
text_welcome_screen.setAutoDraw(True)
# *key_resp* updates
waitOnFlip = False
if key_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
key_resp.frameNStart = frameN # exact frame index
key_resp.tStart = t # local t and not account for scr refresh
key_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(key_resp, 'tStartRefresh') # time at next scr refresh
key_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(key_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(key_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if key_resp.status == STARTED and not waitOnFlip:
theseKeys = key_resp.getKeys(keyList=['q', '1'], waitRelease=True)
_key_resp_allKeys.extend(theseKeys)
if len(_key_resp_allKeys):
key_resp.keys = _key_resp_allKeys[-1].name # just the last key pressed
key_resp.rt = _key_resp_allKeys[-1].rt
# a response ends the routine
continueRoutine = False
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Welcome_screenComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Welcome_screen"-------
for thisComponent in Welcome_screenComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('text_welcome_screen.started', text_welcome_screen.tStartRefresh)
thisExp.addData('text_welcome_screen.stopped', text_welcome_screen.tStopRefresh)
# check responses
if key_resp.keys in ['', [], None]: # No response was made
key_resp.keys = None
thisExp.addData('key_resp.keys',key_resp.keys)
if key_resp.keys != None: # we had a response
thisExp.addData('key_resp.rt', key_resp.rt)
thisExp.addData('key_resp.started', key_resp.tStartRefresh)
thisExp.addData('key_resp.stopped', key_resp.tStopRefresh)
thisExp.nextEntry()
# the Routine "Welcome_screen" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
Study_trials = data.TrialHandler(nReps=1000, method='random',
extraInfo=expInfo, originPath=-1,
trialList=[None],
seed=None, name='Study_trials')
thisExp.addLoop(Study_trials) # add the loop to the experiment
thisStudy_trial = Study_trials.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb = thisStudy_trial.rgb)
if thisStudy_trial != None:
for paramName in thisStudy_trial:
exec('{} = thisStudy_trial[paramName]'.format(paramName))
for thisStudy_trial in Study_trials:
currentLoop = Study_trials
# abbreviate parameter names if possible (e.g. rgb = thisStudy_trial.rgb)
if thisStudy_trial != None:
for paramName in thisStudy_trial:
exec('{} = thisStudy_trial[paramName]'.format(paramName))
# ------Prepare to start Routine "Start_trial_screen"-------
continueRoutine = True
# update component parameters for each repeat
key_resp_for_start_trial.keys = []
key_resp_for_start_trial.rt = []
_key_resp_for_start_trial_allKeys = []
# keep track of which components have finished
Start_trial_screenComponents = [background_start_trial_screen, text__for_start_trial_screen, key_resp_for_start_trial, image_MARK]
for thisComponent in Start_trial_screenComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Start_trial_screenClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "Start_trial_screen"-------
while continueRoutine:
# get current time
t = Start_trial_screenClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=Start_trial_screenClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *background_start_trial_screen* updates
if background_start_trial_screen.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
background_start_trial_screen.frameNStart = frameN # exact frame index
background_start_trial_screen.tStart = t # local t and not account for scr refresh
background_start_trial_screen.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(background_start_trial_screen, 'tStartRefresh') # time at next scr refresh
background_start_trial_screen.setAutoDraw(True)
# *text__for_start_trial_screen* updates
if text__for_start_trial_screen.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text__for_start_trial_screen.frameNStart = frameN # exact frame index
text__for_start_trial_screen.tStart = t # local t and not account for scr refresh
text__for_start_trial_screen.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text__for_start_trial_screen, 'tStartRefresh') # time at next scr refresh
text__for_start_trial_screen.setAutoDraw(True)
# *key_resp_for_start_trial* updates
waitOnFlip = False
if key_resp_for_start_trial.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
key_resp_for_start_trial.frameNStart = frameN # exact frame index
key_resp_for_start_trial.tStart = t # local t and not account for scr refresh
key_resp_for_start_trial.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(key_resp_for_start_trial, 'tStartRefresh') # time at next scr refresh
key_resp_for_start_trial.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(key_resp_for_start_trial.clock.reset) # t=0 on next screen flip
win.callOnFlip(key_resp_for_start_trial.clearEvents, eventType='keyboard') # clear events on next screen flip
if key_resp_for_start_trial.status == STARTED and not waitOnFlip:
theseKeys = key_resp_for_start_trial.getKeys(keyList=['q', '1'], waitRelease=False)
_key_resp_for_start_trial_allKeys.extend(theseKeys)
if len(_key_resp_for_start_trial_allKeys):
key_resp_for_start_trial.keys = _key_resp_for_start_trial_allKeys[-1].name # just the last key pressed
key_resp_for_start_trial.rt = _key_resp_for_start_trial_allKeys[-1].rt
# a response ends the routine
continueRoutine = False
# *image_MARK* updates
if image_MARK.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
image_MARK.frameNStart = frameN # exact frame index
image_MARK.tStart = t # local t and not account for scr refresh
image_MARK.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(image_MARK, 'tStartRefresh') # time at next scr refresh
image_MARK.setAutoDraw(True)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Start_trial_screenComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Start_trial_screen"-------
for thisComponent in Start_trial_screenComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
Study_trials.addData('background_start_trial_screen.started', background_start_trial_screen.tStartRefresh)
Study_trials.addData('background_start_trial_screen.stopped', background_start_trial_screen.tStopRefresh)
Study_trials.addData('text__for_start_trial_screen.started', text__for_start_trial_screen.tStartRefresh)
Study_trials.addData('text__for_start_trial_screen.stopped', text__for_start_trial_screen.tStopRefresh)
# check responses
if key_resp_for_start_trial.keys in ['', [], None]: # No response was made
key_resp_for_start_trial.keys = None
Study_trials.addData('key_resp_for_start_trial.keys',key_resp_for_start_trial.keys)
if key_resp_for_start_trial.keys != None: # we had a response
Study_trials.addData('key_resp_for_start_trial.rt', key_resp_for_start_trial.rt)
Study_trials.addData('key_resp_for_start_trial.started', key_resp_for_start_trial.tStartRefresh)
Study_trials.addData('key_resp_for_start_trial.stopped', key_resp_for_start_trial.tStopRefresh)
# the Routine "Start_trial_screen" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "code_study"-------
study_display_order=['t','s','c','z']
#shuffle order to present symbols
random.seed()
random.shuffle(study_display_order)
#reset name of file to display
image_for_study="stimuli/"
#choose the stimulus
smell_correct=random.randrange(4)
#update number of stimuli presented
while True:
print ('random smell try#', smell_correct)
if odor_dict[odor_keys_list[smell_correct]] < limit_study:
odor_dict[odor_keys_list[smell_correct]] += 1
break
elif sum(odor_dict.values()) == limit_study*4:
odor_dict = {key: 0 for key in odor_keys_list}
Study_trials.finished = True
else:
smell_correct = random.randrange(4)
continue
print ('random smell#', smell_correct)
#open port and eject stimulus
if not isEmulate: eject(smell_correct)
#set correct symbol
correct_symbol=symbols[smell_correct]
#create name of file to display
for i in range(4):
if correct_symbol == study_display_order[i]:
#choose red if symbol represents correct smell
image_for_study+='r'
correct_key=keys[i]
else:
#choose black for other symbols
image_for_study+='b'
#add symbol name according to display order
image_for_study+=str(study_display_order[i])
#add .jpg to the filename
image_for_study+='.jpeg'
#set next study_number
study_number+=1
#set next trial_number
trial_number+=1
#add data to the file
thisExp.addData('correct_smell', smell_correct)
thisExp.addData('correct_symbol', correct_symbol)
thisExp.addData('image_selected', image_for_study)
thisExp.addData('correct_key', correct_key)
thisExp.addData('study_number', study_number)
thisExp.addData('trial_number', trial_number)
# keep track of which components have finished
code_studyComponents = []
for thisComponent in code_studyComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
code_studyClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "code_study"-------
while continueRoutine:
# get current time
t = code_studyClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=code_studyClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in code_studyComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "code_study"-------
for thisComponent in code_studyComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# the Routine "code_study" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "Smell_creen_with_code"-------
continueRoutine = True
routineTimer.add(fixation_point_duration)
# update component parameters for each repeat
# keep track of which components have finished
Smell_creen_with_codeComponents = [background_for_smell_screen, fixation_point_during_smell]
for thisComponent in Smell_creen_with_codeComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Smell_creen_with_codeClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "Smell_creen_with_code"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = Smell_creen_with_codeClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=Smell_creen_with_codeClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *background_for_smell_screen* updates
if background_for_smell_screen.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
background_for_smell_screen.frameNStart = frameN # exact frame index
background_for_smell_screen.tStart = t # local t and not account for scr refresh
background_for_smell_screen.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(background_for_smell_screen, 'tStartRefresh') # time at next scr refresh
background_for_smell_screen.setAutoDraw(True)
if background_for_smell_screen.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > background_for_smell_screen.tStartRefresh + fixation_point_duration-frameTolerance:
# keep track of stop time/frame for later
background_for_smell_screen.tStop = t # not accounting for scr refresh
background_for_smell_screen.frameNStop = frameN # exact frame index
win.timeOnFlip(background_for_smell_screen, 'tStopRefresh') # time at next scr refresh
background_for_smell_screen.setAutoDraw(False)
# *fixation_point_during_smell* updates
if fixation_point_during_smell.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_point_during_smell.frameNStart = frameN # exact frame index
fixation_point_during_smell.tStart = t # local t and not account for scr refresh
fixation_point_during_smell.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_point_during_smell, 'tStartRefresh') # time at next scr refresh
fixation_point_during_smell.setAutoDraw(True)
if fixation_point_during_smell.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation_point_during_smell.tStartRefresh + fixation_point_duration-frameTolerance:
# keep track of stop time/frame for later
fixation_point_during_smell.tStop = t # not accounting for scr refresh
fixation_point_during_smell.frameNStop = frameN # exact frame index
win.timeOnFlip(fixation_point_during_smell, 'tStopRefresh') # time at next scr refresh
fixation_point_during_smell.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Smell_creen_with_codeComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Smell_creen_with_code"-------
for thisComponent in Smell_creen_with_codeComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
Study_trials.addData('background_for_smell_screen.started', background_for_smell_screen.tStartRefresh)
Study_trials.addData('background_for_smell_screen.stopped', background_for_smell_screen.tStopRefresh)
Study_trials.addData('fixation_point_during_smell.started', fixation_point_during_smell.tStartRefresh)
Study_trials.addData('fixation_point_during_smell.stopped', fixation_point_during_smell.tStopRefresh)
# ------Prepare to start Routine "Smell_creen_with_code_green"-------
continueRoutine = True
routineTimer.add(fixation_point_duration_green)
# update component parameters for each repeat
# keep track of which components have finished
Smell_creen_with_code_greenComponents = [background_for_smell_screen, fixation_point_during_smell_green]
for thisComponent in Smell_creen_with_code_greenComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
Smell_creen_with_code_greenClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "Smell_creen_with_code_green"-------
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = Smell_creen_with_code_greenClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=Smell_creen_with_code_greenClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *background_for_smell_screen* updates
if background_for_smell_screen.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
background_for_smell_screen.frameNStart = frameN # exact frame index
background_for_smell_screen.tStart = t # local t and not account for scr refresh
background_for_smell_screen.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(background_for_smell_screen, 'tStartRefresh') # time at next scr refresh
background_for_smell_screen.setAutoDraw(True)
if background_for_smell_screen.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > background_for_smell_screen.tStartRefresh + fixation_point_duration_green-frameTolerance:
# keep track of stop time/frame for later
background_for_smell_screen.tStop = t # not accounting for scr refresh
background_for_smell_screen.frameNStop = frameN # exact frame index
win.timeOnFlip(background_for_smell_screen, 'tStopRefresh') # time at next scr refresh
background_for_smell_screen.setAutoDraw(False)
# *fixation_point_during_smell_green* updates
if fixation_point_during_smell_green.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
fixation_point_during_smell_green.frameNStart = frameN # exact frame index
fixation_point_during_smell_green.tStart = t # local t and not account for scr refresh
fixation_point_during_smell_green.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(fixation_point_during_smell_green, 'tStartRefresh') # time at next scr refresh
fixation_point_during_smell_green.setAutoDraw(True)
if fixation_point_during_smell_green.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > fixation_point_during_smell_green.tStartRefresh + fixation_point_duration_green-frameTolerance:
# keep track of stop time/frame for later
fixation_point_during_smell_green.tStop = t # not accounting for scr refresh
fixation_point_during_smell_green.frameNStop = frameN # exact frame index
win.timeOnFlip(fixation_point_during_smell_green, 'tStopRefresh') # time at next scr refresh
fixation_point_during_smell_green.setAutoDraw(False)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in Smell_creen_with_code_greenComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "Smell_creen_with_code_green"-------
for thisComponent in Smell_creen_with_code_greenComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
Study_trials.addData('background_for_smell_screen.started', background_for_smell_screen.tStartRefresh)
Study_trials.addData('background_for_smell_screen.stopped', background_for_smell_screen.tStopRefresh)
Study_trials.addData('fixation_point_during_smell_green.started', fixation_point_during_smell.tStartRefresh)
Study_trials.addData('fixation_point_during_smell_green.stopped', fixation_point_during_smell.tStopRefresh)
# ------Prepare to start Routine "study_trial"-------
continueRoutine = True
# update component parameters for each repeat
image_study.setImage(image_for_study)
key_resp_study_trial.keys = []
key_resp_study_trial.rt = []
_key_resp_study_trial_allKeys = []
# keep track of which components have finished
study_trialComponents = [polygon_study_background, image_study, key_resp_study_trial]
for thisComponent in study_trialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
study_trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "study_trial"-------
while continueRoutine:
# get current time
t = study_trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=study_trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *polygon_study_background* updates
if polygon_study_background.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
polygon_study_background.frameNStart = frameN # exact frame index
polygon_study_background.tStart = t # local t and not account for scr refresh