[visionegg] visual attention task

Hi,

I'm a visionegg newby.

Please find attached a work in progress.  It will present a sequence
of stimuli for a visual attention task.  However, I do not understand
how to specify different stimulus durations for different stimuli in
the sequence.  Also, I want to offset the location of the stimuli to
the left and right of the visual field - how do I do that?  I wonder
if the object model and timing control for this task will work with
the texture_list contruct.  Please have a look at this script and
advise me on how to change it.

I hope the visionegg will prove useful for this task.  I think it is
already useful for randomization of stimulus presentation, but I want
to learn more about how to control stimulus screen location and
timing.

Thanks, Darren
#!/usr/bin/env python
"""Display a sequence of images.

The displayed image changes by changing the TextureStimulus's
Texture parameter, which will delete the old OpenGL texture object and
create a new one.

This method to switch images is slower than that demonstrated in the
image_sequence_fast.py demo.

The images need not all be the same size.
"""

from VisionEgg import *
start_default_logging(); watch_exceptions()

from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation, FunctionController
from VisionEgg.Textures import *

import Image, ImageDraw
import OpenGL.GL as gl

import random

# ---------------------------------------------------
# image files
image_path = 
'E:\\psychophysics\\PTSDnovelty\\ucb_stimuli\\Presentation\\Images\\'

buddists = image_path + 'Buddists.bmp'
canoe    = image_path + 'Canoe.bmp'
cg_fctry = image_path + 'Cg_fctry.bmp'
chndes   = image_path + 'Chndes.bmp'
chocoice = image_path + 'Chocoice.bmp'
cow      = image_path + 'Cow.bmp'
crabrd   = image_path + 'Crabrd.bmp'
cruiser1 = image_path + 'Cruiser1.bmp'
cstlevgl = image_path + 'Cstlevgl.bmp'
deathead = image_path + 'Deathead.bmp'
doc_angl = image_path + 'Doc_angl.bmp'
festivl3 = image_path + 'Festivl3.bmp'
flower8  = image_path + 'Flower8.bmp'
ftball3  = image_path + 'Ftball3.bmp'
horse2   = image_path + 'Horse2.bmp'
jumpwing = image_path + 'Jumpwing.bmp'
lily     = image_path + 'Lily.bmp'
location = image_path + 'Location.bmp'
mltrspch = image_path + 'Mltrspch.bmp'
mntcfog  = image_path + 'Mntcfog.bmp'
mouse    = image_path + 'Mouse.bmp'
penguin  = image_path + 'Penguin.bmp'
wmntenis = image_path + 'Wmntenis.bmp'
womanbl  = image_path + 'Womanbl.bmp'

standard = image_path + 'standard.bmp'
target   = image_path + 'target.bmp'

fixationCross = image_path + 'Cross.bmp'

cueLeft  = image_path + 'lt_arrw.bmp'
cueRight = image_path + 'rt_arrw.bmp'

novelList = [ buddists, canoe, cg_fctry, chndes, chocoice, cow, crabrd,
               cruiser1, cstlevgl, deathead, doc_angl, festivl3, flower8,
               ftball3, horse2, jumpwing, lily, location, mltrspch, mntcfog,
               mouse, penguin, wmntenis, womanbl ]


# Task parameters
number_images = 100
percent_standard = 0.6
percent_target = 0.2
percent_novel =  0.2

number_standard = int(number_images * percent_standard)
number_target = int(number_images * percent_target)
number_novel = int(number_images * percent_novel)

# stimulus duration (seconds)
image_duration = 0.4

fixation_duration = 0.4
standard_duration = 0.1
target_duration = 0.1
novel_duration = 0.1

image_size = (256,256)




# -----------------------------------------------
# Generate the task image sequence


imageList = []
sequence_duration = 0 # seconds

sequence_duration = sequence_duration + (number_standard * standard_duration)
for i in range(number_standard):
    image = Image.open(standard, mode='r')
    imageList.append(image)

sequence_duration = sequence_duration + (number_target * target_duration)
for i in range(number_target):
    image = Image.open(target, mode='r')
    imageList.append(image)

# use a random selection of the novelList here
sequence_duration = sequence_duration + (number_novel * novel_duration)
novelRandList = random.sample(novelList, number_novel)
for fp in novelRandList:
    image = Image.open(fp, mode='r')
    imageList.append(image)


# Now create a random sequence of imageList
imageN = len(imageList)
imageList = random.sample(imageList, imageN)

# Nowinsert the fixation crosses
sequence_duration = sequence_duration + (imageN * fixation_duration)
i = 0
while i < ( imageN * 2 ):
    j = random.choice([cueLeft,cueRight])
    image = Image.open(j, mode='r')
    imageList.insert(i,image)
    i = i + 2

imageN = len(imageList)
texture_list = map(Texture,imageList) # create instances of Texture from images

# Image.rotate(self, angle, resample=0)
#    Rotate image.  Angle given as degrees counter-clockwise.
# Image.open(fp, mode='r')
#    Open an image file, without loading the raster data
# Image.show(self, title=None, command=None)
#    Display image (for debug purposes only)
# Image.resize(self, size, resample=0)
#    Resize image
# Image.load(self)
#    Explicitly load pixel data.




# -----------------------------------------
# Run the task

screen = get_default_screen()

# How do we randomly allocate stimuli to left/right side of screen?

stimulus = TextureStimulus(texture=texture_list[0],
                           position = (screen.size[0]/2.0,screen.size[1]/2.0),
                           anchor='center')


# How do we make the screen background black, instead of gray?


viewport = Viewport(screen=screen,
                    stimuli=[stimulus])

sequence_duration = imageN * 0.4
p = Presentation(go_duration=(sequence_duration,'seconds'),viewports=[viewport])

def put_image(t):
    i = int(t/image_duration) # choose image
    stimulus.parameters.texture = texture_list[i]

p.add_controller(None,None,FunctionController(during_go_func=put_image))

p.go()


#
#
#
##Visual Orientation (October 2001); fMRI study.
#
#scenario = "block1";
#scenario_type = fMRI_emulation;
#scan_period = 2000;
#
#active_buttons = 1;
#button_codes = 1;
#target_button_codes = 11;
#
#screen_width = 800;
#screen_height = 600;
#screen_bit_depth = 16;
#
#pulses_per_scan = 1;
#pulse_code = 21;
#
#default_picture_duration = 107;
#default_background_color = 0, 0, 0;   # black
#default_font_size = 40 ;
#default_font = "Arial";
#default_text_color = 138, 171, 247;   #blue
#
##define variables
#$w = 265;
#$h = 189;
#
#begin ;
#
#picture {
#bitmap { filename = "Cross.bmp"; } Cross ;
#x = 0;
#y = 0;} 
#default;
#
#bitmap { filename = "Buddists.bmp"; width = $w; height = $h;  } buddists;
#bitmap { filename = "Canoe.bmp"; width = $w; height = $h; } canoe; 
#bitmap { filename = "Cg_fctry.bmp"; width = $w; height = $h;  } cg_fctry;
#bitmap { filename = "Chndes.bmp"; width = $w; height = $h;  } chndes;
#bitmap { filename = "Chocoice.bmp"; width = $w; height = $h;  } chocoice;
#bitmap { filename = "Cow.bmp"; width = $w; height = $h; } cow;
#bitmap { filename = "Crabrd.bmp"; width = $w; height = $h;  } crabrd;
#bitmap { filename = "Cruiser1.bmp"; width = $w; height = $h;  } cruiser1;
#bitmap { filename = "Cstlevgl.bmp"; width = $w; height = $h;  } cstlevgl;
#bitmap { filename = "Deathead.bmp"; width = $w; height = $h;  } deathead;
#bitmap { filename = "Doc_angl.bmp"; width = $w; height = $h;  } doc_angl; 
#bitmap { filename = "Festivl3.bmp"; width = $w; height = $h;  } festivl3;
#bitmap { filename = "Flower8.bmp"; width = $w; height = $h;  } flower8;
#bitmap { filename = "Ftball3.bmp"; width = $w; height = $h;  } ftball3;
#bitmap { filename = "Horse2.bmp"; width = $w; height = $h;  } horse2;
#bitmap { filename = "Jumpwing.bmp"; width = $w; height = $h; } jumpwing;
#bitmap { filename = "Lily.bmp"; width = $w; height = $h; } lily;
#bitmap { filename = "Location.bmp"; width = $w; height = $h; } location;
#bitmap { filename = "Mltrspch.bmp"; width = $w; height = $h; } mltrspch;
#bitmap { filename = "Mntcfog.bmp"; width = $w; height = $h;  } mntcfog;
#bitmap { filename = "Mouse.bmp"; width = $w; height = $h; } mouse;
#bitmap { filename = "Penguin.bmp"; width = $w; height = $h; } penguin;
#bitmap { filename = "Wmntenis.bmp"; width = $w; height = $h;  } wmntenis;
#bitmap { filename = "Womanbl.bmp"; width = $w; height = $h; } womanbl;
#bitmap { filename = "standard.bmp"; width = $w; height = $h; } standard;
#bitmap { filename = "target.bmp"; width = $w; height = $h;  } target;
#
#trial {
#
##picture { text { caption = "Experiment begins in 10 seconds... ";};
##x = 0;
##y = 0;
##};
##duration = 4000;
#
#picture { text { caption = "Attend to the RIGHT";};
#x = 0;
#y = 0;
#};
#mri_pulse = 1;
#time = 0;
#duration = 4000;
#
#picture default;
#mri_pulse = 3;
#time = 0;
#duration = 1000;
#
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           5;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#mntcfog        360     -233    left            7;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       160     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#cow          310       233     right           10;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       128     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       118     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            11;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           14;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#deathead       360     -233    left            16;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       120     233     right   707     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#standard       160     -233    left    307     ;
#standard       180     -233    left    1107    ;
#standard       130     233     right   1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#location       310     233     right           19;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            20;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       180     -233    left    1107    ;
#standard       170     -233    left    707     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#flower8        310     233     right           22;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       170     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            24;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           25;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#doc_angl       360     -233    left            28;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       130     233     right   1107    ;
#};
#
#picture { text { caption = "Attend to the LEFT";};
#x = 0;
#y = 0;
#};
#mri_pulse = 30;
#time = 0;
#duration = 4000;
#
#picture default;
#mri_pulse = 32;
#time = 0;
#duration = 1000;
#
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           34;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#buddists       360     -233    left            36;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       160     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#canoe        310       233     right           39;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       128     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       118     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            40;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           43;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#cg_fctry       360     -233    left            45;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       120     233     right   707     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#standard       160     -233    left    307     ;
#standard       180     -233    left    1107    ;
#standard       130     233     right   1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#chndes 310     233     right           48;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       120     233     right   707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            49;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       180     -233    left    1107    ;
#standard       170     -233    left    707     ;
#standard       160     -233    left    307     ;
#standard       130     233     right   1107    ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#crabrd 310     233     right           51;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#standard       110     233     right   307     ;
#standard       170     -233    left    707     ;
#standard       170     -233    left    707     ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 260     -233    left            53;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       170     -233    left    707     ;
#standard       110     233     right   307     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#target 210     233     right           54;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       130     233     right   1107    ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       130     233     right   1107    ;
#standard       170     -233    left    707     ;
#standard       180     -233    left    1107    ;
#};
#
#TEMPLATE "template2.tem" { 
#stim           ecode   xpos    vfield  mri_n;
#festivl3       360     -233    left            57;
#};
#
#TEMPLATE "template.tem" {
#stim        ecode      xpos vfield     SOA     ;
#standard       130     233     right   1107    ;
#standard       160     -233    left    307     ;
#standard       110     233     right   307     ;
#standard       160     -233    left    307     ;
#standard       170     -233    left    707     ;
#standard       130     233     right   1107    ;
#};
#
#picture { text { caption = "RELAX...";};
#x = 0;
#y = 0;
#};
#deltat = 3000;
#duration = response;
#};

Other related posts: