예제 #1
0
def write_reward(newy, reward_success=True):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
            dt = time1 - GameLogic.Object['train_tstart']
        else:
            dt = time1 - GameLogic.Object['time0']
        try:
            GameLogic.Object['event_file'].write(
                np.array([
                    dt,
                ], dtype=np.float32).tostring())
        except ValueError:
            sys.stderr.write(
                "BLENDER: Error - writing to closed reward file\n")
            return
        if reward_success:
            sys.stdout.write(
                "%s Reward %d; position: %d\n" %
                (gu.time2str(dt), GameLogic.Object['rewcount'], newy))
            GameLogic.Object['event_file'].write(b'RE')
        else:
            sys.stdout.write(
                "%s No reward %d; position: %d\n" %
                (gu.time2str(dt), GameLogic.Object['rewfail'], newy))
            GameLogic.Object['event_file'].write(b'RF')
        GameLogic.Object['event_file'].flush()
예제 #2
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
def write_reward(newy, reward_success=True):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
            dt = time1 -  GameLogic.Object['train_tstart']
        else:
            dt = time1 -  GameLogic.Object['time0']
        try:
            GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
        except ValueError:
            sys.stderr.write("BLENDER: Error - writing to closed reward file\n")
            return
        if reward_success:
            sys.stdout.write("%s Reward %d; position: %d\n" % (gu.time2str(dt), GameLogic.Object['rewcount'], newy))
            GameLogic.Object['event_file'].write(b'RE')
        else:
            sys.stdout.write("%s No reward %d; position: %d\n" % (gu.time2str(dt), GameLogic.Object['rewfail'], newy))
            GameLogic.Object['event_file'].write(b'RF')
        GameLogic.Object['event_file'].flush()
예제 #3
0
파일: gnoomio.py 프로젝트: chanlukas/gnoom
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()
예제 #4
0
파일: gnoomio.py 프로젝트: chanlukas/gnoom
def save_event(ev_code):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']

        GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
        sys.stdout.write("%s Saved event %s\n" % (gu.time2str(dt),ev_code))
        GameLogic.Object['event_file'].write(ev_code.encode('utf_8'))
        GameLogic.Object['event_file'].flush()
예제 #5
0
파일: gnoomio.py 프로젝트: chanlukas/gnoom
def write_puff():
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']

        GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
        sys.stdout.write("%s Airpuff %d\n" % (gu.time2str(dt), GameLogic.Object['puffcount']))
        GameLogic.Object['event_file'].write(b'AP')
        GameLogic.Object['event_file'].flush()
예제 #6
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
def save_event(ev_code):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']

        GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
        sys.stdout.write("%s Saved event %s\n" % (gu.time2str(dt),ev_code))
        GameLogic.Object['event_file'].write(ev_code.encode('utf_8'))
        GameLogic.Object['event_file'].flush()
예제 #7
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
def write_puff():
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']

        GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
        sys.stdout.write("%s Airpuff %d\n" % (gu.time2str(dt), GameLogic.Object['puffcount']))
        GameLogic.Object['event_file'].write(b'AP')
        GameLogic.Object['event_file'].flush()
예제 #8
0
파일: gnoomio.py 프로젝트: chanlukas/gnoom
def write_licks(licks):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        for nlick in range(licks.shape[0]):
            if licks[nlick, 1] > 0:
                time1 = licks[nlick, 0]
                if GameLogic.Object['train_open']:
                   dt = time1 -  GameLogic.Object['train_tstart']
                else:
                   dt = time1 -  GameLogic.Object['time0']
                
                for nl in range(int(np.round(licks[nlick, 1]))):
                    GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
                    sys.stdout.write("%s lick\n" % (gu.time2str(dt)))
                    GameLogic.Object['event_file'].write(b'LI')
                    GameLogic.Object['event_file'].flush()
예제 #9
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
def write_licks(licks):
    if GameLogic.Object['train_open'] or GameLogic.Object['file_open']:
        for nlick in range(licks.shape[0]):
            if licks[nlick, 1] > 0:
                time1 = licks[nlick, 0]
                if GameLogic.Object['train_open']:
                   dt = time1 -  GameLogic.Object['train_tstart']
                else:
                   dt = time1 -  GameLogic.Object['time0']
                
                for nl in range(int(np.round(licks[nlick, 1]))):
                    GameLogic.Object['event_file'].write(np.array([dt,], dtype=np.float32).tostring())
                    sys.stdout.write("%s lick\n" % (gu.time2str(dt)))
                    GameLogic.Object['event_file'].write(b'LI')
                    GameLogic.Object['event_file'].flush()
예제 #10
0
파일: gnoomio.py 프로젝트: chanlukas/gnoom
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
예제 #11
0
def valve_command(arduino, cmd, kb=None):
    if arduino is None:
        return

    if kb is not None:
        run_code = kb.positive
    else:
        run_code = True
    if run_code:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']
        print("%ss " % (gu.time2str(dt))+ str(kb))
        executed = False
        while not executed:
            try:
                arduino.write(cmd)
                executed = True
                gio.write_valve(cmd)
            except BlockingIOError:
                sys.stderr.write("GNOOMUTILS: Couldn't write to arduino\n")
예제 #12
0
def valve_command(arduino, cmd, kb=None):
    if arduino is None:
        return

    if kb is not None:
        run_code = kb.positive
    else:
        run_code = True
    if run_code:
        time1 = time.time()
        if GameLogic.Object['train_open']:
           dt = time1 -  GameLogic.Object['train_tstart']
        else:
           dt = time1 -  GameLogic.Object['time0']
        print("%ss " % (gu.time2str(dt))+ str(kb))
        executed = False
        while not executed:
            try:
                arduino.write(cmd)
                executed = True
                gio.write_valve(cmd)
            except BlockingIOError:
                sys.stderr.write("GNOOMUTILS: Couldn't write to arduino\n")
예제 #13
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
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
예제 #14
0
파일: gnoomio.py 프로젝트: neurodroid/gnoom
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()