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


Python Recorder.stop_recording方法代码示例

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


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

示例1: start

# 需要导入模块: from recorder import Recorder [as 别名]
# 或者: from recorder.Recorder import stop_recording [as 别名]
    def start(self):
        # Init the amp
        print 'Initializing the amp...'
        recorder = Recorder('lslamp', params.FREQ_S, params.LEN_REC_BUF_SEC, params.NUM_CHANNELS)
        thread_rec = threading.Thread(target=recorder.record)
        thread_rec.start()

        # Start plotting
        plt.show()
        #thread_plot = threading.Thread(target=self.plot_live)
        #thread_plot.start()

        # Get and display data from the amp
        counter = 0
        while not is_terminate_requested:

            data_last_chunk = recorder.get_new_data(params.LEN_DATA_CHUNK_READ, params.AMP_WAIT_SEC)
            recorder.acknowledge_new_data()
            print 'recorder.new_data_counter:', recorder.new_data_counter
            #print 'data_last_chunk.shape: ', data_last_chunk.shape

            # Position the older data to the beginning of the buffer
            self.X_buf[0:(self.len_buf - params.LEN_DATA_CHUNK_READ)]\
                    = self.X_buf[params.LEN_DATA_CHUNK_READ:]

            # Insert the new data into the buffer
            self.X_buf[(self.len_buf - params.LEN_DATA_CHUNK_READ):]\
                    = data_last_chunk

            #i_row_from = int((counter*params.LEN_DATA_CHUNK_READ) % self.len_buf)
            #i_row_to = int(((counter+1)*params.LEN_DATA_CHUNK_READ) % self.len_buf)
            #if i_row_to == 0:
            #    i_row_to = self.len_buf
            #print 'i_row_from, i_row_to:', i_row_from, i_row_to
            #self.X_buf[i_row_from: i_row_to] = data_last_chunk
            #print 'X_buf[i_row_from: i_row_to]:\n', self.X_buf[i_row_from: i_row_to]

            if counter % 2 == 0:
                self.plot_live()

            counter += 1

        # End of while

        # Stop the amp
        recorder.stop_recording()
开发者ID:kristofvarszegi,项目名称:mibbci,代码行数:48,代码来源:eeg_monitor.py

示例2: cursor_func

# 需要导入模块: from recorder import Recorder [as 别名]
# 或者: from recorder.Recorder import stop_recording [as 别名]

#.........这里部分代码省略.........
    # Initialize the amplifier
    if not is_simulation_mode:
        print 'Initializing the amp...'
        recorder = Recorder('lslamp', freq_sampling, params.LEN_REC_BUF_SEC, num_signal_channels)
        thread_rec = threading.Thread(target=recorder.record)
        thread_rec.start()

    # Cursor control loop
    X_raw_buf_live = np.zeros((int(freq_sampling*params.LEN_REC_BUF_SEC), num_signal_channels))
    label_buf_live = np.zeros((int(freq_sampling*params.LEN_REC_BUF_SEC), num_event_types))
    counter = 0
    #while True:
    while counter < (params.LEN_REC_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ):
        print 'counter: ', counter

        # Clear the canvas
        win.delete('all')

        if not is_simulation_mode:
            # Wait for new data and get it
            data_last_chunk = recorder.get_new_data(params.LEN_DATA_CHUNK_READ, params.AMP_WAIT_SEC)
            recorder.acknowledge_new_data()
            print 'recorder.new_data_counter:', recorder.new_data_counter
        else:
            time.sleep(1.0 / (freq_sampling/params.LEN_DATA_CHUNK_READ))
            data_last_chunk = 1000.0 * np.random.rand(int(params.LEN_DATA_CHUNK_READ), num_signal_channels)
            #print 'Random data_last_chunk size:', data_last_chunk

        # Insert the new sample into our time series
        i_row_lb = int((counter+len_padding)*params.LEN_DATA_CHUNK_READ)
        i_row_ub = int((counter+len_padding+1)*params.LEN_DATA_CHUNK_READ)
        X_raw_buf_live[i_row_lb:i_row_ub, :] = data_last_chunk
        #print 'data_last_chunk:', data_last_chunk
        label_buf_live[i_row_lb:i_row_ub, :]\
                = cursor_event_list[counter % int(params.LEN_PERIOD_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)]

        # Calculating cursor step
        i_row_ub = int((counter+len_padding+1)*params.LEN_DATA_CHUNK_READ)
        i_row_lb = i_row_ub - int(window_size_in_samples)
        if i_row_lb >= 0:
            #print 'i_row_lb, i_row_ub:', i_row_lb, i_row_ub
            #print 'X_raw_buf_live[i_row_lb:i_row_ub, :].shape:', X_raw_buf_live[i_row_lb:i_row_ub, :].shape
            if is_control_mode:
                X_window = utils.preprocess(X_raw_buf_live[i_row_lb:i_row_ub, :], scaler)
                X_in = TimeSeriesBatchIterator.create_X_instance(X_window, conv_dim=1)
                X_in = X_in.reshape(1, X_in.shape[0], X_in.shape[1])
                #print 'X_window.shape:', X_window.shape
                #print 'X_in.shape:', X_in.shape
                cursor_step = calc_cursor_step(nnet, X_in.astype(np.float32))
            else:
                #X_window = X_raw_buf_live[i_row_lb:i_row_ub, :]
                cursor_step = 0

            cursor_pos = cursor_pos_prev + np.array([cursor_step, 0])
            #print 'cursor_pos: ', cursor_pos

        else:
            cursor_pos = cursor_pos_prev

        cursor_pos_point = graphics.Point(cursor_pos[0], cursor_pos[1])
        cursor_pos_prev = cursor_pos
        cursor = graphics.Circle(cursor_pos_point, cursor_radius)
        color_temp = cursor_color_arr_final[counter % int(params.LEN_PERIOD_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)]
        cursor.setFill(graphics.color_rgb(color_temp[0], color_temp[1], color_temp[2]))
        cursor.setOutline(graphics.color_rgb(color_temp[0], color_temp[1], color_temp[2]))
        cursor.draw(win)

        counter += 1

        # End of if
    # End of while

    # Stop recording
    recorder.stop_recording()

    # Close the window
    win.close()

    # Cut the padding from the data
    i_row_lb = int(len_padding * params.LEN_DATA_CHUNK_READ)
    i_row_ub = int((counter+len_padding)*params.LEN_DATA_CHUNK_READ)
    X_raw_buf_cut = X_raw_buf_live[i_row_lb:i_row_ub, :]
    label_buf_cut = label_buf_live[i_row_lb:i_row_ub, :]

    # Save data to file
    time_axis = np.arange(X_raw_buf_cut.shape[0]).reshape((X_raw_buf_cut.shape[0], 1))
    print 'time_axis.shape:', time_axis.shape
    data_merged = np.concatenate((time_axis, X_raw_buf_cut, label_buf_cut), axis=1)
    print 'data_merged.shape: ', data_merged.shape
    time_save = datetime.now()
    np.savetxt('../data/MIBBCI_REC_{0}Hz_{1}{2:02}{3:02}_{4:02}h{5:02}m{6:02}s_RAW.csv'.format(
            int(freq_sampling),
            time_save.year, time_save.month, time_save.day,
            time_save.hour, time_save.minute, time_save.second),
            X=data_merged, fmt='%.8f', delimiter=",",
            header='time, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, red, blue, idle',
            comments='')


    print 'cursor_func(.) terminates.'
开发者ID:kristofvarszegi,项目名称:mibbci,代码行数:104,代码来源:bci_cursor.py


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