Browse Source

Increasing font on ResponseBox image, integrating image display into text screen display in template. -MT

master
Michael Tan 6 years ago
parent
commit
5be3b559d6
  1. BIN
      Images/ResponseBox3.tif
  2. 4
      SaccadePursuit.py
  3. 74
      SaccadePursuitEyeTracking.py
  4. BIN
      __pycache__/SaccadePursuitEyeTracking.cpython-36.pyc
  5. 20
      template.py

BIN
Images/ResponseBox3.tif

Binary file not shown.

4
SaccadePursuit.py

@ -200,7 +200,7 @@ class SPtask(template.BaseExperiment): @@ -200,7 +200,7 @@ class SPtask(template.BaseExperiment):
"""Displays a break screen in between blocks.
"""
break_text = 'Please take a short break. Press space to continue.'
break_text = 'Please take a short break. Press any key to continue.'
self.display_text_screen(text=break_text, bg_color=[0, 0, 0])
def display_fixation(self, wait_time, necker_bg_color=[-1,-1,-1]):
@ -351,7 +351,7 @@ class SPtask(template.BaseExperiment): @@ -351,7 +351,7 @@ class SPtask(template.BaseExperiment):
responses.append((response[0],direction,psychopy.core.getAbsTime()))
if tracker:
#print(response[0])
tracker.send_message(['Direction: %s' % direction])
tracker.send_message(['Direction: %s, Key: %s' % (direction, response[0])])
stim.draw()
self.experiment_window.flip()
#print(responses)

74
SaccadePursuitEyeTracking.py

@ -47,7 +47,7 @@ saccade_distance = 15 #15 @@ -47,7 +47,7 @@ saccade_distance = 15 #15
saccade_time = 3 #3
stimulus_size = 0.3
stim_color = [1,-1,-1]
saccade_fixation_color = [.5,.5,.5]
saccade_fixation_color = [191,191,191]
# Pursuit Parameters
number_of_pursuit_trials = 1
@ -59,12 +59,12 @@ pursuit_time = [5,5,5] #[40,20,15] @@ -59,12 +59,12 @@ pursuit_time = [5,5,5] #[40,20,15]
# Necker Cube Parameters
number_of_necker_trials = 1
number_of_necker_blocks = 4
necker_time = 60
necker_time = 6
necker_color = [191,191,191]
necker_bg_color = [-0.5,-0.5,-0.5]
necker_bg_color = [64,64,64]
necker_scale = 0.5
necker_file = os.path.join(image_directory,'Necker1.tif')
response_box_file = os.path.join(image_directory,'ResponseBox2.tif')
response_box_file = os.path.join(image_directory,'ResponseBox3.tif')
# Fixation Parameters
number_of_fixation_trials = 1
@ -79,7 +79,7 @@ rivalry_time = 90 @@ -79,7 +79,7 @@ rivalry_time = 90
rivalry_scale = 2.5
rivalry_file1 = os.path.join(image_directory,'house4n_11-160.tif')
rivalry_file2 = os.path.join(image_directory,'face2nS_11-160.tif')
rivalry_border_color = [0.5,0.5,0.5]
rivalry_border_color = [191,191,191]
rivalry_border_width = 5
rivalry_distance = 4
@ -110,7 +110,7 @@ instruct_text = [ @@ -110,7 +110,7 @@ instruct_text = [
'Do not move your head during the trials of this '
'experiment. Move only your eyes to follow the targets.'
'You will get breaks in between blocks.\n\n'
'Press space to continue.'),
'Press any key to continue.'),
]
saccade_instruct_text = (
@ -118,7 +118,7 @@ saccade_instruct_text = ( @@ -118,7 +118,7 @@ saccade_instruct_text = (
'appears, move your gaze to the target. Move your gaze back to '
'the fixation point after the target disappears.\n\n'
'Try not to blink after the target appears.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
antisaccade_instruct_text = (
@ -128,21 +128,21 @@ antisaccade_instruct_text = ( @@ -128,21 +128,21 @@ antisaccade_instruct_text = (
'the target. Move your gaze back to the fixation point after '
'the target disappears.\n\n'
'Try not to blink after the target appears.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
pursuit_instruct_text = (
'For these trials, when the circle target appears, follow the '
'target with your eyes.\n\n'
'Try not to blink while the circle is moving.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
fixation_instruct_text = (
'For these trials, when the cross appears, fixate on it.\n\n'
'Try not to move your eyes from the cross while it '
'remains visible.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
necker_instruct_text = (
@ -152,7 +152,7 @@ necker_instruct_text = ( @@ -152,7 +152,7 @@ necker_instruct_text = (
'switches to up and to the right, press the right '
'button.\n\n'
'Respond at any time during the stimulus.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
rivalry_instruct_text = (
@ -164,9 +164,17 @@ rivalry_instruct_text = ( @@ -164,9 +164,17 @@ rivalry_instruct_text = (
'you perceive a combination of the face and house, '
'press the middle button.\n\n'
'Respond at any time during the stimuli.\n\n'
'Press space to continue.'
'Press any key to continue.'
)
def convert_color_value(color):
"""Converts a list of 3 values from 0 to 255 to -1 to 1.
Parameters:
color -- A list of 3 ints between 0 and 255 to be converted.
"""
return [round(((n/127.5)-1), 2) for n in color]
class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
def __init__(self, **kwargs):
@ -204,27 +212,6 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask): @@ -204,27 +212,6 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
subprocess.call(['edf2asc',fName])
super(EyeTrackingSaccadePursuit, self).quit_experiment()
def display_necker_instructions(self, text):
textObject = psychopy.visual.TextStim(
self.experiment_window, text=text, color=[1,1,1], units='pix',
height=36, alignHoriz='center', alignVert='center',
wrapWidth=round(.8*self.experiment_window.size[0]))
imageObject = psychopy.visual.ImageStim(
self.experiment_window, units='pix',
image=self.response_box_file)
sizex = int(round(imageObject.size[0])*0.25)
sizey = int(round(imageObject.size[1])*0.25)
imageObject.size = [sizex,sizey]
imageObject.pos = (0,-self.experiment_window.size[1]/2+sizey/2)
print(imageObject.pos)
textObject.draw()
imageObject.draw()
self.experiment_window.flip()
psychopy.core.wait(.2) # Prevents accidental key presses
keys = psychopy.event.waitKeys()
self.experiment_window.flip()
def run(self):
self.chdir()
@ -282,12 +269,11 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask): @@ -282,12 +269,11 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
numBlocks = self.number_of_pursuit_blocks
numTrials = self.number_of_pursuit_trials
elif condition=='Necker':
#self.display_text_screen(text=necker_instruct_text)
self.display_necker_instructions(text=necker_instruct_text)
self.display_text_screen(text=necker_instruct_text, image_file=self.response_box_file)
numBlocks = self.number_of_necker_blocks
numTrials = self.number_of_necker_trials
elif condition=='Rivalry':
self.display_text_screen(text=rivalry_instruct_text)
self.display_text_screen(text=rivalry_instruct_text, image_file=self.response_box_file)
numBlocks = self.number_of_rivalry_blocks
numTrials = self.number_of_rivalry_trials
else:
@ -339,8 +325,16 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask): @@ -339,8 +325,16 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
self.display_text_screen(text='Remember:\n\n' + saccade_instruct_text)
elif condition=='AntiSaccade':
self.display_text_screen(text='Remember:\n\n' + antisaccade_instruct_text)
else:
elif condition=='Fixation':
self.display_text_screen(text='Remember:\n\n' + fixation_instruct_text)
elif condition=='Pursuit':
self.display_text_screen(text='Remember:\n\n' + pursuit_instruct_text)
elif condition=='Necker':
self.display_text_screen(text='Remember:\n\n' + necker_instruct_text,
image_file=self.response_box_file)
elif condition=='Rivalry':
self.display_text_screen(text='Remember:\n\n' + rivalry_instruct_text,
image_file=self.response_box_file)
self.display_text_screen(
'The experiment is now over.',
@ -366,20 +360,20 @@ experiment = EyeTrackingSaccadePursuit( @@ -366,20 +360,20 @@ experiment = EyeTrackingSaccadePursuit(
pursuit_frequencies=pursuit_frequencies,
saccade_distance=saccade_distance,
saccade_time=saccade_time,
saccade_fixation_color=saccade_fixation_color,
saccade_fixation_color=convert_color_value(saccade_fixation_color),
isi_time=isi_time, stimulus_size=stimulus_size,
fixation_size=fixation_size,
pursuit_distance=pursuit_distance,
necker_time=necker_time, necker_color=necker_color,
necker_scale=necker_scale,
necker_bg_color=necker_bg_color,
necker_bg_color=convert_color_value(necker_bg_color),
fixation_trial_time=fixation_trial_time,
rivalry_time=rivalry_time,
rivalry_scale=rivalry_scale,
necker_file=necker_file,
rivalry_file1=rivalry_file1,
rivalry_file2=rivalry_file2,
rivalry_border_color=rivalry_border_color,
rivalry_border_color=convert_color_value(rivalry_border_color),
disableTracker=disableTracker,
rivalry_border_width=rivalry_border_width,
rivalry_distance=rivalry_distance,

BIN
__pycache__/SaccadePursuitEyeTracking.cpython-36.pyc

Binary file not shown.

20
template.py

@ -17,6 +17,7 @@ from __future__ import print_function @@ -17,6 +17,7 @@ from __future__ import print_function
import os
import pickle
import sys
import math
import psychopy.monitors
import psychopy.visual
@ -300,7 +301,8 @@ class BaseExperiment(object): @@ -300,7 +301,8 @@ class BaseExperiment(object):
colorSpace='rgb', units='deg', allowGUI=False, **kwargs)
def display_text_screen(
self, text='', text_color=[255, 255, 255], text_height=36,
self, text='', image_file=[], image_scale=0.25,
text_color=[255, 255, 255], text_height=36,
bg_color=None, wait_for_input=True, **kwargs):
"""Takes a string as input and draws it centered on the screen.
@ -333,6 +335,7 @@ class BaseExperiment(object): @@ -333,6 +335,7 @@ class BaseExperiment(object):
backgroundRect = psychopy.visual.Rect(
self.experiment_window, fillColor=bg_color, units='norm', width=2,
height=2)
backgroundRect.draw()
text_color = convert_color_value(text_color)
@ -340,13 +343,22 @@ class BaseExperiment(object): @@ -340,13 +343,22 @@ class BaseExperiment(object):
self.experiment_window, text=text, color=text_color, units='pix',
height=text_height, alignHoriz='center', alignVert='center',
wrapWidth=round(.8*self.experiment_window.size[0]), **kwargs)
backgroundRect.draw()
textObject.draw()
if image_file: # Display image immediately below text.
imageObject = psychopy.visual.ImageStim(
self.experiment_window, units='pix',
image=image_file)
sizex = int(round(imageObject.size[0])*image_scale)
sizey = int(round(imageObject.size[1])*image_scale)
belowText = int(math.floor(-textObject.boundingBox[1]/2-sizey/2))
imageObject.size = [sizex,sizey]
imageObject.pos = (0,belowText)
imageObject.draw()
self.experiment_window.flip()
keys = None
if wait_for_input:
psychopy.core.wait(.2) # Prevents accidental key presses
keys = psychopy.event.waitKeys()

Loading…
Cancel
Save