[visionegg] goodbye

  • From: Christoph Lehmann <lehmann@xxxxxxxxxxxx>
  • To: visionegg@xxxxxxxxxxxxx
  • Date: Fri, 09 May 2003 13:02:34 +0200

it seems to be a problem only if we have many stimuli (in my case: 120
stimuli give a problem, 80 are more or less o.k.) AND the process in
max_priority-mode runs for quite a long time (with 120stimui: 480s). If
I present each stimulus for 0.4s instead of 4s, I don't face serious
problems:

which linux processes do interfere with visionegg, even in max_priority
mode, resulting in an extensive hard-disk use and therefore yielding
breaks of up to 15!! seconds?

Thanks, I quit herewith and give you my code in the attachment. I don't
continue to look into this problem, since I have no idea, where the bug
is. Maybe someone can run it under windows and test, whether we get the
same problems there. And: are mouse-events in windows also not available
when running in max_priority mode?

Many thanks

Christoph



On Fri, 2003-05-09 at 10:37, Christoph Lehmann wrote: 
> now, with the corrected way, texture-stimuli are preloaded into
> video-RAM, even running in max_priority mode gives breaks of in one, two
> cases more than 4 seconds!! During this time I hear my hard-disk
> working....
> 
> so why? so what?
> c


-- 

Christoph Lehmann <lehmann@xxxxxxxxxxxx>

University Hospital of Clinical Psychiatry
#!/usr/bin/env python

#This bypasses the VisionEgg.Core.Presentation class.  It may be easier
#to create simple experiments this way."""

import VisionEgg
from VisionEgg.Core import *
import pygame
from pygame.locals import *
from VisionEgg.Text import *
from math import *
from operator import mod
from operator import div
from random import *
import VisionEgg.Daq
from VisionEgg.DaqLPT import *
from VisionEgg.Textures import *

screen = get_default_screen()
screen.parameters.bgcolor = (0.0,0.0,0.0,0.0) # black (RGBA)

path = 
"/home/christoph/work/programming/my_ve_projects/load_picture/data_orig/" #the 
path the images are in
fixation = 
"/home/christoph/work/programming/my_ve_projects/load_picture/fixation_stimuli/fixation02.bmp"

photo = []
photoX = []

# present them in random order
for filename in os.listdir(path):
    photo.append(filename)
length = len(photo)
for stim_index in range(0, length):
    ran = randint(0, len(photo)-1)
    file = photo[ran]
    photoX.append(file)
    photo.pop(ran)

# Insert a fixation cross in front of the texture list
photoX.insert(0,fixation)
os.chdir(path)

num_images = len(photoX)
ratio = 4 #4 volumes equal one trial (one TR fixtion, 3 TRs stimulus)

# Create list of stimuli

preloaded_stimulus_list = [] # empty at first
for stim_index in range(num_images):
    # Read the texture file
    texture = Texture(photoX[stim_index])

    # Add to list of TEXTURES
    x = screen.size[0]/2 - texture.size[0]/2
    y = screen.size[1]/2 - texture.size[1]/2

    # Load the texture to OpenGL, prepare for display
    stimulus = TextureStimulus(texture = texture,
                               size = texture.size,
                               lowerleft=(x,y))
  
    # Add to list of stimuli
    preloaded_stimulus_list.append( stimulus )

viewport = Viewport( screen=screen)

# The main loop below is an alternative to using the
# VisionEgg.Core.Presentation class.

trial_log_list = []
trial_log = []
response_log_list = []
response_log = []        
  
swap_time = 0
stim_index = 0
trial_index = 0
trial_onset = 0 #the time, a stimulus is drawn (not fixation)
trigger_onset = 0 #the time, a trigger has been detected on the lpt
start_time = -1
trigger_counter = -1
loop_ctr = 0 #to check, whether the outer while loop is entered the first time 
(log start_time)
trigger_armed = 1
 
timestamp = [] #for time loggging only
looptime = 0 #for time loggging only
last_time = VisionEgg.time_func()


my_debug_msg = []
just_swapped = 1

while (not pygame.event.peek((QUIT,KEYDOWN))):
    # wait for mouse response and trigger on the parallel port
    while (not pygame.event.peek((QUIT,KEYDOWN))):
        # only during developing check timing accuracy
        actualtime = VisionEgg.time_func()
        looptime = (actualtime - last_time)*1000 #log in ms
        last_time = actualtime
        timestamp.append(looptime)
        
        if (looptime > 20) and (just_swapped):
            my_debug_msg.append('-S<' + str(looptime) + '> <' + 
photoX[stim_index] + '>' ) 
        elif  (looptime > 20) and (not just_swapped):
            my_debug_msg.append(' !<' + str(looptime) + '> <' + 
photoX[stim_index] + '>' ) 
        just_swapped = 0

        #log the mouse response (which button, and RT)
        for event in pygame.event.get(pygame.locals.MOUSEBUTTONDOWN): 
            if event.button == 1:
                response_log.append(VisionEgg.time_func() - trial_onset)
                response_log.append('L') #left
            elif event.button == 3:
                response_log.append(VisionEgg.time_func() - trial_onset)
                response_log.append('R') #right
        # poll the LPT for the TTL trigger, sent by the MR scanner
        if trigger_counter == 3:
            trigger_counter = -1 #reset ctr, since 4 volumes equal one trial 
(one TR fixtion, 3 TRs stimulus)
        input_value = raw_lpt_module.inp(0x379) & 0x20        # pin nr 12
        # if TTL signal on lpt, increment the index for the texture-list
        if input_value == 0x20 and trigger_armed == 1: 
            trigger_counter = trigger_counter + 1
            trigger_armed = 0 #don't increment the texture-index, until a new 
trigger puls is received (TTL pulse ca. 50ms)
            if mod(trigger_counter,ratio) == 0: #0: draw fixation
                trial_index = trial_index + 1 #after the drawn fixation cross, 
the next swap will draw a new stimulus
                stim_index = 0
                break #leave the loop and update the screen, drawing a fixation 
cross (begin of a new trial-compound)
            if mod(trigger_counter,ratio) == 1: #1: draw stimulus
                stim_index = trial_index #has been incremented during the 
previous fixation loop
                break #leave the loop and update the screen with the new 
stimulus
        elif input_value == 0 and trigger_armed == 0:  #first lpt poll-loop 
after the TTL signal has fallen from 1 to 0 (-> arm trigger)
            trigger_armed = 1

    # quit if all stimuli shown
    if trial_index == num_images:
        response_log_list.append(response_log) #append last response log and 
quit
        break
 

    # draw the stimulus (during first loop: fixation)
    #stimulus.parameters.texture = preloaded_texture_list[stim_index]

    screen.clear()
    #beforetime = VisionEgg.time_func()  
    viewport.parameters.stimuli = [preloaded_stimulus_list[stim_index]] #the 
outer '[' and ']' are very important
    viewport.draw()
    #my_debug_msg.append('--<' + str(1000*(VisionEgg.time_func() - 
beforetime))+ '> <' + photoX[stim_index]+ '>' ) 
    swap_buffers()
    swap_time = VisionEgg.time_func()

  
    if loop_ctr == 0: #first fixation shown
        start_time = swap_time

    just_swapped = 1

    # logging
    if stim_index > 0: 
        # log the stimulus with onset-time info
        trial_onset = swap_time #confusing: trial_onset is the time the 
stimulus is drawn 
        trial_log = (stim_index, trial_onset - start_time, photoX[stim_index]) 
#create next new log
        trial_log_list.append(trial_log) #append last log
        # log the mouse-response info
        if loop_ctr > 0: #1st loop: fixation; only after the first stimulus, 
response makes sense
            response_log_list.append(response_log) #append last response log 
(since we want only one response log per trial
        response_log = [] #clear response_log
        response_log.append(stim_index)
        response_log.append(photoX[stim_index])      

    loop_ctr = loop_ctr + 1

#end of the main loop


# write all log info to several files
# create a histogramm of the loop-repeats in ms
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t5 = 0
t6 = 0
t8 = 0
t10 = 0
t20 = 0
t30 = 0
t40 = 0
t50 = 0
t60 = 0
t80 = 0
t100 = 0
t200 = 0
t400 = 0
t600 = 0
t800 = 0
t1000 = 0
t2000 = 0
t3000 = 0
t4000 = 0
t5000 = 0
t6000 = 0
t7000 = 0
t8000 = 0
t9000 = 0
t10000 = 0
t11000 = 0
t12000 = 0
t13000 = 0
t14000 = 0
t15000 = 0
t16000 = 0
t17000 = 0
t18000 = 0
t19000 = 0
t20000 = 0
t30000 = 0
t40000 = 0
t50000 = 0
t100000 = 0
tt = 0

for x in timestamp: #all in ms (milliseconds!)
    if x <= 1:
        t1 = t1 + 1
    elif x <= 2:
        t2 = t2 + 1
    elif x <= 3:
        t3 = t3 + 1
    elif x <= 4:
        t4 = t4 + 1
    elif x <= 5:
        t5 = t5 + 1
    elif x <= 6:
        t6 = t6 + 1
    elif x <= 8:
        t8 = t8 + 1
    elif x <= 10:
        t10 = t10 + 1
    elif x <= 20:
        t20 = t20 + 1
    elif x <= 30:
        t30 = t30 + 1
    elif x <= 40:
        t40 = t40 + 1
    elif x <= 50:
        t50 = t50 + 1
    elif x <= 60:
        t60 = t60 + 1
    elif x <= 80:
        t80 = t80 + 1
    elif x <= 100:
        t100 = t100 + 1
    elif x <= 200:
        t200 = t200 + 1
    elif x <= 400:
        t400 = t400 + 1
    elif x <= 600:
        t600 = t600 + 1
    elif x <= 800:
        t800 = t800 + 1
    elif x <= 1000:
        t1000 = t1000 + 1
    elif x <= 2000:
        t2000 <= 2000
    elif x <= 3000:
        t3000 = t3000 + 1
    elif x <= 4000:
        t4000 = t4000 + 1
    elif x <= 5000:
        t5000 = t5000 + 1
    else:
        tt = tt + 1



f=open('/home/christoph/work/programming/my_ve_projects/load_picture/timing.txt',
 'w')
f.write('______ all times in ms ____________' + '\n')
f.write("<= 0.001: %d    " % t1)
f.write('\n')
f.write("<= 0.002: %d    " % t2)
f.write('\n')
f.write("<= 0.003: %d    " % t3)
f.write('\n')
f.write("<= 0.004: %d    " % t4)
f.write('\n')
f.write("<= 0.005: %d    " % t5)
f.write('\n')
f.write("<= 0.006: %d    " % t6)
f.write('\n')
f.write("<= 0.008: %d    " % t8)
f.write('\n')
f.write("<= 0.010: %d    " % t10)
f.write('\n')
f.write("<= 0.020: %d    " % t20)
f.write('\n')
f.write("<= 0.030: %d    " % t30)
f.write('\n')
f.write("<= 0.040: %d    " % t40)
f.write('\n')
f.write("<= 0.050: %d    " % t50)
f.write('\n')
f.write("<= 0.060: %d    " % t60)
f.write('\n')
f.write("<= 0.080: %d    " % t80)
f.write('\n')
f.write("<= 0.1: %d    " % t100)
f.write('\n')
f.write("<= 0.2: %d    " % t200)
f.write('\n')
f.write("<= 0.4: %d    " % t400)
f.write('\n')
f.write("<= 0.6: %d    " % t600)
f.write('\n')
f.write("<= 0.8: %d    " % t800)
f.write('\n')
f.write("<= 1: %d    " % t1000)
f.write('\n')
f.write("<= 2: %d    " % t2000)
f.write('\n')
f.write("<= 3: %d    " % t3000)
f.write('\n')
f.write("<= 4: %d    " % t4000)
f.write('\n')
f.write("<= 5: %d    " % t5000)
f.write('\n')
f.write("> 5: %d    " % tt)
f.write('___________________________________' + '\n')
f.close()


f=open('/home/christoph/work/programming/my_ve_projects/load_picture/trial_log_file.txt',
 'w')
f.write('trial   onset_t         stim' + '\n')
f.write('______________________________' + '\n')

x = 0
while x < len(trial_log_list):
    y = 0
    while y < len(trial_log_list[x]):
        if (type(trial_log_list[x][y]) == types.FloatType):
            if y == 0:
                 f.write("%04.0f    " % trial_log_list[x][y])           #trial 
index
            elif y == 1:                                           # y = 0: 
onset_time of the stimulus             
                f.write("    %010.2f    " % (trial_log_list[x][y] * 1000)) 
#onset time of the stimulus
            else:
                f.write("%010.2f    " % (trial_log_list[x][y] * 1000)) #RT
        else:
            f.write(str(trial_log_list[x][y]) + "  ")                  #mouse 
response (left/right)
        y = y + 1
    f.write('\n')
    x = x + 1
f.write('______________________________' + '\n')
f.write('Remarks:' + '\n')
f.write('(i) onset_t: time of the stimulus onset relative to the first volume 
of the scanner' + '\n')
f.close()


f=open('/home/christoph/work/programming/my_ve_projects/load_picture/response_log_file.txt',
 'w')
f.write('trial   stim          RT  button (L/R)' + '\n')
f.write('___________________________________________________________________________________'
 + '\n')

x = 0
while x < len(response_log_list):
    y = 0
    while y < len(response_log_list[x]):
        if (type(response_log_list[x][y]) == types.FloatType):
           if (y == 0):
                f.write("%04.0f    " % response_log_list[x][y])          #trial 
index
           else:
                f.write("    %010.2f    " % (response_log_list[x][y] * 1000)) 
#RT
        else:
            f.write(str(response_log_list[x][y]) + "  ")                  
#mouse response (left/right)
        y = y + 1
    f.write('\n')
    x = x + 1
f.write('___________________________________________________________________________________'
 + '\n')
f.write('Remarks:' + '\n')
f.write('(i) RT: reaction-time of the subject, measured relative to the 
corresponding stimulus onset' + '\n')
f.close()


f=open('/home/christoph/work/programming/my_ve_projects/load_picture/my_debug_msg.txt',
 'w')
f.write('_______________________________________________________' + '\n')
for x in my_debug_msg:
    if (type(x) == types.FloatType):
        f.write("%010.2f    " % x)
    else:
        f.write(str(x) + "  ")   
    f.write('\n')
f.write('_______________________________________________________' + '\n')
f.close()

Attachment: 755_0.bmp
Description: Windows bitmap

Attachment: fixation02.bmp
Description: PNG image

Other related posts:

  • » [visionegg] goodbye