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):
"""Displays a break screen in between blocks. """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]) self.display_text_screen(text=break_text, bg_color=[0, 0, 0])
def display_fixation(self, wait_time, necker_bg_color=[-1,-1,-1]): def display_fixation(self, wait_time, necker_bg_color=[-1,-1,-1]):
@ -351,7 +351,7 @@ class SPtask(template.BaseExperiment):
responses.append((response[0],direction,psychopy.core.getAbsTime())) responses.append((response[0],direction,psychopy.core.getAbsTime()))
if tracker: if tracker:
#print(response[0]) #print(response[0])
tracker.send_message(['Direction: %s' % direction]) tracker.send_message(['Direction: %s, Key: %s' % (direction, response[0])])
stim.draw() stim.draw()
self.experiment_window.flip() self.experiment_window.flip()
#print(responses) #print(responses)

74
SaccadePursuitEyeTracking.py

@ -47,7 +47,7 @@ saccade_distance = 15 #15
saccade_time = 3 #3 saccade_time = 3 #3
stimulus_size = 0.3 stimulus_size = 0.3
stim_color = [1,-1,-1] stim_color = [1,-1,-1]
saccade_fixation_color = [.5,.5,.5] saccade_fixation_color = [191,191,191]
# Pursuit Parameters # Pursuit Parameters
number_of_pursuit_trials = 1 number_of_pursuit_trials = 1
@ -59,12 +59,12 @@ pursuit_time = [5,5,5] #[40,20,15]
# Necker Cube Parameters # Necker Cube Parameters
number_of_necker_trials = 1 number_of_necker_trials = 1
number_of_necker_blocks = 4 number_of_necker_blocks = 4
necker_time = 60 necker_time = 6
necker_color = [191,191,191] 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_scale = 0.5
necker_file = os.path.join(image_directory,'Necker1.tif') 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 # Fixation Parameters
number_of_fixation_trials = 1 number_of_fixation_trials = 1
@ -79,7 +79,7 @@ rivalry_time = 90
rivalry_scale = 2.5 rivalry_scale = 2.5
rivalry_file1 = os.path.join(image_directory,'house4n_11-160.tif') rivalry_file1 = os.path.join(image_directory,'house4n_11-160.tif')
rivalry_file2 = os.path.join(image_directory,'face2nS_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_border_width = 5
rivalry_distance = 4 rivalry_distance = 4
@ -110,7 +110,7 @@ instruct_text = [
'Do not move your head during the trials of this ' 'Do not move your head during the trials of this '
'experiment. Move only your eyes to follow the targets.' 'experiment. Move only your eyes to follow the targets.'
'You will get breaks in between blocks.\n\n' 'You will get breaks in between blocks.\n\n'
'Press space to continue.'), 'Press any key to continue.'),
] ]
saccade_instruct_text = ( saccade_instruct_text = (
@ -118,7 +118,7 @@ saccade_instruct_text = (
'appears, move your gaze to the target. Move your gaze back to ' 'appears, move your gaze to the target. Move your gaze back to '
'the fixation point after the target disappears.\n\n' 'the fixation point after the target disappears.\n\n'
'Try not to blink after the target appears.\n\n' 'Try not to blink after the target appears.\n\n'
'Press space to continue.' 'Press any key to continue.'
) )
antisaccade_instruct_text = ( antisaccade_instruct_text = (
@ -128,21 +128,21 @@ antisaccade_instruct_text = (
'the target. Move your gaze back to the fixation point after ' 'the target. Move your gaze back to the fixation point after '
'the target disappears.\n\n' 'the target disappears.\n\n'
'Try not to blink after the target appears.\n\n' 'Try not to blink after the target appears.\n\n'
'Press space to continue.' 'Press any key to continue.'
) )
pursuit_instruct_text = ( pursuit_instruct_text = (
'For these trials, when the circle target appears, follow the ' 'For these trials, when the circle target appears, follow the '
'target with your eyes.\n\n' 'target with your eyes.\n\n'
'Try not to blink while the circle is moving.\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 = ( fixation_instruct_text = (
'For these trials, when the cross appears, fixate on it.\n\n' 'For these trials, when the cross appears, fixate on it.\n\n'
'Try not to move your eyes from the cross while it ' 'Try not to move your eyes from the cross while it '
'remains visible.\n\n' 'remains visible.\n\n'
'Press space to continue.' 'Press any key to continue.'
) )
necker_instruct_text = ( necker_instruct_text = (
@ -152,7 +152,7 @@ necker_instruct_text = (
'switches to up and to the right, press the right ' 'switches to up and to the right, press the right '
'button.\n\n' 'button.\n\n'
'Respond at any time during the stimulus.\n\n' 'Respond at any time during the stimulus.\n\n'
'Press space to continue.' 'Press any key to continue.'
) )
rivalry_instruct_text = ( rivalry_instruct_text = (
@ -164,9 +164,17 @@ rivalry_instruct_text = (
'you perceive a combination of the face and house, ' 'you perceive a combination of the face and house, '
'press the middle button.\n\n' 'press the middle button.\n\n'
'Respond at any time during the stimuli.\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): class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -204,27 +212,6 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
subprocess.call(['edf2asc',fName]) subprocess.call(['edf2asc',fName])
super(EyeTrackingSaccadePursuit, self).quit_experiment() 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): def run(self):
self.chdir() self.chdir()
@ -282,12 +269,11 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
numBlocks = self.number_of_pursuit_blocks numBlocks = self.number_of_pursuit_blocks
numTrials = self.number_of_pursuit_trials numTrials = self.number_of_pursuit_trials
elif condition=='Necker': elif condition=='Necker':
#self.display_text_screen(text=necker_instruct_text) self.display_text_screen(text=necker_instruct_text, image_file=self.response_box_file)
self.display_necker_instructions(text=necker_instruct_text)
numBlocks = self.number_of_necker_blocks numBlocks = self.number_of_necker_blocks
numTrials = self.number_of_necker_trials numTrials = self.number_of_necker_trials
elif condition=='Rivalry': 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 numBlocks = self.number_of_rivalry_blocks
numTrials = self.number_of_rivalry_trials numTrials = self.number_of_rivalry_trials
else: else:
@ -339,8 +325,16 @@ class EyeTrackingSaccadePursuit(SaccadePursuit.SPtask):
self.display_text_screen(text='Remember:\n\n' + saccade_instruct_text) self.display_text_screen(text='Remember:\n\n' + saccade_instruct_text)
elif condition=='AntiSaccade': elif condition=='AntiSaccade':
self.display_text_screen(text='Remember:\n\n' + antisaccade_instruct_text) 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) 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( self.display_text_screen(
'The experiment is now over.', 'The experiment is now over.',
@ -366,20 +360,20 @@ experiment = EyeTrackingSaccadePursuit(
pursuit_frequencies=pursuit_frequencies, pursuit_frequencies=pursuit_frequencies,
saccade_distance=saccade_distance, saccade_distance=saccade_distance,
saccade_time=saccade_time, 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, isi_time=isi_time, stimulus_size=stimulus_size,
fixation_size=fixation_size, fixation_size=fixation_size,
pursuit_distance=pursuit_distance, pursuit_distance=pursuit_distance,
necker_time=necker_time, necker_color=necker_color, necker_time=necker_time, necker_color=necker_color,
necker_scale=necker_scale, 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, fixation_trial_time=fixation_trial_time,
rivalry_time=rivalry_time, rivalry_time=rivalry_time,
rivalry_scale=rivalry_scale, rivalry_scale=rivalry_scale,
necker_file=necker_file, necker_file=necker_file,
rivalry_file1=rivalry_file1, rivalry_file1=rivalry_file1,
rivalry_file2=rivalry_file2, rivalry_file2=rivalry_file2,
rivalry_border_color=rivalry_border_color, rivalry_border_color=convert_color_value(rivalry_border_color),
disableTracker=disableTracker, disableTracker=disableTracker,
rivalry_border_width=rivalry_border_width, rivalry_border_width=rivalry_border_width,
rivalry_distance=rivalry_distance, 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
import os import os
import pickle import pickle
import sys import sys
import math
import psychopy.monitors import psychopy.monitors
import psychopy.visual import psychopy.visual
@ -300,7 +301,8 @@ class BaseExperiment(object):
colorSpace='rgb', units='deg', allowGUI=False, **kwargs) colorSpace='rgb', units='deg', allowGUI=False, **kwargs)
def display_text_screen( 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): bg_color=None, wait_for_input=True, **kwargs):
"""Takes a string as input and draws it centered on the screen. """Takes a string as input and draws it centered on the screen.
@ -333,6 +335,7 @@ class BaseExperiment(object):
backgroundRect = psychopy.visual.Rect( backgroundRect = psychopy.visual.Rect(
self.experiment_window, fillColor=bg_color, units='norm', width=2, self.experiment_window, fillColor=bg_color, units='norm', width=2,
height=2) height=2)
backgroundRect.draw()
text_color = convert_color_value(text_color) text_color = convert_color_value(text_color)
@ -340,13 +343,22 @@ class BaseExperiment(object):
self.experiment_window, text=text, color=text_color, units='pix', self.experiment_window, text=text, color=text_color, units='pix',
height=text_height, alignHoriz='center', alignVert='center', height=text_height, alignHoriz='center', alignVert='center',
wrapWidth=round(.8*self.experiment_window.size[0]), **kwargs) wrapWidth=round(.8*self.experiment_window.size[0]), **kwargs)
backgroundRect.draw()
textObject.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() self.experiment_window.flip()
keys = None keys = None
if wait_for_input: if wait_for_input:
psychopy.core.wait(.2) # Prevents accidental key presses psychopy.core.wait(.2) # Prevents accidental key presses
keys = psychopy.event.waitKeys() keys = psychopy.event.waitKeys()

Loading…
Cancel
Save