当前位置: 首页>>代码示例>>Python>>正文


Python StreamInlet.pull_chunk方法代码示例

本文整理汇总了Python中pylsl.StreamInlet.pull_chunk方法的典型用法代码示例。如果您正苦于以下问题:Python StreamInlet.pull_chunk方法的具体用法?Python StreamInlet.pull_chunk怎么用?Python StreamInlet.pull_chunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pylsl.StreamInlet的用法示例。


在下文中一共展示了StreamInlet.pull_chunk方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BetaInlet

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
class BetaInlet(object):
    def __init__(self):
        print("looking for an EEG stream...")
        streams = resolve_byprop("type", "EEG")

        # create a new inlet to read from the stream
        proc_flags = proc_clocksync | proc_dejitter | proc_monotonize
        self.inlet = StreamInlet(streams[0], processing_flags=proc_flags)

        # The following is an example of how to read stream info
        stream_info = self.inlet.info()
        stream_Fs = stream_info.nominal_srate()
        stream_xml = stream_info.desc()
        chans_xml = stream_xml.child("channels")
        chan_xml_list = []
        ch = chans_xml.child("channel")
        while ch.name() == "channel":
            chan_xml_list.append(ch)
            ch = ch.next_sibling("channel")
        self.channel_names = [ch_xml.child_value("label") for ch_xml in chan_xml_list]
        print("Reading from inlet named {} with channels {} sending data at {} Hz".format(stream_info.name(),
                                                                                          self.channel_names, stream_Fs))

    def update(self):
        max_samps = 3276*2
        data = np.nan * np.ones((max_samps, len(self.channel_names)), dtype=np.float32)
        _, timestamps = self.inlet.pull_chunk(max_samples=max_samps, dest_obj=data)
        data = data[:len(timestamps), :]
        print("Beta inlet retrieved {} samples.".format(len(timestamps)))
        return data, np.asarray(timestamps)
开发者ID:cboulay,项目名称:labstreaminglayer,代码行数:32,代码来源:PerformanceTest.py

示例2: __init__

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
class LSLInlet:
    def __init__(self, name=LSL_STREAM_NAMES[2], max_chunklen=8, n_channels=20):
        streams = resolve_byprop('name', name, timeout=LSL_RESOLVE_TIMEOUT)
        self.inlet = None
        self.dtype = 'float64'
        if len(streams) > 0:
            self.inlet = StreamInlet(streams[0], max_buflen=1, max_chunklen=max_chunklen)
            # self.dtype = fmt2string[self.inlet.info().channel_format()]
            print(self.dtype)
        self.n_channels = n_channels if n_channels else self.inlet.info().channel_count()

    def get_next_chunk(self):
        # get next chunk
        chunk, timestamp = self.inlet.pull_chunk()
        # convert to numpy array
        chunk = np.array(chunk, dtype=self.dtype)
        # return first n_channels channels or None if empty chunk
        return chunk[:, :self.n_channels] if chunk.shape[0] > 0 else None

    def update_action(self):
        pass

    def save_info(self, file):
        with open(file, 'w') as f:
            f.write(self.inlet.info().as_xml())

    def get_frequency(self):
        return self.inlet.info().nominal_srate()

    def get_n_channels(self):
        return self.n_channels

    def get_channels_labels_bad(self):
        time.sleep(0.001)
        labels = []
        ch = self.inlet.info().desc().child("channels").child("channel")
        for k in range(self.get_n_channels()):
            labels.append(ch.child_value("label"))
            ch = ch.next_sibling()
        return

    def get_channels_labels(self):
        return ch_names[:self.n_channels]

    def disconnect(self):
        del self.inlet
        self.inlet = None
开发者ID:nikolaims,项目名称:nfb,代码行数:49,代码来源:lsl_inlet_n_channels.py

示例3: MarkerInlet

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
class MarkerInlet(object):
    def __init__(self):
        self.task = {'phase':'precue', 'class':1, 'target':1}
        print("Looking for stream with type Markers")
        streams = resolve_bypred("type='Markers'", minimum=1)
        proc_flags = 0  # Marker events are relatively rare. No need to post-process.
        self.inlet = StreamInlet(streams[0], processing_flags=proc_flags)
        # The following is an example of how to read stream info
        stream_info = self.inlet.info()
        stream_Fs = stream_info.nominal_srate()
        stream_xml = stream_info.desc()
        chans_xml = stream_xml.child("channels")
        chan_xml_list = []
        ch = chans_xml.child("channel")
        while ch.name() == "channel":
            chan_xml_list.append(ch)
            ch = ch.next_sibling("channel")
        stream_ch_names = [ch_xml.child_value("label") for ch_xml in chan_xml_list]
        print("Reading from inlet named {} with channels {}".format(stream_info.name(), stream_ch_names))

    def update(self):
        marker_samples, marker_timestamps = self.inlet.pull_chunk(timeout=0.0)
        if (marker_timestamps):
            [phase_str, class_str, targ_str] = marker_samples[-1][0].split(', ')
            if phase_str in ['TargetCue']:
                self.task['phase'] = 'cue'
            elif phase_str in ['GoCue']:
                self.task['phase'] = 'go'
            elif phase_str in ['Miss', 'Hit']:
                self.task['phase'] = 'evaluate'
            elif phase_str[:8] == 'NewTrial':
                self.task['phase'] = 'precue'
            else:
                print(phase_str)
            self.task['class'] = int(class_str.split(' ')[1])
            self.task['target'] = int(targ_str.split(' ')[1])
            print("Marker inlet updated with task {}".format(self.task))
开发者ID:cboulay,项目名称:labstreaminglayer,代码行数:39,代码来源:PerformanceTest.py

示例4: print

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]

# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = resolve_stream('type', 'Data')

# create a new inlet to read from the stream
inlet = StreamInlet(streams[0])

globalstart = time.time()

while (time.time() - globalstart < exptime):
    
    startwhile = time.time()

    chunk, timestamp = inlet.pull_chunk()
    np_ar_chunk = np.asarray(chunk)
    chunk_size = np_ar_chunk.shape[0]
    
    if chunk_size > 0:
        
        data_chunk_test = np_ar_chunk.T
        
        received_data_buf[:,pos:(pos+chunk_size)] = data_chunk_test
        pos = pos + chunk_size + 1
        
        [data_chunk_test,Zlast_pre_high[0,:,:]] = spsig.lfilter(b_pre_high[0], a_pre_high[0], data_chunk_test, 1, Zlast_pre_high[0,:,:])
        [data_chunk_test,Zlast_pre_low[0,:,:]] = spsig.lfilter(b_pre_low[0], a_pre_low[0], data_chunk_test, 1, Zlast_pre_low[0,:,:])
        
        data_chunk_test = data_chunk_test[without_emp_mask,:]
        #chan_names_test_used = chan_names_test[:,without_emp_mask]
开发者ID:nikolaims,项目名称:nfb,代码行数:32,代码来源:runmain2.py

示例5: len

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
    # Name of our channel for plotting purposes
    ch_names = [ch_names[i] for i in index_channel]
    n_channels = len(index_channel)

    # Get names of features
    # ex. ['delta - CH1', 'pwr-theta - CH1', 'pwr-alpha - CH1',...]
    feature_names = BCIw.get_feature_names(ch_names)

    # Number of seconds to collect training data for (one class)
    training_length = 20

    """ 3. RECORD TRAINING DATA """

    # Record data for mental activity 0
    BCIw.beep()
    eeg_data0, timestamps0 = inlet.pull_chunk(
            timeout=training_length+1, max_samples=fs * training_length)
    eeg_data0 = np.array(eeg_data0)[:, index_channel]

    print('\nClose your eyes!\n')

    # Record data for mental activity 1
    BCIw.beep()  # Beep sound
    eeg_data1, timestamps1 = inlet.pull_chunk(
            timeout=training_length+1, max_samples=fs * training_length)
    eeg_data1 = np.array(eeg_data1)[:, index_channel]

    # Divide data into epochs
    eeg_epochs0 = BCIw.epoch(eeg_data0, epoch_length * fs,
                             overlap_length * fs)
    eeg_epochs1 = BCIw.epoch(eeg_data1, epoch_length * fs,
                             overlap_length * fs)
开发者ID:bcimontreal,项目名称:bci_workshop,代码行数:34,代码来源:exercise_02.py

示例6: print

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
                                       timeout=100)[0]
    print('GUI source discovered')

    #print(experiment_info, bci_info)

    experiment_inlet = StreamInlet(experiment_info)
    bci_inlet = StreamInlet(bci_info)

    bci_results = [[], []]
    experiment_results = [[], []]

    print('Recording')
    while True:
        # get a new sample (you can also omit the timestamp part if you're not
        # interested in it)
        bci_values, bci_timestamps = bci_inlet.pull_chunk(max_samples=device.sfreq * 60 *6)
        bci_results[0].extend(bci_values)
        bci_results[1].extend(bci_timestamps)

        experiment_values, experiment_timestamps = experiment_inlet.pull_chunk()
        experiment_results[0].extend(experiment_values)
        experiment_results[1].extend(experiment_timestamps)

        if len(experiment_results[0]) > 0 and experiment_results[0][-1][0] < 0:
            break

    experiment_results = np.hstack([np.array(experiment_results[1])[:, None],
                                    experiment_results[0]])
    np.savetxt(filename+'_experiment'+'.csv', experiment_results, delimiter=';')

    bci_results = np.hstack([np.array(bci_results[1])[:, None],
开发者ID:Egor-Krivov,项目名称:eegstream,代码行数:33,代码来源:experiment_recorder.py

示例7: print

# 需要导入模块: from pylsl import StreamInlet [as 别名]
# 或者: from pylsl.StreamInlet import pull_chunk [as 别名]
                                    1 / shift_length)

    """ 3. GET DATA """

    # The try/except structure allows to quit the while loop by aborting the
    # script with <Ctrl-C>
    print('Press Ctrl-C in the console to break the while loop.')

    try:
        # The following loop does what we see in the diagram of Exercise 1:
        # acquire data, compute features, visualize raw EEG and the features
        while True:

            """ 3.1 ACQUIRE DATA """
            # Obtain EEG data from the LSL stream
            eeg_data, timestamp = inlet.pull_chunk(
                    timeout=1, max_samples=int(shift_length * fs))

            # Only keep the channel we're interested in
            ch_data = np.array(eeg_data)[:, index_channel]

            # Update EEG buffer
            eeg_buffer, filter_state = BCIw.update_buffer(
                    eeg_buffer, ch_data, notch=True,
                    filter_state=filter_state)

            """ 3.2 COMPUTE FEATURES """
            # Get newest samples from the buffer
            data_epoch = BCIw.get_last_data(eeg_buffer,
                                            epoch_length * fs)

            # Compute features
开发者ID:bcimontreal,项目名称:bci_workshop,代码行数:34,代码来源:exercise_01_multichannel.py


注:本文中的pylsl.StreamInlet.pull_chunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。