def write_training_file(move, xtranslate, ytranslate, zrotate): # get controller controller = GameLogic.getCurrentController() own = controller.owner has_fw = GameLogic.Object['has_fw'] if has_fw: connfw = GameLogic.Object['fwconn'] else: connfw = None time1 = time.time() dt = time1 - GameLogic.Object['train_tstart'] arduino = GameLogic.Object['arduino'] if GameLogic.Object['bcstatus']==False: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'u') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 1) GameLogic.Object['bcstatus']=True else: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 0) GameLogic.Object['bcstatus']=False if has_fw: frametimefw = parse_frametimes(connfw)-GameLogic.Object['time0'] else: frametimefw = np.array([0,]) sys.stdout.write("%s\r" % (gu.time2str(dt))) GameLogic.Object['train_file'].write(np.array([dt, len(move[0]), len(move[2])], dtype=np.float32).tostring()) # 0:x1, 1:y1, 2:x2, 3:y2, 4:t1, 5:t2, 6:dt1, 7:dt2 GameLogic.Object['train_file'].flush() if len(move[0]): GameLogic.Object['train_file'].write(np.array([ move[0].sum(), move[1].sum()], dtype=np.float32).tostring()) if len(move[2]): GameLogic.Object['train_file'].write(np.array([ move[2].sum(), move[3].sum()], dtype=np.float32).tostring()) if len(move[0]) or len(move[2]): GameLogic.Object['train_file'].flush() GameLogic.Object['pos_file'].write(np.array([ xtranslate, ytranslate, zrotate, own.position[0], own.position[1], own.position[2], own.orientation[0][0], own.orientation[0][1], own.orientation[0][2], own.orientation[1][0], own.orientation[1][1], own.orientation[1][2], own.orientation[2][0], own.orientation[1][2], own.orientation[2][2], ], dtype=np.float64).tostring()) GameLogic.Object['pos_file'].flush()
def write_record_file(move, xtranslate, ytranslate, zrotate): time1 = time.time() dt = time1 - GameLogic.Object['time0'] arduino = GameLogic.Object['arduino'] controller = GameLogic.getCurrentController() own = controller.owner if GameLogic.Object['bcstatus']==False: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'u') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 1) GameLogic.Object['bcstatus']=True else: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 0) GameLogic.Object['bcstatus']=False if GameLogic.Object['has_fw']: frametimefw = gc.parse_frametimes(GameLogic.Object['fwconn'])-GameLogic.Object['time0'] elif GameLogic.Object['has_usb3']: frametimefw = gc.parse_frametimes(GameLogic.Object['usb3conn'])-GameLogic.Object['time0'] if 'usb3conn2' in GameLogic.Object.keys(): frametimefw2 = gc.parse_frametimes(GameLogic.Object['usb3conn2'])-GameLogic.Object['time0'] frametimefw2 = -frametimefw2-10 frametimefw = np.concatenate((frametimefw, frametimefw2)) else: frametimefw = np.array([0,]) GameLogic.Object['current_file'].write(np.array([dt, xtranslate, ytranslate, zrotate, own.position[0], own.position[1], own.position[2], time1, own.orientation[0][0], own.orientation[0][1], own.orientation[0][2], own.orientation[1][0], own.orientation[1][1], own.orientation[1][2], own.orientation[2][0], own.orientation[1][2], own.orientation[2][2], len(move[0]), len(move[2]), len(frametimefw)], dtype=np.float64).tostring()) # 0:x1, 1:y1, 2:x2, 3:y2, 4:t1, 5:t2, 6:dt1, 7:dt2 GameLogic.Object['current_file'].flush() for nm in range(len(move[0])): GameLogic.Object['current_file'].write(np.array([ move[0][nm], move[1][nm], move[4][nm], move[6][nm]], dtype=np.float64).tostring()) for nm in range(len(move[2])): GameLogic.Object['current_file'].write(np.array([ move[2][nm], move[3][nm], move[5][nm], move[7][nm]], dtype=np.float64).tostring()) if (len(move[0]) or len(move[2])): GameLogic.Object['current_file'].flush() if len(frametimefw) > 0: GameLogic.Object['current_file'].write(frametimefw.tostring()) GameLogic.Object['current_file'].flush()
def write_record_file(move, xtranslate, ytranslate, zrotate): time1 = time.time() dt = time1 - GameLogic.Object['time0'] arduino = GameLogic.Object['arduino'] controller = GameLogic.getCurrentController() own = controller.owner if GameLogic.Object['bcstatus']==False: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'u') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 1) GameLogic.Object['bcstatus']=True else: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 0) GameLogic.Object['bcstatus']=False # if settings.has_webcam: # frametime = parse_frametimes(connvid)-GameLogic.Object['time0'] # else: # frametime = np.array([0,]) if GameLogic.Object['has_fw']: frametimefw = parse_frametimes(GameLogic.Object['fwconn'])-GameLogic.Object['time0'] else: frametimefw = np.array([0,]) GameLogic.Object['current_file'].write(np.array([dt, xtranslate, ytranslate, zrotate, own.position[0], own.position[1], own.position[2], time1, own.orientation[0][0], own.orientation[0][1], own.orientation[0][2], own.orientation[1][0], own.orientation[1][1], own.orientation[1][2], own.orientation[2][0], own.orientation[1][2], own.orientation[2][2], len(move[0]), len(move[2]), len(frametimefw)], dtype=np.float64).tostring()) # 0:x1, 1:y1, 2:x2, 3:y2, 4:t1, 5:t2, 6:dt1, 7:dt2 GameLogic.Object['current_file'].flush() for nm in range(len(move[0])): GameLogic.Object['current_file'].write(np.array([ move[0][nm], move[1][nm], move[4][nm], move[6][nm]], dtype=np.float64).tostring()) for nm in range(len(move[2])): GameLogic.Object['current_file'].write(np.array([ move[2][nm], move[3][nm], move[5][nm], move[7][nm]], dtype=np.float64).tostring()) if (len(move[0]) or len(move[2])): GameLogic.Object['current_file'].flush() if len(frametimefw) > 0: GameLogic.Object['current_file'].write(frametimefw.tostring()) GameLogic.Object['current_file'].flush()
def stop_training_file(): GameLogic.Object['train_file'].close() GameLogic.Object['event_file'].close() GameLogic.Object['pos_file'].close() if settings.looming: GameLogic.Object['current_loomfile'].close() GameLogic.Object['loomcounter'] = 0 GameLogic.Object['loom_first_trial'] = 0 if settings.has_licksensor_piezo: GameLogic.Object['current_lickfile'].close() train_tend = time.time()-GameLogic.Object['train_tstart'] sys.stdout.write("BLENDER: Closing file; recorded %s of training\n" % (gu.time2str(train_tend))) GameLogic.Object['train_open'] = False if GameLogic.Object['has_fw']: gc.safe_send(GameLogic.Object['fwconn'], 'stop', '') arduino = GameLogic.Object['arduino'] if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') GameLogic.Object['bcstatus']=False
def stop_record_file(): arduino = GameLogic.Object['arduino'] # Close video and ephys acquisition if GameLogic.Object['has_fw']: gc.safe_send(GameLogic.Object['fwconn'], 'stop', '') if GameLogic.Object['has_usb3']: gc.safe_send(GameLogic.Object['usb3conn'], 'stop', '') if 'usb3conn2' in GameLogic.Object.keys(): gc.safe_send(GameLogic.Object['usb3conn2'], 'stop', '') GameLogic.Object['bcstatus'] = False if settings.has_comedi and ncl.has_comedi: gc.safe_send(GameLogic.Object['comediconn'], 'stop', '') ncl.set_trig(GameLogic.Object['outtrigch'], 0) ncl.set_trig(GameLogic.Object['outfrch'], 0) # get ephys end time: ephysstop = (parse_ephystimes(GameLogic.Object['comediconn']) - GameLogic.Object['time0'])[0] else: # TODO: get correct intan ephys end time ephysstop = time.time() - GameLogic.Object['time0'] if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') GameLogic.Object['event_file'].close() GameLogic.Object['current_file'].close() if settings.looming: GameLogic.Object['current_loomfile'].close() GameLogic.Object['loomcounter'] = 0 GameLogic.Object['loom_first_trial'] = 0 if settings.has_licksensor_piezo: GameLogic.Object['current_lickfile'].close() print("BLENDER: Closing file") GameLogic.Object['file_open'] = False write_header(GameLogic.Object['current_movfile'][:-4] + "_header.txt", GameLogic.Object['current_movfile'], GameLogic.Object['current_ephysfile'], GameLogic.Object['ephysstart'], ephysstop)
def stop_record_file(): arduino = GameLogic.Object['arduino'] # Close video and ephys acquisition if GameLogic.Object['has_fw']: gc.safe_send(GameLogic.Object['fwconn'], 'stop', '') if GameLogic.Object['has_usb3']: gc.safe_send(GameLogic.Object['usb3conn'], 'stop', '') if 'usb3conn2' in GameLogic.Object.keys(): gc.safe_send(GameLogic.Object['usb3conn2'], 'stop', '') GameLogic.Object['bcstatus']=False if settings.has_comedi and ncl.has_comedi: gc.safe_send(GameLogic.Object['comediconn'], 'stop', '') ncl.set_trig(GameLogic.Object['outtrigch'], 0) ncl.set_trig(GameLogic.Object['outfrch'], 0) # get ephys end time: ephysstop = (parse_ephystimes(GameLogic.Object['comediconn'])-GameLogic.Object['time0'])[0] else: # TODO: get correct intan ephys end time ephysstop = time.time()-GameLogic.Object['time0'] if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') GameLogic.Object['event_file'].close() GameLogic.Object['current_file'].close() if settings.looming: GameLogic.Object['current_loomfile'].close() GameLogic.Object['loomcounter'] = 0 GameLogic.Object['loom_first_trial'] = 0 if settings.has_licksensor_piezo: GameLogic.Object['current_lickfile'].close() print("BLENDER: Closing file") GameLogic.Object['file_open'] = False write_header(GameLogic.Object['current_movfile'][:-4]+"_header.txt", GameLogic.Object['current_movfile'], GameLogic.Object['current_ephysfile'], GameLogic.Object['ephysstart'], ephysstop)
def stop_training_file(): GameLogic.Object['train_file'].close() GameLogic.Object['event_file'].close() GameLogic.Object['pos_file'].close() if settings.looming: GameLogic.Object['current_loomfile'].close() GameLogic.Object['loomcounter'] = 0 GameLogic.Object['loom_first_trial'] = 0 if settings.has_licksensor_piezo: GameLogic.Object['current_lickfile'].close() train_tend = time.time()-GameLogic.Object['train_tstart'] sys.stdout.write("BLENDER: Closing file; recorded %s of training\n" % (gu.time2str(train_tend))) GameLogic.Object['train_open'] = False if GameLogic.Object['has_fw']: gc.safe_send(GameLogic.Object['fwconn'], 'stop', '') if GameLogic.Object['has_usb3']: gc.safe_send(GameLogic.Object['usb3conn'], 'stop', '') if 'usb3conn2' in GameLogic.Object.keys(): gc.safe_send(GameLogic.Object['usb3conn2'], 'stop', '') arduino = GameLogic.Object['arduino'] if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') GameLogic.Object['bcstatus']=False
def write_training_file(move, xtranslate, ytranslate, zrotate): # get controller controller = GameLogic.getCurrentController() own = controller.owner has_fw = GameLogic.Object['has_fw'] if has_fw: connfw = GameLogic.Object['fwconn'] else: connfw = None has_usb3 = GameLogic.Object['has_usb3'] if has_usb3: connusb3 = GameLogic.Object['usb3conn'] if 'usb3conn2' in GameLogic.Object.keys(): conn2usb3 = GameLogic.Object['usb3conn2'] else: conn2usb3 = None else: connusb3 = None conn2usb3 = None time1 = time.time() dt = time1 - GameLogic.Object['train_tstart'] arduino = GameLogic.Object['arduino'] if GameLogic.Object['bcstatus']==False: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'u') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 1) GameLogic.Object['bcstatus']=True else: if arduino is not None: gc.write_arduino_nonblocking(arduino, b'd') if settings.has_comedi and ncl.has_comedi: ncl.set_trig(GameLogic.Object['outfrch'], 0) GameLogic.Object['bcstatus']=False if has_fw: frametimefw = gc.parse_frametimes(connfw)-GameLogic.Object['time0'] elif has_usb3: frametimefw = gc.parse_frametimes(connusb3)-GameLogic.Object['time0'] if conn2usb3 is not None: frametimefw2 = gc.parse_frametimes(conn2usb3)-GameLogic.Object['time0'] frametimefw2 = -frametimefw2-10 frametimefw = np.concatenate((frametimefw, frametimefw2)) else: frametimefw = np.array([0,]) sys.stdout.write("%s\r" % (gu.time2str(dt))) GameLogic.Object['train_file'].write(np.array([dt, len(move[0]), len(move[2])], dtype=np.float32).tostring()) # 0:x1, 1:y1, 2:x2, 3:y2, 4:t1, 5:t2, 6:dt1, 7:dt2 GameLogic.Object['train_file'].flush() if len(move[0]): GameLogic.Object['train_file'].write(np.array([ move[0].sum(), move[1].sum()], dtype=np.float32).tostring()) if len(move[2]): GameLogic.Object['train_file'].write(np.array([ move[2].sum(), move[3].sum()], dtype=np.float32).tostring()) if len(move[0]) or len(move[2]): GameLogic.Object['train_file'].flush() GameLogic.Object['pos_file'].write(np.array([ xtranslate, ytranslate, zrotate, own.position[0], own.position[1], own.position[2], own.orientation[0][0], own.orientation[0][1], own.orientation[0][2], own.orientation[1][0], own.orientation[1][1], own.orientation[1][2], own.orientation[2][0], own.orientation[1][2], own.orientation[2][2], ], dtype=np.float64).tostring()) GameLogic.Object['pos_file'].flush()