本文整理匯總了Python中recorder.Recorder.get_new_data方法的典型用法代碼示例。如果您正苦於以下問題:Python Recorder.get_new_data方法的具體用法?Python Recorder.get_new_data怎麽用?Python Recorder.get_new_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類recorder.Recorder
的用法示例。
在下文中一共展示了Recorder.get_new_data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: start
# 需要導入模塊: from recorder import Recorder [as 別名]
# 或者: from recorder.Recorder import get_new_data [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()
示例2: cursor_func
# 需要導入模塊: from recorder import Recorder [as 別名]
# 或者: from recorder.Recorder import get_new_data [as 別名]
def cursor_func(
freq_sampling,
num_signal_channels,
num_event_types,
window_size_in_samples):
logging.debug('%s cursor_func(.) entered.', TAG)
len_padding = 5 * freq_sampling
cursor_radius = 26
w = 2 * math.pi / 10
# Initialize the time-domain filter
#numer, denom = get_time_domain_filters(8.0, 12.0, 0.5)
# Init the NN
if is_control_mode:
filename_base = '../models/MIBBCI_NN_medium_bestsofar'
filename_nn = filename_base + '.npz'
nnet = nnutils.load_nn(nnutils.create_nn_medium, filename_nn)
# Init the preproc stuff
if is_control_mode:
filename_p = filename_base + '.p'
scaler = cPickle.load(open(filename_p, 'rb'))
print 'Loaded scaler.mean_, scaler.var_:', scaler.mean_, scaler.var_
# Init graphics
win = graphics.GraphWin('Cursor', params.IMAGE_W, params.IMAGE_H)
cursor = graphics.Circle(graphics.Point(params.IMAGE_W/2, params.IMAGE_H/2), cursor_radius)
cursor.setFill(graphics.color_rgb(params.CURSOR_COLOR_REST[0], params.CURSOR_COLOR_REST[1], params.CURSOR_COLOR_REST[2]))
cursor.setOutline(graphics.color_rgb(params.CURSOR_COLOR_REST[0], params.CURSOR_COLOR_REST[1], params.CURSOR_COLOR_REST[2]))
cursor.draw(win)
cursor_pos_prev = np.array([params.IMAGE_W/2, params.IMAGE_H/2])
cursor_pos = cursor_pos_prev
# Init event labels
event_arr_right = np.zeros((params.LEN_DATA_CHUNK_READ, num_event_types))
event_arr_right[:, params.EVENT_ID_RH] = np.ones(params.LEN_DATA_CHUNK_READ)
event_arr_left = np.zeros((params.LEN_DATA_CHUNK_READ, num_event_types))
event_arr_left[:, params.EVENT_ID_LH] = np.ones(params.LEN_DATA_CHUNK_READ)
event_arr_idle = np.zeros((params.LEN_DATA_CHUNK_READ, num_event_types))
event_arr_idle[:, params.EVENT_ID_IDLE] = np.ones(params.LEN_DATA_CHUNK_READ)
#event_arr_calib = np.zeros((params.LEN_DATA_CHUNK_READ, num_event_types))
#event_arr_calib[:, 3] = np.ones(params.LEN_DATA_CHUNK_READ)
cursor_event_list = []
cursor_color_arr_raw = np.zeros((int(params.LEN_PERIOD_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ), 3))
color_counter = 0
for i in range(int(params.LEN_IDLE_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)):
cursor_color_arr_raw[color_counter, :] = params.CURSOR_COLOR_IDLE
cursor_event_list.append(event_arr_idle) # r, l, idle, calib
color_counter += 1
for i in range(int(params.LEN_RIGHT_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)):
cursor_color_arr_raw[color_counter, :] = params.CURSOR_COLOR_RIGHT
cursor_event_list.append(event_arr_right)
color_counter += 1
for i in range(int(params.LEN_IDLE_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)):
cursor_color_arr_raw[color_counter, :] = params.CURSOR_COLOR_IDLE
cursor_event_list.append(event_arr_idle)
color_counter += 1
for i in range(int(params.LEN_LEFT_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ)):
cursor_color_arr_raw[color_counter, :] = params.CURSOR_COLOR_LEFT
cursor_event_list.append(event_arr_left)
color_counter += 1
conv_window = np.ones((params.LEN_COLOR_CONV_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ, 1))\
/ (1 * int(params.LEN_COLOR_CONV_SEC * freq_sampling / params.LEN_DATA_CHUNK_READ))
cursor_color_arr_ud = np.flipud(cursor_color_arr_raw)
cursor_color_arr_ud_convd = signal.convolve(cursor_color_arr_ud.T, conv_window.T).T
cursor_color_arr_final = np.flipud(cursor_color_arr_ud_convd[0:cursor_color_arr_raw.shape[0], :])
if False:
plt.figure()
plt.plot(cursor_color_arr_raw)
#plt.plot(cursor_color_arr_ud[:, 0])
#plt.plot(cursor_color_arr_ud_convd[:, 0])
plt.plot(cursor_color_arr_final)
#plt.legend(['raw', 'ud', 'ud_convd', 'final'])
plt.show()
# 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)
#.........這裏部分代碼省略.........