Guest User

Untitled

a guest
Feb 18th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.48 KB | None | 0 0
  1. ## Globals relating to experiment control
  2. int blockRun = 0;
  3. bool reverseBlocks = false; # Change this to true to reverse block selection (set 2 comes first)
  4.  
  5. ## Globals relating to output
  6. string feedback, subject_info, outfile_name, timelock, blocktype="1Practice";
  7. string outfile_suffix = ".txt";
  8. string trigger_accuracy = "";
  9. string eeg_trigger = "";
  10. string trial_description = "prac";
  11. output_file outfile = new output_file;
  12. int blink_break = 7; #80 trials per block + 4 catch trials = 42 trials
  13. int between_block_break = 84;
  14. int trial_num = 1, block_num = 1, correct_trials = 0, trials_so_far = 0;
  15. int calc_port_code;
  16. int min_ISI = 400, max_ISI = 900, long_ISI_duration = 1000, actual_ISI, calc_ISI_duration; # ISI timing variables
  17. array <string> parts[5]; # For storing the various description details
  18.  
  19. ## Globals relating to trial display
  20. # Picture counters
  21. int happy_pics = 80;
  22. int sad_pics = 80;
  23. int gloloc_pics = 4;
  24. int total_pics = happy_pics+sad_pics;
  25. int failures = -1;
  26.  
  27. # Picture arrays
  28. array <int> trial_order[2];
  29. array <int> block1[happy_pics/2+sad_pics/2];
  30. array <int> block2[happy_pics/2+sad_pics/2];
  31. array <int> global_local_array[total_pics];
  32.  
  33. #------------ subroutine to write out a line of breaks ------------
  34. sub
  35. update_output_file_break
  36. begin
  37.  
  38. outfile.print( subject_info + "\t");
  39. outfile.print( string(trial_num) + "\t"); # current trial number
  40. outfile.print( string(block_num) + "\t"); # current block number
  41.  
  42. loop
  43. int i = 1;
  44. until
  45. i > 17 # write break in 17 additional columns
  46. begin
  47. outfile.print( "break" + "\t"); # print break instead just to include the line in output
  48. i = i + 1;
  49. end;
  50. outfile.print( "break" + "\n"); # and the final column
  51.  
  52. end;
  53.  
  54. /*sub
  55. update_output_file_oddemotion
  56. begin
  57.  
  58. outfile.print( subject_info + "\t");
  59. outfile.print( string(trial_num) + "\t"); # current trial number
  60. outfile.print( string(block_num) + "\t"); # current block number
  61. outfile.print ( string( stimulus_manager.last_stimulus_data().button()) + "\t" );
  62. outfile.print( "\n"); # and the final column
  63.  
  64. end;
  65. */
  66.  
  67. #------------- subroutine to write the column headings for the output file
  68.  
  69. sub
  70. header_output_file
  71. begin
  72.  
  73. outfile.print("subject"
  74. + "\t" + "trial"
  75. + "\t" + "emotion"
  76. + "\t" + "gender"
  77. + "\t" + "gaze"
  78. + "\t" + "pic#"
  79. + "\t" + "part_trigger" #AML1, AML1Bg
  80. + "\t" + "blocktype"
  81. + "\t" + "gloloc"
  82. + "\t" + "glopic"
  83. + "\t" + "event_code"
  84. + "\t" + "face_filename"
  85. + "\t" + "gloloc_filename"
  86. /*+ "\t" + "RT-EMO"
  87. + "\t" + "resp_button-EMO"
  88. + "\t" + "accuracy-EMO" */
  89. + "\t" + "ISI"
  90. + "\t" + "resp_port_code"
  91. + "\t" + "time_lock"
  92. + "\t" + "stim_port_code"
  93. + "\t" + "RT-GL"
  94. + "\t" + "resp_button-GL"
  95. + "\t" + "accuracy-GL"
  96. + "\t" + "trigger"
  97. + "\n");
  98.  
  99. end;
  100.  
  101. #------------ subroutines to write out the trial ------------
  102.  
  103.  
  104. sub
  105. output_one_line ( int type, string filename)
  106. begin
  107. trial_description = stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).event_code() + ", " + stimulus_manager.last_stimulus_data().event_code();
  108. outfile.print(trial_description+"\n");
  109.  
  110. trial_description.split( ",", parts );
  111. string current_resp = "miss";
  112.  
  113.  
  114. parts[5] = parts[5] + parts[6].substring(1,1); # add blocktype (h#, n# or a#) to the part trigger
  115.  
  116. array <string> fileparts[2];
  117. filename.split(" ", fileparts);
  118.  
  119. outfile.print ( subject_info + "\t" );
  120. outfile.print ( string(trial_num) + "\t" ); # current trial number
  121.  
  122. loop int p = 1 until p > parts.count() # print up until non-shared fields
  123. begin
  124. outfile.print( parts[p] + "\t");
  125. p = p + 1;
  126. end;
  127.  
  128. /*if(type == 1) then # For the face stimulus
  129. outfile.print( "" + "\t"); # gloloc
  130. outfile.print( "" + "\t"); # gloloc image number
  131. outfile.print ( trial_description + "\t" );
  132. outfile.print ( fileparts[1] + "\t" );
  133. outfile.print ( "" + "\t");
  134. outfile.print ( "" + "\t");
  135. outfile.print ( "" + "\t");
  136. outfile.print ( "" + "\t");
  137. outfile.print ( string(actual_ISI) + "\t" );
  138. outfile.print ( "" + "\t");
  139. timelock = "stimlock";
  140. else # For the gloloc & response*/
  141. outfile.print ( trial_description + "\t" );
  142. outfile.print ( fileparts[1] + "\t");
  143. outfile.print ( fileparts[2] + "\t" );
  144. /*outfile.print ( string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).reaction_time()) + "\t" ); # rt
  145. outfile.print ( string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).button()) + "\t" ); # response button
  146. trigger_accuracy = "e";
  147. if stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_hit then
  148. current_resp = "hit";
  149. trigger_accuracy = "c";
  150. correctanswer = true;
  151. elseif stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_miss then current_resp = "miss";
  152. elseif stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_incorrect then current_resp = "error";
  153. else current_resp = "other";
  154. end;
  155.  
  156. outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other */
  157. outfile.print ( string(actual_ISI) + "\t" );
  158. string current_button_code;
  159. if stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() == stimulus_miss
  160. then current_button_code = "none";
  161. else
  162. current_button_code = string( stimulus_manager.get_stimulus_data(stimulus_manager.stimulus_count()-1).type() );
  163. end;
  164.  
  165. outfile.print ( current_button_code + "\t" ); # button code is erp response port code
  166.  
  167. if(type==2) then
  168. timelock = "stimlock";
  169. else
  170. timelock = "resplock";
  171. end;
  172. # end;
  173.  
  174. outfile.print(timelock + "\t"); # timelock
  175. outfile.print( string(calc_port_code) + "\t" ); # port out stimulus port code
  176. eeg_trigger = "2";#eeg_trigger = parts[5];
  177. if(type != 1) then
  178. eeg_trigger = eeg_trigger + parts[parts.count()];
  179. end;
  180. # if(type == 4) then
  181. outfile.print ( string( stimulus_manager.last_stimulus_data().reaction_time()) + "\t" ); # rt
  182. outfile.print ( string( stimulus_manager.last_stimulus_data().button()) + "\t" ); # response button
  183. trigger_accuracy = "e";
  184. current_resp = "miss";
  185. if stimulus_manager.last_stimulus_data().type() == stimulus_hit then
  186. current_resp = "hit";
  187. correct_trials = correct_trials + 1;
  188. trigger_accuracy = "c";
  189. elseif stimulus_manager.last_stimulus_data().type() == stimulus_miss then current_resp = "miss";
  190. elseif stimulus_manager.last_stimulus_data().type() == stimulus_incorrect then current_resp = "error";
  191. else current_resp = "other";
  192. end;
  193.  
  194. outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other
  195. /* else
  196. outfile.print( "\t");
  197. outfile.print( "\t");
  198. outfile.print( "\t");
  199. end;*/
  200. outfile.print(timelock.substring(1,1)+eeg_trigger+trigger_accuracy + "\n");
  201. outfile.print(stimulus_manager.stimulus_count());
  202. end;
  203.  
  204. sub
  205. showBreaks
  206. begin
  207.  
  208. # note the following works only if between_block_break is divisible by blink_break
  209. if mod(trial_num, blink_break) == 0 && trial_num != total_pics # provide blink breaks
  210. then
  211. feedback = "You got " + string(correct_trials) + " out of " + string(trials_so_far) + " correct.";
  212. text_accuracy.set_caption (feedback);
  213. text_accuracy.redraw();
  214.  
  215. if mod(trial_num, between_block_break) == 0 && trial_num != total_pics
  216. # provide longer breaks between blocks
  217. then
  218. #oddemotion_trial.present();
  219. #update_output_file_oddemotion();
  220. block_break_trial.present();
  221. update_output_file_break(); # write line in output for blink break so match trigger file
  222. # this port out time timelocked to the response
  223. # picture onset does not port out, is this because there is no port_code for the trial?
  224. else
  225. break_trial.present();
  226. update_output_file_break(); # write line in output for blink break so match trigger file
  227. # this port out time timelocked to the response
  228. end; # if between_block_break
  229.  
  230. correct_trials = 0; # reset for next set of trials
  231. trials_so_far = 0;
  232.  
  233. ISI_event.set_duration (long_ISI_duration );
  234. ISI_trial.present();
  235. end; # if blink break
  236.  
  237. trial_num = trial_num + 1; # update after every stimulus presentation
  238. eeg_trigger = ""; # reset the eeg_trigger
  239. trial_description = "";
  240. end; # of subroutine
  241.  
  242.  
  243.  
  244. sub
  245. generate_global_local_array
  246. begin
  247. loop int j=1 until j > global_local_array.count()
  248. begin
  249. # Assign global_local associations for all pictures
  250. # Two straight pictures should be opposites
  251.  
  252. global_local_array[j] = 1; # Straight Pic 1 -- Random!
  253. global_local_array[j+1] = 2; # Straight Pic 2 --
  254.  
  255. j=j+2;
  256. end;
  257. end;
  258.  
  259. sub
  260. validate_array( array< int, 1> &validateArray, bool checkGL)
  261. begin
  262. int last_seen_gl = -1, last_seen_img = -1, last_last_seen_img = -1;
  263. loop int j=1 until j > validateArray.count()
  264. begin
  265. if((global_local_array[validateArray[j]] == last_seen_gl && checkGL==true) ||
  266. ((validateArray[j]/84) == last_seen_img && last_seen_img == last_last_seen_img) ) then # Something is wrong.
  267. #outfile.print("\nSomething is wrong! Image #: "+string(validateArray[j]));
  268. #outfile.print(" emotion match: "+string(validateArray[j]/132)+"=="+string(last_seen_img)+"=="+string(last_last_seen_img)+"\n");
  269. #outfile.print(" gl match: "+string(global_local_array[validateArray[j]])+"=="+string(last_seen_gl)+"\n");
  270.  
  271. loop int k=j+1 until k > validateArray.count() # search for a valid picture
  272. begin
  273. if((global_local_array[validateArray[k]] != last_seen_gl || checkGL==false) && !(((validateArray[k]/84) == last_seen_img) && (last_seen_img==last_last_seen_img))) then
  274. #outfile.print("\n Swapping with! Image #: "+string(validateArray[k]));
  275. #outfile.print("emotion change: "+string(validateArray[j]/132)+" to "+string(validateArray[k]/132));
  276. #outfile.print(" gl change: "+string(global_local_array[validateArray[j]])+" to "+string(global_local_array[validateArray[k]])+"\n");
  277. int temp = validateArray[j];
  278. validateArray[j] = validateArray[k];
  279. validateArray[k] = temp;
  280. break;
  281. else
  282. #outfile.print("F: I#"+string(validateArray[k])+" E#"+string(validateArray[k]/132)+" G#"+string(global_local_array[validateArray[k]])+"\n");
  283. end;
  284. k = k + 1;
  285. if(k > validateArray.count()) then
  286. #outfile.print("\nFailed to swap in! Image #: "+string(validateArray[j])+"\n");
  287. failures = failures+1;
  288. end;
  289. end;
  290. end;
  291. last_seen_gl = global_local_array[validateArray[j]]; # Get the G/L indicator for this picture
  292. last_last_seen_img = last_seen_img;
  293. last_seen_img = (validateArray[j]/84);
  294. j = j + 1;
  295. end;
  296. end;
  297.  
  298.  
  299.  
  300. sub
  301. generate_block_arrays( array< int, 1 >& block_array1, array< int, 1>& block_array2, int num_pics)
  302. begin
  303. int k = 1; #k = the picture's place within each of the arrays while j= the picture number overall
  304. loop int j=1 until j > (num_pics)
  305. begin
  306. block_array1[k] = j; # Straight
  307. block_array2[k+1] = j+1; # Straight2
  308.  
  309. block_array2[k] = j+2; # Straight1
  310. block_array1[k+1] = j+3; # Straight2
  311.  
  312.  
  313. if(j+3 >= (num_pics)) then
  314. break;
  315. end;
  316.  
  317. block_array1[k] = j; # Straight
  318. block_array2[k+1] = j+1; # Straight2
  319.  
  320. block_array2[k] = j+2; # Straight1
  321. block_array1[k+1] = j+3; # Straight2
  322.  
  323. j=j+4; # Onto the next set of 4 people
  324. k=k+2; # Onto the next set of 4 people (divided into two arrays)
  325. end;
  326. block_array1.shuffle();
  327. block_array2.shuffle();
  328.  
  329. validate_array(block_array1, true);
  330. outfile.print("\n************************************************************\n");
  331. validate_array(block_array2, true);
  332.  
  333.  
  334. /*loop int mir=1 until mir>block_array1.count()
  335. begin
  336. outfile.print(string(block_array1[mir])+" ");
  337. mir = mir + 1;
  338. end;
  339. outfile.print("\n");
  340. loop int mir=1 until mir>block_array2.count()
  341. begin
  342. outfile.print(string(block_array2[mir])+" ");
  343. mir = mir + 1;
  344. end;
  345.  
  346. loop int mir=1 until mir>block_array1.count()
  347. begin
  348. string x = face_pics[block_array1[mir]].filename();
  349. outfile.print(x + "\n");
  350. mir = mir + 1;
  351. end;
  352. outfile.print("\n");
  353.  
  354. loop int mir=1 until mir>block_array2.count()
  355. begin
  356. string x = face_pics[block_array2[mir]].filename();
  357. outfile.print(x + "\n");
  358. mir = mir + 1;
  359. end;
  360. outfile.print("\n");*/
  361. end;
  362.  
  363. sub
  364. trials_display( array< int, 1 >& displayArray, int portCode, int emotion)
  365. begin
  366.  
  367. array <string> fileparts[4];
  368.  
  369. int catchCounter = 0;
  370. loop int j=1 until j > displayArray.count()
  371. begin
  372. int pic_index;
  373. calc_ISI_duration = random(min_ISI,max_ISI);
  374. ISI_event.set_duration (calc_ISI_duration);
  375. actual_ISI = calc_ISI_duration + 1500 - 250; # these should be set as variables at some point
  376.  
  377. # Replace placeholder face with face
  378. bitmap actual_face;
  379. if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1))
  380. then
  381. # face pics= total pics in the experiment represented in an array
  382. actual_face = catch_pics[catchCounter+1];
  383. else
  384. actual_face = face_pics[(displayArray[j])];
  385. end;
  386. face_picture.set_part(1,actual_face); # replace the PLACEHOLDER with the actual picture that was selected
  387. show_face.set_stimulus(face_picture); # the picture is the stimulus!
  388. show_face.set_event_code(actual_face.description() + ","+blocktype);
  389. calc_port_code = 102;
  390. show_face.set_port_code(calc_port_code);
  391.  
  392. # Replace placeholder with global/local
  393. int gloloc_index;
  394. int gloaccess = displayArray[j];
  395. if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1))
  396. then
  397. gloaccess = gloaccess - 1;
  398. end;
  399.  
  400. if(global_local_array[gloaccess] == 1) then #this checks to see which global-local stim should be shown with this face
  401. gloloc_index = random(1,gloloc_pics/2);
  402. else
  403. gloloc_index = random((gloloc_pics/2+1),gloloc_pics);
  404. end;
  405. /*
  406. if(displayArray[j] <= 132) then
  407. show_face.set_target_button(1);
  408. else
  409. show_face.set_target_button(2);
  410. end;
  411. */
  412. if(gloloc_index == 1 || gloloc_index == 3) then ## 2
  413. show_gloloc.set_target_button(2);
  414. else ## 5
  415. show_gloloc.set_target_button(1);
  416. end;
  417. bitmap actual_gloloc = global_local_pics[gloloc_index];
  418. gloloc_picture.set_part(1,actual_gloloc);
  419. show_gloloc.set_stimulus(gloloc_picture);
  420. show_gloloc.set_event_code(actual_gloloc.description());
  421. calc_port_code = 103;
  422. show_gloloc.set_port_code(calc_port_code);
  423. show_trial.present();
  424.  
  425. string x = actual_face.filename(), flname;
  426. x.split("\\", fileparts); # Split the filename by directory
  427. flname = fileparts[fileparts.count()]; # Take the last item (filename.jpg)
  428.  
  429. x = actual_gloloc.filename();
  430. x.split("\\", fileparts);
  431. flname = flname + " " + fileparts[fileparts.count()]; # Take both filenames together
  432.  
  433. output_one_line(1,flname); # Write relevant data
  434.  
  435. #show_gloloc_trial.present(); # Show the global/loc portion of the trial
  436. #output_one_line(2, flname); # Write relevant data
  437. #output_one_line(3, flname);
  438. #utput_one_line(4, flname);
  439. ISI_trial.present();
  440.  
  441. trials_so_far = trials_so_far + 1;
  442. showBreaks();
  443. if((j == 27 && catchCounter == 0) || (j == 54 && catchCounter == 1)) then
  444. catchCounter = catchCounter + 1;
  445. else
  446. j=j+1;
  447. end;
  448. end;
  449. end;
  450.  
  451. sub
  452. output_prac ( string filename)
  453. begin
  454. trial_description = stimulus_manager.last_stimulus_data().event_code();
  455.  
  456. outfile.print ( subject_info + "\t" );
  457. outfile.print ( string(trial_num) + "\t" ); # current trial number
  458. outfile.print ( trial_description + "\t" );
  459. outfile.print ( filename + "\t");
  460. outfile.print ( string( stimulus_manager.last_stimulus_data().reaction_time()) + "\t" ); # rt
  461. string current_resp = "miss";
  462. if stimulus_manager.last_stimulus_data().type() == stimulus_hit then
  463. current_resp = "hit";
  464. elseif stimulus_manager.last_stimulus_data().type() == stimulus_miss then current_resp = "miss";
  465. elseif stimulus_manager.last_stimulus_data().type() == stimulus_incorrect then current_resp = "error";
  466. else current_resp = "other";
  467. end;
  468. outfile.print ( current_resp + "\t" ); # accuracy as hit miss error other
  469. outfile.print("\n");
  470. end;
  471.  
  472. sub prac
  473. begin
  474. int gloloc_index= 0;
  475. string x, flname;
  476. array <string> fileparts[4];
  477. loop int j=1 until j > 21
  478. begin
  479. if (j%2==0) then #this checks to see which global-local stim should be shown with this face
  480. gloloc_index = random(1,gloloc_pics/2);
  481. else
  482. gloloc_index = random((gloloc_pics/2+1),gloloc_pics);
  483. end;
  484.  
  485. if(gloloc_index == 1 || gloloc_index == 3) then ## 2
  486. show_gloloc.set_target_button(1);
  487. else ## 5
  488. show_gloloc.set_target_button(2);
  489. end;
  490. bitmap actual_gloloc = global_local_pics[gloloc_index];
  491. gloloc_picture.set_part(1,actual_gloloc);
  492. show_gloloc.set_stimulus(gloloc_picture);
  493. show_gloloc.set_event_code(actual_gloloc.description());
  494. calc_port_code = 103;
  495. show_gloloc.set_port_code(calc_port_code);
  496.  
  497. #show_gloloc_trial.present(); # Show the global/loc portion of the trial
  498. x = actual_gloloc.filename();
  499. x.split("\\", fileparts);
  500. flname = flname + " " + fileparts[fileparts.count()]; # Take both filenames together
  501. output_prac( flname); # Write relevant data
  502. ISI_trial.present();
  503. j= j+1;
  504. end;
  505. begin
  506. prac_block_break_trial.present();
  507. update_output_file_break();
  508. end;
  509. end;
  510.  
  511.  
  512. # start of experiment
  513.  
  514. subject_info = logfile.subject(); # get subject info from Pres. setting in "Logfiles" tab
  515. #blockRun = int(subject_info)%6;
  516. logfile.set_filename( subject_info + ".log" ); # set Pres logfile to same name as subject info sets the log name
  517.  
  518. outfile_name = subject_info + outfile_suffix; # set up output file sets the txt file name
  519. outfile.open_append( outfile_name );
  520.  
  521. header_output_file(); # write the output column headers
  522.  
  523. begin_trial.present(); # welcome and instructions- refers back to scenario file where the instructions are described
  524.  
  525. ISI_event.set_duration (long_ISI_duration ); #change the duration of ISI event to be a longer break before start of block and start of experiment
  526. ISI_trial.present();
  527.  
  528. block_num = 1;
  529.  
  530. generate_global_local_array();
  531.  
  532. loop until failures==0 begin
  533. failures = 0;
  534. generate_block_arrays(block1,block2, total_pics);
  535. if(failures > 0) then
  536. outfile.print(string(failures) + " failures detected. Reassigning arrays.\n");
  537. end;
  538. end;
  539.  
  540. /*loop int i=1 until i > happy_pics/2
  541. begin
  542. string x = string(happy_array1[i]);
  543. bitmap actual_face = face_pics[(happy_array1[i])];
  544. string x = actual_face.filename();
  545. outfile.print(x + "\n");
  546. i = i+1;
  547. end;
  548. /* creating alternate block orders is not
  549. necessary for esp02 since all blocks contain mixed emotions
  550.  
  551. if blockRun == 0 then
  552. trial_order = {1,2,3,4,5,6};
  553. elseif blockRun == 1 then
  554. trial_order = {2,3,1,5,6,4};
  555. elseif blockRun == 2 then
  556. trial_order = {2,1,3,5,4,6}
  557. elseif blockRun == 3 then
  558. trial_order = {3,1,2,6,4,5};
  559. elseif blockRun == 4 then
  560. trial_order = {3,2,1,6,5,4};
  561. elseif blockRun == 5 then
  562. trial_order = {1,3,2,4,6,5};
  563. end;
  564. */
  565. trial_order = {1,2};
  566. trial_order.shuffle();
  567. #prac();
  568.  
  569. loop int j=1 until j > trial_order.count()
  570. begin
  571. if(trial_order[j] == 1) then
  572. blocktype = "1Block";
  573. trials_display(block1,100, 2);
  574. elseif(trial_order[j] == 2) then
  575. blocktype = "2Block";
  576. trials_display(block2,100, 0);
  577. end;
  578. block_num = block_num + 1;
  579. j = j+1;
  580. end;
  581.  
  582.  
  583. thanks_trial.present(); # goodbye
Add Comment
Please, Sign In to add comment