class Fake_TeleMir_Calibration:
    
    def __init__(self, precomputed):
    
        self.streamhandler = StreamHandler()
        # Configure and start
        self.dev = FakeMultiSignals(streamhandler = self.streamhandler)
        self.dev.configure( #name = 'Test dev',
                                    nb_channel = 14,
                                    sampling_rate =128.,
                                    buffer_length = 30.,
                                    packet_size = 1,
                                    precomputed = precomputed,
                                    )
        self.dev.initialize()
        self.dev.start()
            
        # Impedances
        self.w_imp=Topoplot_imp(stream = self.dev.streams[0], type_Topo = 'imp')
        self.w_imp.show()
        
        
    def close(self):
        
        #close window
        self.w_imp.close()
    
        # Stope and release the device
        self.dev.stop()
        self.dev.close()
def test1():
    import sys
    np.random.seed(6)
    app=QtGui.QApplication([])

    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure(#name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =1000.,
                                buffer_length = 6.4,
                                packet_size = 1,
                                )
    dev.initialize()
    dev.start()
    
    # Read the buffer on ZMQ socket
    port = dev.streams[0]['port']
    np_array = dev.streams[0]['shared_array'].to_numpy_array()
    print np_array.shape # this should be (nb_channel x buffer_length*samplign_rate)

    #initialize plots
    
 #   w1 = ScanningOscilloscope(dev.streams[0],2.,channels=[0])
#    w2 = Oscilloscope(dev.streams[0],2.,channels=[0,1,2])
    w1 = spaceShipLauncher(dev.streams[0])
   # w1 = freqBandsGraphics(dev.streams[0],5.,channels=[1])
  #  w1 = SpectrumGraphics(dev.streams[0],2.,logMode=True,channels=range(2))
  #  w1 = SpectrumGraphics(dev.streams[0],2.,logMode=True,channels=range(14),octavMode=True,octaveRan=1.26)
    
#    w1 = KurtosisGraphicsSci(dev.streams[0],2.,channels=range(10),title='Kurtosis')
    
#    w1.setFixedSize(600,600)
    #start plots
    w1.run()
   # w2.run()

#    timer=QtCore.QTimer()
#    timer.timeout.connect(w1.update)
#    timer.start(100)

   # w2.run()    

 #   w1.showFullScreen()
    #When you close the window the fake device stop emmiting
    w1.connect(w1,QtCore.SIGNAL("fermeturefenetre()"),dev.stop)
    dev.close()

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()
def test1():
    streamhandler = StreamHandler()
    timestampserver = TimestampServer()
    n= 4 
    devices = [ ]
    sampling_rates = [10., 500., 1000., 10000.]
    packet_sizes =  [4, 32, 64, 128]
    for i in range(4):
        dev = FakeMultiSignals(streamhandler = streamhandler)
        sampling_rate = sampling_rates[i%4]
        packet_size = packet_sizes[i%4]
        dev.configure( name = 'device {}'.format(i),
                                    nb_channel = 3,
                                    sampling_rate =sampling_rate,
                                    buffer_length = 10.  * (sampling_rate//packet_size)/(sampling_rate/packet_size),
                                    packet_size = packet_size,
                                    )
        dev.initialize()
        devices.append(dev)
        timestampserver.follow_stream(dev.streams[0])
        
    
    gevent.sleep(1)
    
    for i, dev in enumerate(devices):
        dev.start()
    gevent.sleep(1)
    
    stops = [ gevent.event.Event() for dev in devices ]
    greenlets = [ gevent.spawn(test_recv_loop, dev.streams[0]['port'], stop) for dev, stop in zip(devices, stops) ]
    for i in range(4):
        gevent.spawn_later(2., print_sampling_rate, timestampserver, devices[i] .streams[0]['port'])    
    gevent.sleep(5)
    for stop in stops:
        stop.set()
    
    gevent.sleep(1.)
    
    for i, dev in enumerate(devices):
        dev.stop()
 def __init__(self, precomputed):
 
     self.streamhandler = StreamHandler()
     # Configure and start
     self.dev = FakeMultiSignals(streamhandler = self.streamhandler)
     self.dev.configure( #name = 'Test dev',
                                 nb_channel = 14,
                                 sampling_rate =128.,
                                 buffer_length = 30.,
                                 packet_size = 1,
                                 precomputed = precomputed,
                                 )
     self.dev.initialize()
     self.dev.start()
         
     # Impedances
     self.w_imp=Topoplot_imp(stream = self.dev.streams[0], type_Topo = 'imp')
     self.w_imp.show()
def filter_analog1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure(     nb_channel = 64,
                                sampling_rate =10000.,
                                buffer_length = 30.,
                                packet_size = 100,
                                last_channel_is_trig = True,
                                )
    dev.initialize()
    dev.start()
    
    
    filter = BandPassFilter(stream = dev.streams[0],
                                                streamhandler= streamhandler,
                                                autostart = False)
    
    app = QtGui.QApplication([])
    
    filter.start()

    time.sleep(.2)
    filter.set_params(f_start = 300., f_stop =np.inf)
    time.sleep(.2)
    filter.set_params(f_start = 0., f_stop =40.3)
    time.sleep(.2)
    filter.set_params(f_start = 30., f_stop =70.)


    visibles = np.ones(dev.nb_channel, dtype = bool)
    visibles[1:] = False
    
    w1=Oscilloscope(stream = dev.streams[0])
    w2=Oscilloscope(stream = filter.out_stream)

    time.sleep(.5)
    
    
    for w in [w1, w2]:
        w.auto_gain_and_offset(mode = 0)
        w.set_params(xsize = 1.,
                                        mode = 'scan',
                                        visibles = visibles,
                                        ylims = [-5,5]
                                        )
        w.show()
    
    #~ w3=TimeFreq(stream = dev.streams[0])
    #~ w4=TimeFreq(stream = filter.out_stream)
    #~ for w in [w3, w4]:
        #~ w.set_params(colormap = 'hot', visibles = visibles, 
                                            #~ xsize=30, 
                                            #~ nb_column = 1)
        #~ w.show()
    
    
    
    app.exec_()
    w1.stop()
    w2.stop()
    
    
    dev.stop()

    dev.close()
def trigger_analog1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 32,
                                sampling_rate =1000.,
                                buffer_length = 64,
                                packet_size = 100,
                                last_channel_is_trig = True,
                                )
    dev.initialize()
    dev.start()

    def print_pos(pos):
        print pos
    
    trigger = AnalogTrigger(stream = dev.streams[0],
                                    threshold = 0.25,
                                    front = '+', 
                                    channel = dev.nb_channel-1,
                                    #~ debounce_mode = 'no-debounce',
                                    debounce_mode = 'after-stable',
                                    #~ debounce_mode = 'before-stable',
                                    debounce_time = 0.05,
                                    callbacks = [ print_pos,  ]
                                    )
    

    
    app = QtGui.QApplication([])
    
    w1=Oscilloscope(stream = dev.streams[0])
    w1.show()
    visibles = np.ones(dev.nb_channel, dtype = bool)
    visibles[4:] = False
    w1.set_params(xsize = 4.7,
                                    mode = 'scan',
                                visibles = visibles)


    time.sleep(.5)
    w1.auto_gain_and_offset(mode = 2)

    
    app.exec_()
    print 1
    # Stope and release the device
    trigger.stop()
    print 2
    dev.stop()
    print 3
    dev.close()
    print 4
def test1():
    streamhandler = StreamHandler()
    
    filename = 'cerveau_alex.raw'
    precomputed = np.fromfile(filename , dtype = np.float32).reshape(-1, 14).transpose()

    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =128.,
                                buffer_length = 30.,
                                packet_size = 1,
                                precomputed = precomputed,
                                )
    dev.initialize()
    dev.start()
    
    app = QtGui.QApplication([])
    
    w1=Oscilloscope(stream = dev.streams[0])
    w1.show()
    w1.auto_gain_and_offset(mode = 1)
    w1.set_params(xsize = 10.)

    
    app.exec_()
    
    # Stope and release the device
    dev.stop()
    dev.close()
Beispiel #8
0
    def __init__(self, precomputed, precomputedXY):

        self.streamhandler = StreamHandler()
        # Configure and start
        self.dev = FakeMultiSignals(streamhandler = self.streamhandler)
        self.dev.configure( #name = 'Test dev',
                                    nb_channel = 14,
                                    sampling_rate =128.,
                                    buffer_length = 30.,
                                    packet_size = 1,
                                    precomputed = precomputed,
                                    )
        self.dev.initialize()
        self.dev.start()

         # Configure and start
        self.devXY = FakeMultiSignals(streamhandler = self.streamhandler)
        self.devXY.configure( #name = 'Test dev',
                                    nb_channel = 2,
                                    sampling_rate =128.,
                                    buffer_length = 30.,
                                    packet_size = 1,
                                    precomputed = precomputedXY,
                                    )
        self.devXY.initialize()
        self.devXY.start()

             ## Configure and start output stream (for extracted feature)
        self.fout = TransmitFeatures(streamhandler = self.streamhandler)
        self.fout.configure( #name = 'Test fout',
                                    nb_channel = 14, # np.array([1:5])
                                    nb_feature = 12,
                                    nb_pts = 128,
                                    sampling_rate =10.,
                                    buffer_length = 10.,
                                    packet_size = 1,
                                    )
        self.fout.initialize(stream_in = self.dev.streams[0], stream_xy = self.devXY.streams[0])
        self.fout.start()

        self.screensize = np.array((1920))

        # Impedances
        # self.w_imp=Topoplot_imp(stream = self.dev.streams[0], type_Topo = 'imp')
        # self.w_imp.show()

        # signal
        numscreen = 1
        self.w_oscilo=Oscilloscope(stream = self.dev.streams[0])
        self.w_oscilo.auto_gain_and_offset(mode = 2)
        self.w_oscilo.set_params(xsize = 10, mode = 'scroll')
        self.w_oscilo.automatic_color('jet')
        self.w_oscilo.move(self.screensize + (numscreen-1) * 800 ,200)
        #~ self.w_oscilo.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
        self.w_oscilo.show()

        #parametres
        numscreen = 2
        self.w_feat1=Oscilloscope(stream = self.fout.streams[0])
        self.w_feat1.auto_gain_and_offset(mode = 0)
        self.w_feat1.set_params(xsize = 10, mode = 'scroll')
        #self.w_feat1.set_params(colors = [[0, 0, 255], [255, 0, 255], [255, 0 ,0], [255, 255, 0], [0, 255, 0],  [0, 255, 255]])
        self.w_feat1.set_params(ylims = [0,100])
        self.w_feat1.move(self.screensize + (numscreen-1) * 800 ,200)
        #~ self.w_feat1.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
        self.w_feat1.show()

        #topo
        numscreen = 3
        # self.w_topo=Topoplot(stream = self.dev.streams[0], type_Topo = 'topo')
        # self.w_topo.move(self.screensize + (numscreen-1) * 800 ,200)
        # self.w_topo.show()

        # giro
        #~ self.w_xy=Oscilloscope(stream = self.devXY.streams[0])
        #~ self.w_xy.show()
        #~ self.w_xy.auto_gain_and_offset(mode = 1)
        #~ self.w_xy.set_params(xsize = 10, mode = 'scroll')

        # temps frequence
        numscreen = 4
        # #self.w_Tf=TimeFreq(stream = self.dev.streams[0])
        # self.w_Tf.set_params(xsize = 10)
        # self.w_Tf.change_param_tfr(f_stop = 45, f0 = 1)
        # self.w_Tf.move(self.screensize + (numscreen-1) * 800 ,200)
        # self.w_Tf.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
        # self.w_Tf.show()

        numscreen = 5
        # self.w_Tf2=TimeFreq2(stream = self.dev.streams[0])
        # self.w_Tf2.set_params(xsize = 10)
        # self.w_Tf2.change_param_tfr(f_stop = 45, f0 = 1)
        # self.w_Tf2.move(self.screensize + (numscreen-1) * 800 ,200)
        # self.w_Tf2.setWindowFlags(QtCore.Qt.CustomizeWindowHint)
        # self.w_Tf2.show()
        #w_Tf.change_param_channel(clim = 20)

        #~ # freqbands
        numscreen = 6 # dans le code
def teleMir_CB():
       
    streamhandler = StreamHandler()
    
    # Configure and start
    #~ dev = FakeMultiSignals(streamhandler = streamhandler)
    #~ dev.configure( #name = 'Test dev',
                                #~ nb_channel = 14,
                                #~ sampling_rate =128.,
                                #~ buffer_length = 10.,
                                #~ packet_size = 1,
                                #~ )
    #~ dev.initialize()
    #~ dev.start()
    

    filename = '/home/ran/Projets/pyacq_emotiv_recording/alex/Emotiv Systems Pty Ltd #SN201105160008860.raw'
    #filename = '/home/ran/Projets/pyacq_emotiv_recording/caro/Emotiv Systems Pty Ltd  #SN201105160008860.raw'
    #filename = '/home/mini/pyacq_emotiv_recording/simple_blink/Emotiv Systems Pty Ltd  #SN201105160008860.raw'
    filenameImp = '/home/ran/Projets/EEG_recordings/anneLise/Emotiv Systems Pty Ltd #SN200709276578911.raw'
    filenameXY = '/home/ran/Projets/EEG_recordings/anneLise/Emotiv Systems Pty Ltd #SN200709276578912.raw'

    
    precomputed = np.fromfile(filename , dtype = np.float32).reshape(-1, 14).transpose()
    precomputedImp = np.fromfile(filenameImp , dtype = np.float32).reshape(-1, 14).transpose()
    precomputedXY = np.fromfile(filenameXY , dtype = np.float32).reshape(-1, 2).transpose()
    
    
    # Configure and start signal
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =128.,
                                buffer_length = 30.,
                                packet_size = 1,
                                precomputed = precomputed,
                                )
    dev.initialize()
    dev.start()
    
    #~ # Configure and start imp
    #~ devImp = FakeMultiSignals(streamhandler = streamhandler)
    #~ devImp.configure( #name = 'Test dev',
                                #~ nb_channel = 14,
                                #~ sampling_rate =128.,
                                #~ buffer_length = 30.,
                                #~ packet_size = 1,
                                #~ precomputed = precomputedImp,
                                #~ )
    #~ devImp.initialize()
    #~ devImp.start()
    
    # Configure and start gyroXY
    devXY = FakeMultiSignals(streamhandler = streamhandler)
    devXY.configure( #name = 'Test dev',
                                nb_channel = 2,
                                sampling_rate =128.,
                                buffer_length = 30.,
                                packet_size = 1,
                                precomputed = precomputedXY,
                                )
    devXY.initialize()
    devXY.start()
    
     ## Configure and start output stream (for extracted feature)
    fout = TransmitFeatures(streamhandler = streamhandler)
    fout.configure( #name = 'Test fout',
                                nb_channel = 14, # np.array([1:5])
                                nb_feature = 6,
                                nb_pts = 128,
                                sampling_rate =10.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    fout.initialize(stream_in = dev.streams[0], stream_xy = devXY.streams[0]) 
    fout.start()
    
    #Osc server
    #p = Process(target=., args=('bob',))
    
    #color = 'summer'
    # Bleu
    #color = 'jet'
    # Rouge
    color = 'hot'
    # vert/jaune
    #color = 'summer'
    
    app = QtGui.QApplication([])
    
        
    # Impedances
    w_imp=Topoplot_imp(stream = dev.streams[0], type_Topo= 'imp')
    w_imp.show()
    
    # freqbands 
    w_sp_bd=freqBandsGraphics(stream = dev.streams[0], interval_length = 3., channels = [12])
    w_sp_bd.run()  
    
    # signal
    w_oscilo=Oscilloscope(stream = dev.streams[0])
    w_oscilo.show()
    w_oscilo.set_params(xsize = 10, mode = 'scroll')
    w_oscilo.auto_gain_and_offset(mode = 2)
    w_oscilo.gain_zoom(100)
    #w_oscilo.set_params(colors = 'jet')
    select_chan = np.ones(14, dtype = bool)
    w_oscilo.automatic_color(cmap_name = 'jet', selected = select_chan)
    
    # parametres
    w_feat1=Oscilloscope_f(stream = fout.streams[0])
    w_feat1.show()
    w_feat1.set_params(colormap = color)
    #w_feat1.auto_gain_and_offset(mode = 1)
    #w_feat1.set_params(xsize = 10, mode = 'scroll')
    #~ select_feat = np.ones(6, dtype = bool)
   #~ # print select
    #~ #w_oscilo.set_params(colormap = 'automn',  selected = select)
    #~ w_feat1.automatic_color(cmap_name = 'jet', selected = select_feat)
    w_feat1.showFullScreen()
    
    w_feat1.set_params(xsize = 10, mode = 'scroll')
    #~ select_feat = np.ones(4, dtype = bool)
    #~ w_feat1.automatic_color(cmap_name = 'jet', selected = select_feat)
    
    
    # topographie
    w_topo=Topoplot(stream = dev.streams[0], type_Topo= 'topo')
    w_topo.show()
    
    # temps frequence 1

    w_Tf=TimeFreq(stream = dev.streams[0])
    w_Tf.show()  
    w_Tf.set_params(xsize = 10)
    w_Tf.change_param_tfr(f_stop = 45, f0 = 1)
    w_Tf.set_params(colormap = color)
    #w_Tf.clim_changed(20)
    #w_Tf.change_param_channel(clim = 20)
    
    # temps frequence 2
    w_Tf2=TimeFreq2(stream = dev.streams[0])
    w_Tf2.show()  
    w_Tf2.set_params(xsize = 10)
    w_Tf2.change_param_tfr(f_stop = 45, f0 = 1)
    w_Tf2.set_params(colormap = color)
    
    
    # kurtosis 
    #w_ku=KurtosisGraphics(stream = dev.streams[0], interval_length = 1.)
    #w_ku.run()  
    

    ## Bien moins fluide
    # Spectre
    #~ w_sp=SpectrumGraphics(dev.streams[0],3.,channels=[11,12])
    #~ w_sp.run()
    
    w1 = spaceShipLauncher(dev.streams[0])
    w1.run()
    w1.showFullScreen()

    
    app.exec_()
    
    # Stope and release the device
    fout.stop()
    fout.close()  
    print 'ici'
    dev.stop()
    dev.close()
    print 'ici'
    devXY.stop()
    devXY.close()
    print 'ici'
    devImp.stop()
    devImp.close()
    print 'ici'
def test1():
    streamserver = StreamServer()
    dev = FakeMultiSignals(streamhandler = streamserver)
    dev.configure()
    dev.initialize()
    dev.start()
    
    print streamserver.get_stream_list()
    
    time.sleep(1.)
    
    streamhandlerproxy = StreamHandlerProxy()
    print streamhandlerproxy.get_stream_list()
    
    
    dev.stop()
    dev.close()
    streamserver.stop()
def on_pc1():
    streamhandler = StreamHandler()

    # Configure and start
    dev = FakeMultiSignals(streamhandler=streamhandler)
    dev.configure(nb_channel=16, sampling_rate=1000.0, buffer_length=64, packet_size=100)  # name = 'Test dev',
    dev.initialize()
    dev.start()

    channel_mask = np.ones(16, dtype=bool)
    channel_mask[::2] = False
    converter1 = AnaSigSharedMem_to_AnaSigPlainData(
        streamhandler, dev.streams[0], info_port=info_port, compress="blosc", channel_mask=channel_mask
    )
    time.sleep(20.0)

    converter1.stop()

    dev.stop()
    dev.close()
Beispiel #12
0
# -*- coding: utf-8 -*-

from pyacq import FakeMultiSignals

print FakeMultiSignals.get_available_devices().values()[0]

from .configure import _params_options, _params_rec_on_trigger
import pyacq.gui.guiutil.mypyqtgraph as mypg
import pyqtgraph as pg

p = pg.parametertree.Parameter.create(name='options',
                                      type='group',
                                      children=_params_options)
options = mypg.get_dict_from_group_param(p)
print options
p = pg.parametertree.Parameter.create(name='rec_on_trigger',
                                      type='group',
                                      children=_params_rec_on_trigger)
rec_on_trigger = mypg.get_dict_from_group_param(p)

default_setup = {
    'devices': [FakeMultiSignals.get_available_devices().values()[0]],
    'views': [
        {
            'class': 'Oscilloscope',
            'name': 'Oscilloscope',
            'device_num': 0,
            'subdevice_num': 0,
            'params': {}
        },
    ],
def test1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( 
                                nb_channel = 32,
                                sampling_rate =1000.,
                                buffer_length = 64.,
                                packet_size = 16,
                                )
    dev.initialize()
    dev.start()
    
    app = QtGui.QApplication([])
    w1=Oscilloscope(stream = dev.streams[0])
    w1.set_params(refresh_interval = 40,
                                                        xsize = 2.)
    w1.auto_gain_and_offset(mode = 2)
    w1.show()
    
    w2 = TimeFreq(stream = dev.streams[0], max_visible_on_open = 4)
    w2.set_params(refresh_interval = 40,
                                                        xsize = 2., nb_column = 1)
    w2.show()
    
    app.exec_()
    
    # Stope and release the device
    dev.stop()
    dev.close()
def run_test():
    streamhandler = StreamHandler()
    
    ## Configure and start acquisition stream
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =128.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    dev.initialize()
    dev.start()
    
    ## Configure and start output stream (for extracted feature)
    fout = TransmitFeatures(streamhandler = streamhandler)
    fout.configure( name = 'Test fout',
                                nb_channel = 14, # np.array([1:5])
                                nb_feature = 21,
                                nb_pts = 128,
                                sampling_rate =62.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    fout.initialize(stream_in = dev.streams[0])  # Could take multistreams ?
    fout.start()
    
    
    ## Create and starts recevers with multuprocessing for stream in and stream out
    stream_in = dev.streams[0]
    stream_out = fout.streams[0]
    stop_recv = mp.Value('i', 0)
    process_in = mp.Process(target= test_recv_loop, args = (stream_in['port'],stop_recv))
    process_out = mp.Process(target= test_recv_loop, args = (stream_out['port'],stop_recv))

    process_in.start()
    process_out.start()
    
    
    time.sleep(0.5)
    stop_recv.value = 1
    
    ## Stop and release devices
    fout.stop()
    fout.close()   
    dev.stop()
    dev.close()
    print 'fout and dev devises closed'
    
    process_in.join(1)  # join method blocante
    print 'process in clear'
    process_out.join(1)
    print 'process out clear'
Beispiel #15
0
def teleMir_CB():
       
    streamhandler = StreamHandler()
    
    # Configure and start
    #~ dev = FakeMultiSignals(streamhandler = streamhandler)
    #~ dev.configure( #name = 'Test dev',
                                #~ nb_channel = 14,
                                #~ sampling_rate =128.,
                                #~ buffer_length = 10.,
                                #~ packet_size = 1,
                                #~ )
    #~ dev.initialize()
    #~ dev.start()
    
    #filename = '/home/mini/pyacq_emotiv_recording/rec 2013-09-19 16:20:36.580141_Alex/Emotiv Systems Pty Ltd #SN201105160008860.raw'
    #filename = '/home/mini/pyacq_emotiv_recording/rec 2013-09-18 14:12:09.347990_Caro/Emotiv Systems Pty Ltd  #SN201105160008860.raw'
    filename = '/home/mini/pyacq_emotiv_recording/simple_blink/Emotiv Systems Pty Ltd  #SN201105160008860.raw'
    
    precomputed = np.fromfile(filename , dtype = np.float32).reshape(-1, 14).transpose()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =128.,
                                buffer_length = 30.,
                                packet_size = 1,
                                precomputed = precomputed,
                                )
    dev.initialize()
    dev.start()
    
     ## Configure and start output stream (for extracted feature)
    fout = TransmitFeatures(streamhandler = streamhandler)
    fout.configure( #name = 'Test fout',
                                nb_channel = 14, # np.array([1:5])
                                nb_feature = 4,
                                nb_pts = 128,
                                sampling_rate =10.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    fout.initialize(stream_in = dev.streams[0]) 
    fout.start()
    
    #Osc server
    #p = Process(target=., args=('bob',))
    
    
    app = QtGui.QApplication([])
    
    # Impedances
    #~ w_imp=Topoplot(stream = dev.streams[0], type_Topo= 'imp')
    #~ w_imp.show()
    
    # signal
    w_oscilo=Oscilloscope(stream = dev.streams[0])
    w_oscilo.show()
    w_oscilo.auto_gain_and_offset(mode = 1)
    w_oscilo.set_params(xsize = 10, mode = 'scroll')
    
    # temps frequence
    w_Tf=TimeFreq(stream = dev.streams[0])
    w_Tf.show()  
    w_Tf.set_params(xsize = 10)
    w_Tf.change_param_tfr(f_stop = 45, f0 = 1)
    #w_Tf.change_param_channel(clim = 20)
    
    # kurtosis 
    #w_ku=KurtosisGraphics(stream = dev.streams[0], interval_length = 1.)
    #w_ku.run()  
    
    # freqbands 
    w_sp_bd=freqBandsGraphics(stream = dev.streams[0], interval_length = 3., channels = [11,12])
    w_sp_bd.run()  
    
    ## Bien moins fluide
    # Spectre
    #~ w_sp=SpectrumGraphics(dev.streams[0],3.,channels=[11,12])
    #~ w_sp.run()
    
    w_feat1=Oscilloscope(stream = fout.streams[0])
    w_feat1.show()
    w_feat1.set_params(xsize = 10, mode = 'scroll')
    
    #w1 = glSpaceShip(dev.streams[0])
    #w1.run()
    #w1.showFullScreen()
    
       
    
    app.exec_()
    
    # Stope and release the device
    fout.stop()
    fout.close()  
    dev.stop()
    dev.close()
def filter_analog1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure(     nb_channel = 2,
                                sampling_rate =10000.,
                                buffer_length = 30.,
                                packet_size = 100,
                                last_channel_is_trig = True,
                                )
    dev.initialize()
    dev.start()

    dev2 = FakeDigital(streamhandler = streamhandler)
    dev2.configure( 
                                nb_channel = 30,
                                sampling_rate =10000.,
                                buffer_length = 30.,
                                packet_size = 100,
                                )
    dev2.initialize()
    dev2.start()

    
    
    
    filter = BandPassFilter(stream = dev.streams[0],
                                                streamhandler= streamhandler,
                                                autostart = False,
                                                f_start =0.,
                                                f_stop = dev.streams[0].sampling_rate/10./2.,
                                                )
    decimator = SimpleDecimator( filter.out_stream,
                                                streamhandler= streamhandler,
                                                downsampling_factor = 10,
                                                autostart = False,
                                                )

    decimator2 = SimpleDecimator( dev2.streams[0],
                                                streamhandler= streamhandler,
                                                downsampling_factor = 10,
                                                autostart = False,
                                                )
    print decimator2.out_stream._params
    
                                                
    app = QtGui.QApplication([])
    
    filter.start()
    decimator.start()
    decimator2.start()

    visibles = np.ones(dev.nb_channel, dtype = bool)
    visibles[1:] = False
    
    w1=Oscilloscope(stream = dev.streams[0])
    w2=Oscilloscope(stream = filter.out_stream)
    w3=Oscilloscope(stream = decimator.out_stream)
    
    w4 = OscilloscopeDigital(stream = dev2.streams[0])
    w5 = OscilloscopeDigital(stream = decimator2.out_stream)

    time.sleep(.5)
    
    
    for w in [w1, w2, w3]:
        w.auto_gain_and_offset(mode = 0)
        w.set_params(xsize = 1.,
                                        mode = 'scan',
                                        visibles = visibles,
                                        ylims = [-5,5]
                                        )
        w.show()
    
    for w in [w4, w5]:
        w.set_params(xsize = 1.,
                                        mode = 'scan',
                                        )
        w.show()
    
    
    
    
    app.exec_()
    w1.stop()
    w2.stop()
    
    
    dev.stop()

    dev.close()
def test1():
    
    for name, info_device in FakeMultiSignals.get_available_devices().items():
        print name
        print info_device
def test1():
    streamhandler = StreamHandler()
    
    
    dev0 = FakeMultiSignals(streamhandler = streamhandler)
    dev0.configure( #name = 'Analog fake 0',
                                nb_channel = 16,
                                sampling_rate =1000.,
                                buffer_length = 64,
                                packet_size = 10,
                                )
    
    dev1 = FakeDigital(streamhandler = streamhandler)
    dev1.configure( #name = u'Digital fake 1 éà',
                                nb_channel = 10,
                                sampling_rate =1000.,
                                buffer_length = 10.,
                                packet_size = 128,
                                )
    
    devs = [dev0, dev1]
    
    for dev in devs:
        dev.initialize()
    
    
    streams = [dev.streams[0] for dev in  devs]
    dirname_base = os.path.join(user.home, 'test_pyacq_recording')
    if not os.path.exists(dirname_base):
        os.mkdir(dirname_base)
    dirname = os.path.join(dirname_base, 'rec {}'.format(datetime.datetime.now()))
    if not os.path.exists(dirname):
        os.mkdir(dirname)
    
    rec = RawDataRecording(streams, dirname)
    rec.start()
    
    for dev in devs:
        dev.start()
    
    time.sleep(10.)
    
    rec.stop()
    
    # Stope and release the device
    for dev in devs:
        dev.stop()
        dev.close()
    
    
    # Read the files
    reader = neo.RawBinarySignalIO(filename = os.path.join(dirname, 'fake 16 analog input.raw'))
    seg = reader.read_segment(sampling_rate = 1.*pq.kHz,
                                            t_start = 0.*pq.s,
                                            unit = pq.V,
                                            nbchannel = 16,
                                            dtype = np.float32,
                                            )
    app = QtGui.QApplication([])
    viewer = SegmentViewer(segment = seg)
    #~ viewer = SignalViewer(analogsignals = seg.analogsignals, with_time_seeker = True)
    viewer.show()
    
    print seg.analogsignals[0].shape
    
    analogsignals2 = [ ]
    arr = np.memmap(filename = os.path.join(dirname, u'fake 10 digital input.raw'), mode = 'r', dtype = np.uint8)
    arr = arr.reshape(-1, 2)
    print arr.shape
    for chan in range(10):
        b = chan//8
        mask = 1<<(chan%8)
        sig = (arr[:,b]&mask>0).astype(float)
        analogsignals2.append(neo.AnalogSignal(sig*pq.V, t_start = 0*pq.s, sampling_rate = 1*pq.kHz))
    viewer2 = SignalViewer(analogsignals = analogsignals2, with_time_seeker = True)
    
    viewer2.show()
    
    
    app.exec_()
def test2():
    # record on trigger
    
    streamhandler = StreamHandler()
    
    
    dev0 = FakeMultiSignals(streamhandler = streamhandler)
    dev0.configure(
                                nb_channel = 16,
                                sampling_rate =1000.,
                                buffer_length = 64,
                                packet_size = 10,
                                last_channel_is_trig = True,
                                )
    
    dev1 = FakeDigital(streamhandler = streamhandler)
    dev1.configure(
                                nb_channel = 10,
                                sampling_rate =1000.,
                                buffer_length = 10.,
                                packet_size = 128,
                                )
    
    devs = [dev0, dev1]
    #~ devs = [dev0]
    
    for dev in devs:
        dev.initialize()

    dirname_base = os.path.join(user.home, 'test_pyacq_recording')
    if not os.path.exists(dirname_base):
        os.mkdir(dirname_base)
    dirname = os.path.join(dirname_base, 'rec {}'.format(datetime.datetime.now()))
    if not os.path.exists(dirname):
        os.mkdir(dirname)
        
    
    global is_started
    is_started = 0
    
    def start_rec(pos):
        global is_started
        is_started +=1
        if is_started!=5:
            return
        print 'start_rec', pos, is_started
        streams = [dev.streams[0] for dev in  devs]
        
        bound_indexes = {dev0.streams[0] : (pos-1000, pos+1000),
                                            dev1.streams[0] : (pos-1000, pos+1000),
                         }
        rec = RawDataRecording(streams, dirname, bound_indexes = bound_indexes)
        rec.start()
        

    #~ trigger.start()
    
    
    for dev in devs:
        dev.start()
    
    trigger = AnalogTrigger(stream = dev0.streams[0],
                                    threshold = 0.25,
                                    front = '+', 
                                    channel = dev0.nb_channel-1,
                                    #~ debounce_mode = 'no-debounce',
                                    #~ debounce_mode = 'after-stable',
                                    debounce_mode = 'before-stable',
                                    debounce_time = 0.05,
                                    callbacks = [ start_rec,  ]
                                    )    
    time.sleep(5.)
    
    #~ rec.stop()
    
    # Stope and release the device
    for dev in devs:
        dev.stop()
        dev.close()
    
    
    # Read the files
    reader = neo.RawBinarySignalIO(filename = os.path.join(dirname, 'fake 16 analog input.raw'))
    seg = reader.read_segment(sampling_rate = 1.*pq.kHz,
                                            t_start = 0.*pq.s,
                                            unit = pq.V,
                                            nbchannel = 16,
                                            dtype = np.float32,
                                            )
    app = QtGui.QApplication([])
    viewer = SegmentViewer(segment = seg)
    #~ viewer = SignalViewer(analogsignals = seg.analogsignals, with_time_seeker = True)
    viewer.show()
    
    print seg.analogsignals[0].shape
    sig = seg.analogsignals[-1].magnitude
    print np.where((sig[:-1]<.25)&(sig[1:]>=.25))
    
    analogsignals2 = [ ]
    arr = np.memmap(filename = os.path.join(dirname, u'fake 10 digital input.raw'), mode = 'r', dtype = np.uint8)
    arr = arr.reshape(-1, 2)
    print arr.shape
    for chan in range(10):
        b = chan//8
        mask = 1<<(chan%8)
        sig = (arr[:,b]&mask>0).astype(float)
        analogsignals2.append(neo.AnalogSignal(sig*pq.V, t_start = 0*pq.s, sampling_rate = 1*pq.kHz))
    viewer2 = SignalViewer(analogsignals = analogsignals2, with_time_seeker = True)
    
    viewer2.show()
    
    
    app.exec_()    
def test1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 32,
                                sampling_rate =1000.,
                                buffer_length = 64,
                                packet_size = 100,
                                last_channel_is_trig = True,
                                )
    dev.initialize()
    dev.start()

    def print_pos(pos):
        print pos
    
    def print_new_chunk(n):
        print 'new stackedchunk', n

    stackedchunk = StackedChunkOnTrigger(stream = dev.streams[0],
                                                                                stack_size = 20,
                                                                                left_sweep = 0.1,
                                                                                right_sweep = 0.1,
                                                                                )
    stackedchunk.new_chunk.connect(print_new_chunk)
    
    trigger = AnalogTrigger(stream = dev.streams[0],
                                    threshold = 0.25,
                                    front = '+', 
                                    channel = dev.nb_channel-1,
                                    #~ debounce_mode = 'no-debounce',
                                    debounce_mode = 'after-stable',
                                    #~ debounce_mode = 'before-stable',
                                    debounce_time = 0.05,
                                    callbacks = [ print_pos,  stackedchunk.on_trigger]
                                    )
    

    
    app = QtGui.QApplication([])
    
    
    time.sleep(.5)

    
    app.exec_()
    # Stope and release the device
    trigger.stop()
    dev.stop()
    dev.close()
def test1():
    streamhandler = StreamHandler()
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( 
                                nb_channel = 10,
                                sampling_rate =1000.,
                                buffer_length = 10.,
                                packet_size = 128,
                                )
    dev.initialize()
    dev.start()
    
    # Create and starts receiver with multuprocessing
    stream0 = dev.streams[0]
    stop_recv = mp.Value('i', 0)
    process = mp.Process(target= test_recv_loop, args = (stream0['port'],stop_recv))
    process.start()
    time.sleep(10.)
    stop_recv.value = 1
    process.join()
    

    # Stop and release the device
    dev.stop()
    dev.close()
def test1():
    streamhandler = StreamHandler()
    
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( nb_channel = 16,
                                sampling_rate =1000.,
                                buffer_length = 64,
                                packet_size = 10,
                                )
    dev.initialize()
    print dev.streams[0]
    print dev.streams[0]['port']
    dev.start()
    
    app = QtGui.QApplication([])
    
    w1=Oscilloscope(stream = dev.streams[0])
    w1.show()
    #~ w1.auto_gain_and_offset(mode = 2)
    #~ visibles = np.ones(16, dtype = bool)
    #~ visibles[4:] = False
    #~ w1.set_params(xsize = 1.,
                                    #~ mode = 'scan',
                                #~ visibles = visibles)

    #~ print w1.get_params()
    w1.set_params(**w1.get_params())

    #~ w2=Oscilloscope(stream = dev.streams[0])
    #~ w2.show()
    #~ w2.auto_gain_and_offset(mode = 0)
    #~ w2.set_params(xsize = 5, mode = 'scroll')
    

    
    app.exec_()
    
    # Stope and release the device
    dev.stop()
    dev.close()
def run_test():
    streamhandler = StreamHandler()
    
     ## Configure and start acquisition stream
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( #name = 'Test dev',
                                nb_channel = 14,
                                sampling_rate =128.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    dev.initialize()
    dev.start()
    
    ## Configure and start output stream (for extracted feature)
    fout = TransmitFeatures(streamhandler = streamhandler)
    fout.configure( #name = 'Test fout',
                                nb_channel = 14, # np.array([1:5])
                                nb_feature = 21,
                                nb_pts = 128,
                                sampling_rate =10.,
                                buffer_length = 10.,
                                packet_size = 1,
                                )
    fout.initialize(stream_in = dev.streams[0]) 
    fout.start()
    
    app = QtGui.QApplication([])
    
    w_in=Oscilloscope(stream = dev.streams[0])
    w_in.show()
    
    w_out=Oscilloscope(stream = fout.streams[0])
    w_out.show()
    

    app.exec_()


    ## Stop and release devices
    fout.stop()
    fout.close()   
    dev.stop()
    dev.close()
    print 'fout and dev devises closed'
def test1():
    streamhandler = StreamHandler()
    
    
    # Configure and start
    dev = FakeMultiSignals(streamhandler = streamhandler)
    dev.configure( 
                                #~ nb_channel = 16,
                                #~ sampling_rate =1000.,
                                #~ buffer_length = 64,
                                #~ packet_size = 100,
                                nb_channel = 8,
                                sampling_rate =10000.,
                                buffer_length = 64,
                                packet_size = 100,
                                
                                last_channel_is_trig = True,
                                
                                )
    dev.initialize()
    print dev.streams[0]
    print dev.streams[0]['port']
    dev.start()
    
    app = QtGui.QApplication([])
    
    w1=TriggeredOscilloscope(stream = dev.streams[0])
    w1.set_params(channel = dev.nb_channel-1,
                                    
                                    left_sweep = -.1,
                                    right_sweep = +.3,
                                    threshold = .25,
                                    #~ debounce_mode = 'no-debounce',
                                    debounce_mode = 'after-stable',
                                    #~ debounce_mode = 'before-stable',
                                    debounce_time = 0.05,
                                    )
    w1.show()

    w2=Oscilloscope(stream = dev.streams[0])
    w2.show()
    w2.auto_gain_and_offset(mode = 0)
    w2.set_params(xsize = 5, mode = 'scroll')
    

    
    app.exec_()
    w1.stop()
    # Stope and release the device
    dev.stop()
    dev.close()
# -*- coding: utf-8 -*-

from pyacq import FakeMultiSignals
print FakeMultiSignals.get_available_devices().values()[0]

from .configure import _params_options, _params_rec_on_trigger
import  pyacq.gui.guiutil.mypyqtgraph as mypg
import pyqtgraph as pg
p = pg.parametertree.Parameter.create(name='options', type='group', children=_params_options)
options = mypg.get_dict_from_group_param(p)
print options
p = pg.parametertree.Parameter.create(name='rec_on_trigger', type='group', children=_params_rec_on_trigger)
rec_on_trigger = mypg.get_dict_from_group_param(p)

default_setup = {
    'devices' : [ FakeMultiSignals.get_available_devices().values()[0] ],
    'views' : [
        {
            'class' : 'Oscilloscope',
            'name' : 'Oscilloscope',
            'device_num' : 0,
            'subdevice_num' : 0,
            'params' : {
            
            }
        },
    ],
    'options' : options,
    'rec_on_trigger' : rec_on_trigger,