Frame rate functions in python -


i hoping on piece of python code i've been working on. i'm trying assess frame rate during task on stimulus presentation software python-based. here's have :

frame1 = 0.0152 frame2 = visual.getmsperframe(win, nframes = 60, showvisual=false, msg='', msdelay=0.0) frame3 = frame2 - frame1 

the problem i'm having "frame2" yields set of numbers. specifically, yield average, median, , standard deviation. because of this, "frame3" crash. there anyway pull out average value out of getmsperframe() output "frame3" run?

i'm pretty new programming i'm not familiar stuff.

it looks using psychopy module, whihc according it's source code shows getmsperframe() returns:

return mspfavg, mspfstd, mspfmed #, msdrawavg, msdrawsd, msfree 

the hash sign (#) comment in python means returned values tuple. can access desired value same way wold if return value array so:

>>> print(getmsperframe()) (123, 90, 154) >>> print(getmsperframe()[0]) 123 

as can see rather bad design because requires reading of source code understand meaning of number after. i'm leaving original answer in case find in similar situation in future.


if visual.getmsperframe() returned dict this:

>>> print(frame2) {'max': 154, 'avg': 123, 'min': 90} 

then can access part of name this:

>>> print(frame['avg']) 123 

if returned array this:

>>> print(frame2) [154, 123, 90] 

then have know element avg. assuming 2nd (arrays 0 indexed):

>>> print(frame[1]) 123 

if returned array of dicts this:

>>> print(frame2) [{'max': 154}, {'avg': 123}, {'min': 90}] 

you use list comprehension this:

>>> print([item['avg'] item in frame2 if item.keys()[0] == 'avg'][0]) 123 

(ok getting kind of silly, please post output of print(frames2)) ok 1 more (i having lot of fun learning python these days) how list of tuples this:

>>> print(frame2) [('max', 154), ('avg', 123), ('min', 90)] 

here list comprehension little easier follow:

>>> print([value key, value in frame2 if key=='avg'][0]) 123 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -