コード例 #1
0
ファイル: tools.py プロジェクト: Enchufa2/pyacq
    def __init__(self, input_stream, timeout=200, parent=None):
        QtCore.QThread.__init__(self, parent)
        self.input_stream = weakref.ref(input_stream)
        self.timeout = timeout

        self.running = False
        self.running_lock = Mutex()
        self.lock = Mutex()
        self._pos = None
コード例 #2
0
    def __init__(self):
        MainWindowNode.__init__(self)

        self.layout = QT.QVBoxLayout()
        self.setLayout(self.layout)

        self.docks = {}
        self.docks['overview'] = QT.QDockWidget('overview')
        self.overview = WidgetOverview(self)
        self.docks['overview'].setWidget(self.overview)
        self.addDockWidget(QT.TopDockWidgetArea, self.docks['overview'])

        self.create_actions_and_menu()

        self.dialog_fullchain_params = ParamDialog(fullchain_params,
                                                   parent=self)
        self.dialog_fullchain_params.params['duration'] = 10.  # for debug
        self.dialog_fullchain_params.params['peak_detector',
                                            'relative_threshold'] = 8
        self.dialog_fullchain_params.resize(450, 600)

        self.dialog_method_features = MethodDialog(
            features_params_by_methods,
            parent=self,
            title='Which feature method ?',
            selected_method='peak_max')
        self.dialog_method_cluster = MethodDialog(
            cluster_params_by_methods,
            parent=self,
            title='Which cluster method ?',
            selected_method='sawchaincut')

        self.mutex = Mutex()
コード例 #3
0
    def __init__(self, out_stream, container, parent=None):
        QtCore.QThread.__init__(self)
        self.out_stream = out_stream
        self.container = container

        self.lock = Mutex()
        self.running = False
コード例 #4
0
    def __init__(self, **kargs):
        WidgetNode.__init__(self, **kargs)

        self.layout = QT.QVBoxLayout()
        self.setLayout(self.layout)

        h = QT.QHBoxLayout()
        self.layout.addLayout(h)

        self.combobox = QT.QComboBox()
        h.addWidget(self.combobox)

        but = QT.QPushButton('clear')
        h.addWidget(but)
        but.clicked.connect(self.on_clear)

        self.label = QT.QLabel('')
        h.addWidget(self.label)

        self.graphicsview = pg.GraphicsView()
        self.layout.addWidget(self.graphicsview)

        self.params = pg.parametertree.Parameter.create(name='settings',
                                                        type='group',
                                                        children=self._params)
        self.tree_params = pg.parametertree.ParameterTree(parent=self)
        self.tree_params.header().hide()
        self.tree_params.setParameters(self.params, showTop=True)
        self.tree_params.setWindowTitle('Options for waveforms hist viewer')
        self.tree_params.setWindowFlags(QT.Qt.Window)
        self.params.sigTreeStateChanged.connect(self.on_params_changed)

        self.initialize_plot()

        self.mutex = Mutex()
コード例 #5
0
    def __init__(self, node, parent=None):
        QtCore.QThread.__init__(self, parent=parent)

        self.node = node

        self.lock = Mutex()
        self.running = False
コード例 #6
0
ファイル: rawrecorder.py プロジェクト: funshine/pyacq
 def _initialize(self):
     os.mkdir(self.dirname)
     self.files = []
     self.threads = []
     
     self.mutex = Mutex()
     
     self._stream_properties = collections.OrderedDict()
     
     for name, input in self.inputs.items():
         filename = os.path.join(self.dirname, name+'.raw')
         fid = open(filename, mode='wb')
         self.files.append(fid)
         
         thread = ThreadRec(name, input, fid)
         self.threads.append(thread)
         thread.recv_start_index.connect(self.on_start_index)
         
         prop = {}
         for k in ('streamtype', 'dtype', 'shape', 'sample_rate'):
             prop[k] = input.params[k]
         self._stream_properties[name] = prop
     
     self._stream_properties['pyacq_version'] = pyacq_version
     
     self._flush_stream_properties()
     
     self._annotations = {}
コード例 #7
0
    def __init__(self,
                 input_stream,
                 timeout=200,
                 return_data=None,
                 parent=None):
        QtCore.QThread.__init__(self, parent)
        self.input_stream = weakref.ref(input_stream)
        self.timeout = timeout
        self.return_data = return_data
        if self.return_data is None:
            self.return_data = self.input_stream()._own_buffer

        self.running = False
        self.running_lock = Mutex()
        self.lock = Mutex()
        self._pos = None
        atexit.register(self.stop)
コード例 #8
0
ファイル: overlapfiltfilt.py プロジェクト: funshine/pyacq
 def __init__(self, input_stream, output_stream, timeout=200, parent=None):
     ThreadPollInput.__init__(self,
                              input_stream,
                              timeout=timeout,
                              return_data=True,
                              parent=parent)
     self.output_stream = output_stream
     self.mutex = Mutex()
コード例 #9
0
ファイル: brainampsocket.py プロジェクト: zoeith/pyacq
    def __init__(self, outputs, brainamp_host, brainamp_port, nb_channel, parent=None):
        QtCore.QThread.__init__(self)
        self.outputs = outputs
        self.brainamp_host= brainamp_host
        self.brainamp_port= brainamp_port
        self.nb_channel = nb_channel

        self.lock = Mutex()
        self.running = False
コード例 #10
0
    def __init__(self, frame_grabber, video_index, parent=None):
        QT.QObject.__init__(self, parent)

        self.fg = frame_grabber
        self.video_index = video_index

        self.mutex = Mutex()
        self.request_list = []
        self._last_frame = None
コード例 #11
0
 def __init__(self, name='', parent=None):
     self.name = name
     
     self.lock = Mutex()  # on lock for all state
     self._running = False
     self._configured = False
     self._initialized = False
     self._closed = False
     
     self.inputs = {name:InputStream(spec=spec, node=self, name=name) for name, spec in self._input_specs.items()}
     self.outputs = {name:OutputStream(spec=spec, node=self, name=name) for name, spec in self._output_specs.items()}
コード例 #12
0
ファイル: onlinepeeler.py プロジェクト: xabiben/tridesclous
 def __init__(self, input_stream, output_streams, peeler,in_group_channels,
                     timeout = 200, parent = None):
     
     ThreadPollInput.__init__(self, input_stream,  timeout=timeout, return_data=True, parent = parent)
     self.output_streams = output_streams
     self.peeler = peeler
     self.in_group_channels = in_group_channels
     
     self.sample_rate = input_stream.params['sample_rate']
     self.total_channel = self.input_stream().params['shape'][1]
     
     self.mutex = Mutex()
コード例 #13
0
ファイル: eeg_openBCI.py プロジェクト: funshine/pyacq
    def __init__(self, outputs, serial_port, nb_channel, nb_aux):
        QtCore.QThread.__init__(self)
        self.outputs = outputs
        self.n = 0
        self.serial_port = serial_port
        self.packet_bsize = 3 + (nb_channel * 3) + (nb_aux * 2)
        self.chan_values = np.zeros((1, nb_channel), dtype=np.int64)
        self.aux_values = np.zeros((1, nb_aux), dtype=np.int64)
        self.count_lost_bytes = 0
        self.nb_channel = nb_channel
        self.nb_aux = nb_aux

        self.lock = Mutex()
        self.running = False
コード例 #14
0
    def _initialize(self):
        if not os.path.exists(self.dirname):
            os.mkdir(self.dirname)
        #~ self.files = []
        self.av_containers = []
        self.av_streams = []
        self.threads = []

        self.mutex = Mutex()

        self._stream_properties = collections.OrderedDict()

        for name, input in self.inputs.items():
            filename = os.path.join(self.dirname, name + '.avi')

            sr = input.params['sample_rate']

            # this fix problem inside PyAV
            sr = fractions.Fraction(sr).limit_denominator()

            av_container = av.open(filename, mode='w')
            av_stream = av_container.add_stream(self.codec_name, rate=sr)

            av_stream.width = input.params['shape'][1]
            av_stream.height = input.params['shape'][0]
            av_stream.pix_fmt = 'yuv420p'

            self.av_containers.append(av_container)
            self.av_streams.append(av_stream)

            #~ fid = open(filename, mode='wb')
            #~ self.files.append(fid)

            thread = ThreadRec(name, input, av_container, av_stream)
            self.threads.append(thread)
            thread.recv_start_index.connect(self.on_start_index)

            prop = {}
            for k in ('streamtype', 'dtype', 'shape', 'sample_rate'):
                prop[k] = input.params[k]
            self._stream_properties[name] = prop

        self._stream_properties['pyacq_version'] = pyacq_version

        self._flush_stream_properties()

        self._annotations = {}
コード例 #15
0
ファイル: audio_pyaudio.py プロジェクト: funshine/pyacq
    def _initialize(self):
        self.audiostream = self.pa.open(
            rate=int(self.sample_rate),
            channels=int(self.nb_channel),
            format=format_conv[self.format],
            input=self.input_device_index is not None,
            output=self.output_device_index is not None,
            input_device_index=self.input_device_index,
            output_device_index=self.output_device_index,
            frames_per_buffer=self._chunksize,
            stream_callback=self._audiocallback,
            start=False)

        # outbuffer
        size = self.nb_channel * self._chunksize * np.dtype(
            self.format).itemsize
        self.empty_outputbuffer = b'\x00' * size
        self.out_queue = collections.deque()
        self.lock = Mutex()

        if self.output_device_index is not None:
            self.thread = ThreadPollInput(self.input, return_data=True)
            self.thread.new_data.connect(self._new_output_buffer)
コード例 #16
0
ファイル: mainwindow.py プロジェクト: samuelgarcia/idephyx
    def __init__(self, configuration_file=None):
        QT.QMainWindow.__init__(self)

        self.setDockNestingEnabled(True)

        self.configured = False
        self.docks = {}
        self.conf = {}

        self.create_toolbar()
        #~ self.create_layout()

        self.timer_auto_scale = QT.QTimer(singleShot=True, interval=500)
        self.timer_auto_scale.timeout.connect(self.auto_scale_all)

        self.timer_rec = QT.QTimer(singleShot=False, interval=200)
        self.timer_rec.timeout.connect(self.refresh_rec_duration)

        self.is_recording = False
        self.is_running = False
        self.mutex = Mutex()

        self.configuration_file = configuration_file
        self.open_settings()
コード例 #17
0
 def __init__(self, dev_handle, parent=None):
     QtCore.QThread.__init__(self, parent=parent)
     self.lock = Mutex()
     self.running = False
     self.dev_handle = dev_handle
コード例 #18
0
ファイル: qtimefreq.py プロジェクト: Enchufa2/pyacq
    def _initialize(self, ):
        self.sample_rate = sr = self.input.params['sample_rate']
        d0, d1 = self.input.params['shape']
        self.nb_channel = self.input.params['nb_channel']
        
        # create proxy input to ensure sharedarray with time axis 1
        if self.input.params['transfermode'] == 'sharedarray' and self.input.params['timeaxis'] == 1:
            self.conv = None
        else:
            # if input is not transfermode creat a proxy
            if self.local_workers:
                self.conv = StreamConverter()
            else:
                ng = self.nodegroup_friends[-1]
                self.conv = ng.create_node('StreamConverter')
                self.conv.ng_proxy = ng
            self.conv.configure()

            # the inputstream is not needed except for parameters
            input_spec = dict(self.input.params)
            self.conv.input.connect(input_spec)
            
            if self.input.params['timeaxis']==0:
                new_shape = (d1, d0)
            else:
                new_shape = (d0, d1)
            self.conv.output.configure(protocol='tcp', interface='127.0.0.1', port='*', dtype='float32',
                   transfermode='sharedarray', streamtype='analogsignal', shape=new_shape, timeaxis=1, 
                   compression='', scale=None, offset=None, units='',
                   sharedarray_shape=(self.nb_channel, int(sr*self.max_xsize)), ring_buffer_method = 'double',
                   )
            self.conv.initialize()
            
        self.workers = []
        self.input_maps = []

        self.global_poller = ThreadPollInput(input_stream=self.input)
        self.global_timer = QtCore.QTimer(interval=500)
        self.global_timer.timeout.connect(self.compute_maps)
        
        if not self.local_workers:
            self.map_pollers = []
        
        for i in range(self.nb_channel):
            
            # create worker
            if self.local_workers:
                worker = TimeFreqWorker()
            else:
                ng = self.nodegroup_friends[i%max(len(self.nodegroup_friends)-1, 1)]
                worker = ng.create_node('TimeFreqWorker')
                worker.ng_proxy = ng
            worker.configure(max_xsize=self.max_xsize, channel=i, local=self.local_workers)
            worker.input.connect(self.conv.output)
            if self.local_workers:
                protocol = 'inproc'
            else:
                protocol = 'tcp'
            worker.output.configure(protocol=protocol, transfermode='plaindata')
            worker.initialize()
            self.workers.append(worker)
            
            # socket stream for maps from worker
            input_map = InputStream()
            out_params = worker.output.params
            if not isinstance(out_params, dict):
                # worker is remote; request attribute from remote process.
                out_params = out_params._get_value()
            else:
                # copy to prevent modification
                out_params = dict(out_params)
            stream_spec = out_params
            input_map.connect(worker.output)
            self.input_maps.append(input_map)
            if self.local_workers:
                worker.wt_map_done.connect(self.on_new_map_local)
            else:
                poller = ThreadPollInput(input_stream=input_map)
                poller.new_data.connect(self.on_new_map_socket)
                poller.chan = i
                self.map_pollers.append(poller)
        
        # This is used to diffred heavy action whena changing params (setting plots, compute wavelet, ...)
        # this avoid overload on CPU if multiple changes occurs in a short time
        self.mutex_action = Mutex()
        self.actions = OrderedDict([(self.create_grid, False),
                                                    (self.initialize_time_freq, False),
                                                    (self.initialize_plots, False),
                                                    ])
        self.timer_action = QtCore.QTimer(singleShot=True, interval=300)
        self.timer_action.timeout.connect(self.apply_actions)
        
        # Create parameters
        all = []
        for i in range(self.nb_channel):
            name = 'Signal{}'.format(i)
            all.append({'name': name, 'type': 'group', 'children': self._default_by_channel_params})
        self.by_channel_params = pg.parametertree.Parameter.create(name='AnalogSignals', type='group', children=all)
        self.params = pg.parametertree.Parameter.create(name='Global options',
                                                    type='group', children=self._default_params)
        self.all_params = pg.parametertree.Parameter.create(name='all param',
                                    type='group', children=[self.params,self.by_channel_params])
        self.params.param('xsize').setLimits([16./sr, self.max_xsize*.95]) 
        self.all_params.sigTreeStateChanged.connect(self.on_param_change)
        
        if self.with_user_dialog:
            self.params_controller = TimeFreqController(parent=self, viewer=self)
            self.params_controller.setWindowFlags(QtCore.Qt.Window)
        else:
            self.params_controller = None
        
        self.create_grid()
        self.initialize_time_freq()
        self.initialize_plots()
コード例 #19
0
ファイル: qtimefreq.py プロジェクト: zoeith/pyacq
    def _initialize(self, ):
        assert len(self.input.params['shape']) == 2, 'Are you joking ?'
        self.sample_rate = sr = self.input.params['sample_rate']
        self.nb_channel = self.input.params['shape'][1]
        buf_size = int(self.input.params['sample_rate'] * self.max_xsize)

        # channel names
        channel_info = self.inputs['signals'].params.get('channel_info', None)
        if channel_info is None:
            self.channel_names = [
                'ch{}'.format(c) for c in range(self.nb_channel)
            ]
        else:
            self.channel_names = [ch_info['name'] for ch_info in channel_info]

        # create proxy input to ensure sharedarray with time axis 1
        if self.input.params['transfermode'] == 'sharedmem' and self.input.params['axisorder'] is not None \
                and tuple(self.input.params['axisorder']) == (1,0):
            self.conv = None
            # TODO raise here
        else:
            # if input is not transfermode creat a proxy
            if self.local_workers:
                self.conv = StreamConverter()
            else:
                ng = self.nodegroup_friends[-1]
                self.conv = ng.create_node('StreamConverter')
                self.conv.ng_proxy = ng
            self.conv.configure()

            # the inputstream is not needed except for parameters
            input_spec = dict(self.input.params)
            self.conv.input.connect(input_spec)

            self.conv.output.configure(
                protocol='tcp',
                interface='127.0.0.1',
                port='*',
                dtype='float32',
                transfermode='sharedmem',
                streamtype='analogsignal',
                buffer_size=buf_size,
                axisorder=[1, 0],
                shape=(-1, self.nb_channel),
                double=True,
                fill=0,
            )
            self.conv.initialize()

        self.workers = []
        self.input_maps = []

        #~ self.global_poller = ThreadPollInput(input_stream=self.input, return_data=None) # only valid when no conv
        self.global_poller = ThreadPollOutput(output_stream=self.conv.output,
                                              return_data=False)
        self.global_timer = QtCore.QTimer(interval=500)
        self.global_timer.timeout.connect(self.compute_maps)

        if not self.local_workers:
            self.map_pollers = []

        for i in range(self.nb_channel):

            # create worker
            if self.local_workers:
                worker = TimeFreqWorker()
            else:
                ng = self.nodegroup_friends[i % max(
                    len(self.nodegroup_friends) - 1, 1)]
                worker = ng.create_node('TimeFreqWorker')
                worker.ng_proxy = ng
            worker.configure(channel=i, local=self.local_workers)
            worker.input.connect(self.conv.output)
            if self.local_workers:
                protocol = 'inproc'
            else:
                protocol = 'tcp'
            worker.output.configure(protocol=protocol,
                                    transfermode='plaindata')
            worker.initialize()
            self.workers.append(worker)

            # socket stream for maps from worker
            input_map = InputStream()
            out_params = worker.output.params
            if not isinstance(out_params, dict):
                # worker is remote; request attribute from remote process.
                out_params = out_params._get_value()
            else:
                # copy to prevent modification
                out_params = dict(out_params)
            stream_spec = out_params
            input_map.connect(worker.output)
            self.input_maps.append(input_map)
            if self.local_workers:
                worker.wt_map_done.connect(self.on_new_map_local)
            else:
                poller = ThreadPollInput(input_stream=input_map,
                                         return_data=True)
                poller.new_data.connect(self.on_new_map_socket)
                poller.chan = i
                self.map_pollers.append(poller)

        # This is used to diffred heavy action whena changing params (setting plots, compute wavelet, ...)
        # this avoid overload on CPU if multiple changes occurs in a short time
        self.mutex_action = Mutex()
        self.actions = OrderedDict([
            (self.create_grid, False),
            (self.initialize_time_freq, False),
            (self.initialize_plots, False),
        ])
        self.timer_action = QtCore.QTimer(singleShot=True, interval=300)
        self.timer_action.timeout.connect(self.apply_actions)

        # Create parameters
        all = []
        for i in range(self.nb_channel):
            by_chan_p = [{
                'name': 'label',
                'type': 'str',
                'value': self.channel_names[i],
                'readonly': True
            }] + list(self._default_by_channel_params)
            all.append({
                'name': 'ch{}'.format(i),
                'type': 'group',
                'children': by_chan_p
            })
        self.by_channel_params = pg.parametertree.Parameter.create(
            name='AnalogSignals', type='group', children=all)
        self.params = pg.parametertree.Parameter.create(
            name='Global options', type='group', children=self._default_params)
        self.all_params = pg.parametertree.Parameter.create(
            name='all param',
            type='group',
            children=[self.params, self.by_channel_params])
        self.params.param('xsize').setLimits([16. / sr, self.max_xsize * .95])
        self.all_params.sigTreeStateChanged.connect(self.on_param_change)

        if self.with_user_dialog:
            self.params_controller = TimeFreqController(parent=self,
                                                        viewer=self)
            self.params_controller.setWindowFlags(QtCore.Qt.Window)
        else:
            self.params_controller = None

        self.create_grid()
        self.initialize_time_freq()
        self.initialize_plots()
コード例 #20
0
 def __init__(self, **kargs):
     QOscilloscope.__init__(self, **kargs)
     self.mutex = Mutex()
コード例 #21
0
ファイル: triggeraccumulator.py プロジェクト: zoeith/pyacq
    def __init__(self, input_stream, **kargs):
        ThreadPollInput.__init__(self, input_stream, **kargs)

        self.limit_lock = Mutex()
        self.limit_indexes = []