コード例 #1
0
    def _initiate_stream(self):
        # outlet needs to be made on the same process
        pylsl = _check_pylsl_installed(strict=True)
        self._streaming = True
        info = pylsl.StreamInfo(name='MNE',
                                type=self._ch_type.upper(),
                                channel_count=self._raw.info['nchan'],
                                nominal_srate=self._sfreq,
                                channel_format='float32',
                                source_id=self._host)
        info.desc().append_child_value("manufacturer", "MNE")
        channels = info.desc().append_child("channels")
        for ch in self._raw.info['chs']:
            unit = ch['unit']
            keys, values = zip(*list(constants.FIFF.items()))
            unit = keys[values.index(unit)]
            channels.append_child("channel") \
                    .append_child_value("label", ch['ch_name']) \
                    .append_child_value("type", self._ch_type.lower()) \
                    .append_child_value("unit", unit)

        # next make an outlet
        outlet = pylsl.StreamOutlet(info)

        # let's make some data
        counter = 0
        while self._streaming:
            mysample = self._raw[:, counter][0].ravel().tolist()
            # now send it and wait for a bit
            outlet.push_sample(mysample)
            counter = 0 if counter == self._raw.last_samp else counter + 1
            time.sleep(self._time_dilation / self._sfreq)
コード例 #2
0
    def _connect(self):
        # To use this function with an LSL stream which has a 'name' but no
        # 'source_id', change the keyword in pylsl.resolve_byprop accordingly.
        pylsl = _check_pylsl_installed(strict=True)
        stream_info = pylsl.resolve_byprop('source_id',
                                           self.host,
                                           timeout=self.wait_max)[0]
        self.client = pylsl.StreamInlet(info=stream_info,
                                        max_buflen=self.buffer_size)

        return self
コード例 #3
0
ファイル: lsl_client.py プロジェクト: larsoner/mne-realtime
    def _connect(self):
        # To use this function with an LSL stream which has a 'name' but no
        # 'source_id', change the keyword in pylsl.resolve_byprop accordingly.
        pylsl = _check_pylsl_installed(strict=True)
        print(f'Looking for LSL stream {self.host}...')
        # resolve_byprop is a bit fragile
        streams = pylsl.resolve_streams(wait_time=min(0.1, self.wait_max))
        ids = list()
        for stream_info in streams:
            ids.append(stream_info.source_id())
            if ids[-1] == self.host:
                break
        else:
            raise RuntimeError(f'{self.host} not found in streams: {ids}')
        print(f'Found stream {repr(stream_info.name())} via '
              f'{stream_info.source_id()}...')
        self.client = pylsl.StreamInlet(info=stream_info,
                                        max_buflen=self.buffer_size)

        return self
コード例 #4
0
    def _initiate_stream(self):
        # outlet needs to be made on the same process
        pylsl = _check_pylsl_installed(strict=True)
        self._streaming = True
        info = pylsl.StreamInfo(name='MNE',
                                type=self._ch_type.upper(),
                                channel_count=self._raw.info['nchan'],
                                nominal_srate=self._sfreq,
                                channel_format='float32',
                                source_id=self._host)
        info.desc().append_child_value("manufacturer", "MNE")
        channels = info.desc().append_child("channels")
        for ch in self._raw.info['chs']:
            unit = ch['unit']
            keys, values = zip(*list(constants.FIFF.items()))
            unit = keys[values.index(unit)]
            channels.append_child("channel") \
                    .append_child_value("label", ch['ch_name']) \
                    .append_child_value("type", self._ch_type.lower()) \
                    .append_child_value("unit", unit)

        # next make an outlet
        outlet = pylsl.StreamOutlet(info)

        # let's make some data
        counter = 0
        delta = self._time_dilation / self._sfreq  # desired push step
        next_t = time.time()
        every = max(int(round(self._sfreq)), 1)
        while self._streaming:
            mysample = self._raw[:, counter][0].ravel()
            # now send it and wait for a bit
            if self._status and counter % every == 0:
                print(f'Sending sample {counter} on {self._host}, '
                      f'have_consumers={outlet.have_consumers()}')
            outlet.push_sample(mysample)
            counter = 0 if counter == self._raw.last_samp else counter + 1
            next_t += delta
            sleep = next_t - time.time()
            if sleep > 0:
                time.sleep(sleep)
コード例 #5
0
ファイル: lsl_client.py プロジェクト: larsoner/mne-realtime
 def _connection_error(self):
     pylsl = _check_pylsl_installed(strict=True)
     extra = (f' Available streams on {self.host} from resolve_streams():\n'
              f'{pylsl.resolve_streams()}')
     super()._connection_error(extra)