Beispiel #1
0
Any method of the numpy.array class can be called by a NumPyRingBuffer instance,
however numpy.array module funtions will not accept a NumPyRingBuffer as input.

@author: Sol
"""
from psychopy.iohub.util import NumPyRingBuffer

# Create a ring buffer with a maximum size of 10 elements. AS more than 10 elements
#   are added using append(x), each new element removed the oldeest element in
#   the buffer. The default data type is numpy.float32. To change the type to a
#   different numpy scalar value (for example numpy.uint, numpy ubyte, etc),
#   use the dtype parameter of NumPyRingBuffer.
ring_buffer = NumPyRingBuffer(10)

# Add 25 values to the ring buffer, between 1 and 25 inclusive.
# Print out info about the ring buffer and ring buffer contents state
#   after each element is added.
#
for i in xrange(1, 26):
    ring_buffer.append(i)
    print '-------'
    print 'Ring Buffer Stats:'
    print '\tWindow size: ', len(ring_buffer)
    print '\tMin Value: ', ring_buffer.min()
    print '\tMax Value: ', ring_buffer.max()
    print '\tMean Value: ', ring_buffer.mean()
    print '\tStandard Deviation: ', ring_buffer.std()
    print '\tFirst 3 Elements: ', ring_buffer[:3]
    print '\tLast 3 Elements: ', ring_buffer[-3:]
Beispiel #2
0
 stim2_type=stim2.__class__.__name__+u' '
 while True:
     # For the textBox and TextStim resource, change the text every
     # chng_txt_each_flips, and record the time it takes to update the text
     # and redraw() each resource type.
     #
 
     # Make sure timing of stim is for the time taken for that stim alone. ;)
     gl.glFlush()
     gl.glFinish()
 
     if fcount==0 or fcount%chng_txt_each_flips==0:
         t=getRandomString(text_length)
         
         stim1_dur=updateStimText(stim1,stim1_type+t)
         stim1_txt_change_draw_times.append(stim1_dur)
         t=getRandomString(text_length)
         stim2_dur=updateStimText(stim2,stim2_type+t)
         stim2_txt_change_draw_times.append(stim2_dur)
     else:
         stim1_dur=updateStimText(stim1)
         stim1_no_change_draw_times.append(stim1_dur)
         stim2_dur=updateStimText(stim2)
         stim2_no_change_draw_times.append(stim2_dur)
         
     # Update the display to show stim changes
     flip_time=window.flip()
     fcount+=1
 
     # End the test when a keyboard event is detected or when max_flip_count
     # win.flip() calls have been made.
 stim2_type=stim2.__class__.__name__+u' '
 while True:
     # For the textBox and TextStim resource, change the text every
     # chng_txt_each_flips, and record the time it takes to update the text
     # and redraw() each resource type.
     #
 
     # Make sure timing of stim is for the time taken for that stim alone. ;)
     gl.glFlush()
     gl.glFinish()
 
     if fcount==0 or fcount%chng_txt_each_flips==0:
         t=getRandomString(text_length)
         
         stim1_dur=updateStimText(stim1,stim1_type+t)
         stim1_txt_change_draw_times.append(stim1_dur)
         t=getRandomString(text_length)
         stim2_dur=updateStimText(stim2,stim2_type+t)
         stim2_txt_change_draw_times.append(stim2_dur)
     else:
         stim1_dur=updateStimText(stim1)
         stim1_no_change_draw_times.append(stim1_dur)
         stim2_dur=updateStimText(stim2)
         stim2_no_change_draw_times.append(stim2_dur)
         
     # Update the display to show stim changes
     flip_time=window.flip()
     fcount+=1
 
     # End the test when a keyboard event is detected or when max_flip_count
     # win.flip() calls have been made.
Values can be appended to the ring buffer and accessed using slice notation.

Any method of the numpy.array class can be called by a NumPyRingBuffer instance,
however numpy.array module funtions will not accept a NumPyRingBuffer as input.

@author: Sol
"""
from psychopy.iohub.util import NumPyRingBuffer

# Create a ring buffer with a maximum size of 10 elements. AS more than 10 elements
#   are added using append(x), each new element removed the oldeest element in
#   the buffer. The default data type is numpy.float32. To change the type to a
#   different numpy scalar value (for example numpy.uint, numpy ubyte, etc), 
#   use the dtype parameter of NumPyRingBuffer.   
ring_buffer=NumPyRingBuffer(10)

# Add 25 values to the ring buffer, between 1 and 25 inclusive.
# Print out info about the ring buffer and ring buffer contents state 
#   after each element is added.
#
for i in xrange(1,26):
    ring_buffer.append(i)
    print '-------'
    print 'Ring Buffer Stats:'
    print '\tWindow size: ',len(ring_buffer)
    print '\tMin Value: ',ring_buffer.min()
    print '\tMax Value: ',ring_buffer.max()
    print '\tMean Value: ',ring_buffer.mean()
    print '\tStandard Deviation: ',ring_buffer.std()
    print '\tFirst 3 Elements: ',ring_buffer[:3]
    print '\tLast 3 Elements: ',ring_buffer[-3:]