def manage_nsp(self, on_off): f_name, m_name, l_name = self.parse_patient_name( self.subject_settings['name']) file_info = { 'filename': os.path.normpath( os.path.join( BASEPATH, self.subject_settings['id'], self.procedure_settings['date'].strftime('%m%d%y') + '_' + self.subject_settings['id'] + '_' + self.procedure_settings['target_name'] + '_' + self.procedure_settings['recording_config'])), 'comment': self.subject_settings['NSP_comment'], 'patient_info': { 'ID': self.subject_settings['id'], # if only single name, returned in l_name 'firstname': f_name if f_name else l_name, 'middlename': m_name, # TODO: implement MiddleName 'lastname': l_name, 'DOBMonth': self.subject_settings['birthday'].month, 'DOBDay': self.subject_settings['birthday'].day, 'DOBYear': self.subject_settings['birthday'].year } } if not CbSdkConnection().is_connected: CbSdkConnection().connect() return CbSdkConnection().set_recording_state(on_off, file_info)
def refresh_axes(self): last_sample_ix = int( np.mod(get_now_time(), self.plot_config['x_range']) * self.samplingRate) for line_label in self.segmented_series: ss_info = self.segmented_series[line_label] # Fixup axes plot = ss_info['plot'] plot.setXRange(0, self.plot_config['x_range'] * self.samplingRate) plot.setYRange(-self.plot_config['y_range'], self.plot_config['y_range']) plot.hideAxis('bottom') plot.hideAxis('left') # Reset data for seg_ix in range(self.plot_config['n_segments']): pci = plot.dataItems[seg_ix] old_x, old_y = pci.getData() pci.setData(x=old_x, y=np.zeros_like(old_x)) ss_info['last_sample_ix'] = last_sample_ix # Get channel info from cbpy to determine threshold cbsdkconn = CbSdkConnection() full_info = cbsdkconn.get_channel_info(ss_info['chan_id']) ss_info['thresh_line'].setValue(full_info['spkthrlevel'])
def on_thresh_line_moved(self, inf_line): for line_label in self.segmented_series: ss_info = self.segmented_series[line_label] if ss_info['thresh_line'] == inf_line: new_thresh = int(inf_line.getYPos()) cbsdkconn = CbSdkConnection() cbsdkconn.set_channel_info(ss_info['chan_id'], {'spkthrlevel': new_thresh})
def get_now_time(): # Attempt to synchronize different series using machine time. cbsdk_conn = CbSdkConnection() if cbsdk_conn.is_connected: now = cbsdk_conn.time() else: now = time.time() return now
def do_connect(self): from cerebuswrapper import CbSdkConnection con_params = { 'client-addr': self.lineEdit_client_ip.text(), 'client-port': self.spinBox_client_port.value(), 'inst-addr': self.lineEdit_inst_addr.text(), 'inst-port': self.spinBox_inst_port.value(), 'receive-buffer-size': self.spinBox_recv_buff.value() } cbsdkConn = CbSdkConnection( con_params=con_params) # Instance, so no need to return it. return cbsdkConn.connect()
def __init__(self): super(CustomGUI, self).__init__() self.cbsdk_conn = CbSdkConnection(simulate_ok=SIMOK) self.setup_ui() self.indicate_connection_state() self.plot_widget = None self.show()
def update(self): super(MyGUI, self).update() if self.ser.is_open: in_str = self.ser.readline().decode('utf-8').strip() if in_str: in_value = float(in_str) display_string = "{0:.3f}".format( in_value + self.doubleSpinBox_offset.value()) self.lcdNumber.display(display_string) cbsdk_conn = CbSdkConnection() if cbsdk_conn.is_connected and (display_string != self.display_string): cbsdk_conn.set_comments("DTT:" + display_string) self.display_string = display_string else: self.pushButton_send.setText("Send")
def indicate_connection_state(self): from cerebuswrapper import CbSdkConnection msg_str = CbSdkConnection().get_connection_state() if msg_str == 'Connected to NSP': self.action_Connect.setEnabled(False) elif msg_str == 'Not connected': self.action_Connect.setEnabled(True) self.statusBar().showMessage(msg_str)
def on_button(self, modality, region): import json from cerebuswrapper import CbSdkConnection if modality == 'Other': other_text = self.lineEdit_Other.text() if len(other_text) > 0: modality = other_text comment_dict = { 'Side': 'L' if self.radioButton_L.isChecked() else 'R', 'Region': region, 'Modality': modality } conn = CbSdkConnection() if conn.is_connected: comment_string = json.dumps(comment_dict, sort_keys=True) conn.set_comments(comment_string) self.statusBar().showMessage("Sent: " + comment_string)
def on_monitor_group_clicked(self, button_id): self.reset_audio() if button_id == 0: self.audio['chan_label'] = 'silence' monitor_chan_id = 0 else: self.audio['chan_label'] = self.group_info[button_id - 1]['label'] monitor_chan_id = self.group_info[button_id - 1]['chan'] CbSdkConnection().monitor_chan(monitor_chan_id)
def on_open_clicked(self): com_port = self.comboBox_com_port.currentText() cmd_text = self.pushButton_open.text() if cmd_text == 'Open': if com_port == "cbsdk playback": CbSdkConnection().connect() CbSdkConnection().cbsdk_config = { 'reset': True, 'get_events': False, 'get_comments': True, 'buffer_parameter': { 'comment_length': 10 } } self.pushButton_open.setText("Close") else: if self.chk_NSP.isEnabled() and self.chk_NSP.isChecked(): CbSdkConnection().connect() CbSdkConnection().cbsdk_config = { 'reset': True, 'get_events': False, 'get_comments': False } if not self.ser.is_open: self.ser.port = com_port try: self.ser.open() # TODO: Add timeout; Add error. self.ser.write('AXON+\r'.encode()) except serial.serialutil.SerialException: print("Could not open serial port") finally: self.pushButton_open.setText( "Close" if self.ser.is_open else "Open") else: self._do_close(com_port)
def process_settings(self, sub_sett, proc_sett, depth_sett, feat_sett): self.subject_settings = dict(sub_sett) self.procedure_settings = dict(proc_sett) self.depth_settings = dict(depth_sett) self.features_settings = dict(feat_sett) # validate that we have some data in the electrode_settings. If the NSP is not connected we will have # to load the channel names from the DB. Also we want to keep the FeaturesGUI unaware of the DB channels. if len(self.depth_settings['electrode_settings']) == 0: self.depth_settings['electrode_settings'] = {} for lbl in DBWrapper().list_channel_labels(): self.depth_settings['electrode_settings'][lbl] = DEPTHSETTINGS CbSdkConnection().is_simulating = True # set new features self.feature_select.setCurrentIndex(0) # Raw while self.feature_select.count() > 2: # Raw and Mapping self.feature_select.removeItem(2) self.feature_select.addItems(self.features_settings['features'].keys()) # set new channels self.chan_select.setCurrentIndex(0) # None while self.chan_select.count() > 1: self.chan_select.removeItem(1) self.chan_select.addItems( self.depth_settings['electrode_settings'].keys()) # clear and update stacked widget to_delete = [ self.plot_stack.widget(x) for x in range(self.plot_stack.count()) ] for wid in to_delete: self.plot_stack.removeWidget(wid) wid.deleteLater() wid = None self.stack_dict = {} self.create_plots() self.depth_wrapper.send_settings(self.depth_settings) self.features_wrapper.send_settings(self.features_settings) if not self.features_process_running: self.manage_feature_process(True) # self.clear() self.read_from_shared_memory()
def _do_close(self, from_port): if from_port == "cbsdk playback": CbSdkConnection().disconnect() else: self.ser.close() self.pushButton_open.setText("Open")
def start_sending_cbsdk(self): if CbSdkConnection().connect() == 0: self.pushButton_send.setDisabled(True)
def update(self): # Added new_value handling for playback if we ever want to post-process depth # on previously recorded sessions. new_value = False out_value = None if self.comboBox_com_port.currentText() == "cbsdk playback": cbsdk_conn = CbSdkConnection() if cbsdk_conn.is_connected: comments = cbsdk_conn.get_comments() if comments: comment_strings = [x[1].decode('utf8') for x in comments] else: comment_strings = "" dtts = [] for comm_str in comment_strings: if 'DTT:' in comm_str: dtts.append(float(comm_str[4:])) if len(dtts) > 0: out_value = dtts[-1] new_value = True self.offset_ddu.display("{0:.3f}".format(out_value)) offset = self.doubleSpinBox_offset.value() self.raw_ddu.display("{0:.3f}".format(out_value - offset)) elif self.ser.is_open: in_str = self.ser.readline().decode('utf-8').strip() if in_str: try: in_value = float(in_str) # in_value /= DDUSCALEFACTOR # Uncomment this for FHC DDU V2. self.raw_ddu.display("{0:.3f}".format(in_value)) out_value = in_value + self.doubleSpinBox_offset.value() display_string = "{0:.3f}".format(out_value) self.offset_ddu.display(display_string) # Check if new value if display_string != self.display_string: new_value = True self.display_string = display_string # Push to NSP cbsdk_conn = CbSdkConnection() if cbsdk_conn.is_connected: if self.chk_NSP.isChecked() and self.chk_NSP.isEnabled( ) and new_value: cbsdk_conn.set_comments("DTT:" + display_string) else: # try connecting if not connected but button is active if self.chk_NSP.isChecked() and self.chk_NSP.isEnabled( ): cbsdk_conn.connect() cbsdk_conn.cbsdk_config = { 'reset': True, 'get_events': False, 'get_comments': False } # set button to connection status self.chk_NSP.setChecked(cbsdk_conn.is_connected) except ValueError: print("DDU result: {}".format(in_str)) # Push to LSL if self.depth_stream is not None and new_value: self.depth_stream.push_sample([out_value])
def __init__(self, parent=None): super(ConnectDialog, self).__init__(parent) # Get access to the CbSdkConnection instance, but don't connect yet. self.cbsdkConn = CbSdkConnection() # Widgets to show/edit connection parameters. layout = QVBoxLayout(self) # client-addr ip client_addr_layout = QHBoxLayout() client_addr_layout.addWidget(QLabel("client-addr")) self.clientIpEdit = QLineEdit(self.cbsdkConn.con_params['client-addr']) self.clientIpEdit.setInputMask("000.000.000.000;_") client_addr_layout.addWidget(self.clientIpEdit) layout.addLayout(client_addr_layout) # client-port int client_port_layout = QHBoxLayout() client_port_layout.addWidget(QLabel("client-port")) self.clientPortSpin = QSpinBox() self.clientPortSpin.setMinimum(0) self.clientPortSpin.setMaximum(99999) self.clientPortSpin.setSingleStep(1) self.clientPortSpin.setValue(self.cbsdkConn.con_params['client-port']) client_port_layout.addWidget(self.clientPortSpin) layout.addLayout(client_port_layout) # inst-addr ip inst_addr_layout = QHBoxLayout() inst_addr_layout.addWidget(QLabel("inst-addr")) self.instIpEdit = QLineEdit(self.cbsdkConn.con_params['inst-addr']) self.instIpEdit.setInputMask("000.000.000.000;_") inst_addr_layout.addWidget(self.instIpEdit) layout.addLayout(inst_addr_layout) # inst-port int inst_port_layout = QHBoxLayout() inst_port_layout.addWidget(QLabel("inst-port")) self.instPortSpin = QSpinBox() self.instPortSpin.setMinimum(0) self.instPortSpin.setMaximum(99999) self.instPortSpin.setSingleStep(1) self.instPortSpin.setValue(self.cbsdkConn.con_params['inst-port']) inst_port_layout.addWidget(self.instPortSpin) layout.addLayout(inst_port_layout) # receive-buffer-size int rec_buff_layout = QHBoxLayout() rec_buff_layout.addWidget(QLabel("receive-buffer-size")) self.recBuffSpin = QSpinBox() self.recBuffSpin.setMinimum(6 * 1024 * 1024) self.recBuffSpin.setMaximum(8 * 1024 * 1024) self.recBuffSpin.setSingleStep(1024 * 1024) self.recBuffSpin.setValue( self.cbsdkConn.con_params['receive-buffer-size']) rec_buff_layout.addWidget(self.recBuffSpin) layout.addLayout(rec_buff_layout) # OK and Cancel buttons buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) layout.addWidget(buttons)
# Just some chunks of code to help with development. import sys, os import time dbsgui_path = os.path.abspath(os.path.join('..', 'NeuroportDBS', 'DBSGUI')) sys.path.append(dbsgui_path) from cerebuswrapper import CbSdkConnection SAMPLINGGROUPS = ["0", "500", "1000", "2000", "10000", "30000", "RAW"] cbsdk_conn = CbSdkConnection(simulate_ok=False) cbsdk_conn.connect() cbsdk_conn.cbsdk_config = { 'reset': True, 'get_events': False, 'get_comments': False, 'get_continuous': False, 'buffer_parameter': { 'comment_length': 0 } } group_info = cbsdk_conn.get_group_config(SAMPLINGGROUPS.index("30000")) sys_config = cbsdk_conn.get_sys_config() # temp_ev = cbsdk_conn.get_event_data() # temp_cont = cbsdk_conn.get_continuous_data() chid = group_info[0]['chan'] temp_wfs, unit_ids = cbsdk_conn.get_waveforms(chid) # import matplotlib.pyplot as plt # plt.ion()