Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
development:realtime:buffer_python [2018/10/21 15:11]
42.49.180.224 [FieldTrip buffer Python interface]
development:realtime:buffer_python [2017/08/17 11:21] (current)
127.0.0.1 external edit
Line 3: Line 3:
 ====== FieldTrip buffer Python interface ====== ====== FieldTrip buffer Python interface ======
  
-====== ​FieldTrip ​buffer Python interface ======+===== Client side pure Python implementation ​===== 
 + 
 +The directory ''​fieldtrip/​realtime/​src/​buffer/​python''​ contains a single-file ​Python ​module called ''​FieldTrip.py''​. This provides classes that wrap FieldTrip-style header structures, events, and client connections to a server, including functions for the various requests to read and write samples and events. The module depends on [[http://​numpy.scipy.org|Numpy]] for representing data matrices and type and value fields of events. 
 + 
 +The following Python code example demonstrates how to use the interface
 +<code python>​ 
 +import sys 
 +import FieldTrip 
 + 
 +ftc FieldTrip.Client()  
 +ftc.connect('​localhost',​ 1972)    # might throw IOError 
 +ftc.getHeader() 
 +if H is None: 
 +    print '​Failed to retrieve header!'​ 
 +    sys.exit(1) 
 + 
 +print H 
 +print H.labels 
 + 
 +if H.nSamples > 0: 
 +    print '​Trying to read last sample...'​ 
 +    index H.nSamples - 1 
 +    D ftc.getData([index,​ index]) 
 +    print D 
 + 
 +if H.nEvents > 0: 
 +    print '​Trying to read (all) events...'​ 
 +    E ftc.getEvents() 
 +    for e in E: 
 +        print e 
 +  
 +ftc.disconnect() 
 +</​code>​