Exemple #1
0
def load_params() -> dict:
    out_alyx = alyx.load_board_params()
    if out_alyx is None:
        log.warning(
            f"Could not load board params from Alyx. Loading from local file..."
        )
    out = load_params_file()
    if out_alyx != out:
        log.warning(f"Local data and Alyx data are not the same. Using local.")
        alyx.update_board_params(data=out, force=True)
    return out
def load_params() -> dict:
    params_alyx = alyx.load_board_params()
    if params_alyx is None:
        log.warning(
            f"Could not load board params from Alyx. Loading from local file..."
        )
    params_local = load_params_file()
    if params_alyx != params_local:
        log.warning(
            f"Local data and Alyx data are not the same. Trying to update Alyx."
        )
        alyx.update_board_params(data=params_local, force=True)
        log.info("Using local params.")
    return params_local
Exemple #3
0
def get_and_set_thresholds(sph):
    try:
        params = alyx.load_board_params(sph.PYBPOD_BOARD)  # --> dict
        if params['F2TTL_COM'] != sph.COM['FRAME2TTL']:
            alyx.update_board_params(sph.PYBPOD_BOARD,
                                     {'F2TTL_COM': sph.COM['FRAME2TTL']})
            params['F2TTL_COM'] = sph.COM['FRAME2TTL']
    except:  # noqa
        params = {}
        log.error(f"{sph.PYBPOD_BOARD} Board not found")
    if not params:
        log.warning(
            f"No parameters found for board {sph.PYBPOD_BOARD}, please calibrate the device."
        )
    if sum(['F2TTL' in x for x in params.keys()]) != 3:
        log.warning(
            f"Incomplete parameters for F2TTL, please calibrate the device.")
    else:
        dev = Frame2TTL(params['F2TTL_COM'])
        dev.set_thresholds(dark=params['F2TTL_DARK_THRESH'],
                           light=params['F2TTL_LIGHT_THRESH'])
        log.info(f"Frame2TTL: Thresholds set.")
        return 0
    return -1
Exemple #4
0
def try_migrate_to_params(force=False):
    params_file = Path(
        path_helper.get_iblrig_params_folder()) / '.iblrig_params.json'
    comports_file = Path(
        path_helper.get_iblrig_params_folder()) / '.bpod_comports.json'
    # See if file exists:
    if params_file.exists() and not force:
        log.info(f"No steps taken - File exists: {params_file}")
        return
    # Get .bpod_comports file and set the COM values
    if comports_file.exists():
        with open(comports_file, 'r') as f:
            com_data = json.load(f)
        com_dict = {
            'COM_BPOD': com_data['BPOD'],  # str
            'COM_ROTARY_ENCODER': com_data['ROTARY_ENCODER'],  # str
            'COM_F2TTL': com_data['FRAME2TTL']
        }  # str
    else:
        com_dict = {
            'COM_BPOD': get_board_comport(),
            'COM_F2TTL': "",
            'COM_ROTARY_ENCODER': ""
        }
    # Find latest H2O calib and set WATER values
    water_dict = {
        'WATER_CALIBRATION_RANGE': "",  # [min, max]
        'WATER_CALIBRATION_OPEN_TIMES': "",  # [float, float, ...]
        'WATER_CALIBRATION_WEIGHT_PERDROP': "",  # [float, float, ...]
        'WATER_CALIBRATION_DATE': ""
    }  # str
    range_file = path_helper.get_water_calibration_range_file()
    func_file = path_helper.get_water_calibration_func_file()
    if ((str(func_file) != '.' and str(range_file) != '.')
            and (func_file.parent == range_file.parent)):
        water_dict.update(
            path_helper.load_water_calibraition_range_file(range_file))
        water_dict.update(
            path_helper.load_water_calibraition_func_file(func_file))
        water_dict.update(
            {'WATER_CALIBRATION_DATE': func_file.parent.parent.parent.name})
    if str(func_file) != '.':
        water_dict.update(
            path_helper.load_water_calibraition_func_file(func_file))
        water_dict.update(
            {'WATER_CALIBRATION_DATE': func_file.parent.parent.parent.name})
    # Find latest F2TTL calib and set F2TTL values
    f2ttl_params = alyx.load_board_params()
    if f2ttl_params is None:
        f2ttl_dict = {
            'F2TTL_DARK_THRESH': "",
            'F2TTL_LIGHT_THRESH': "",
            'F2TTL_CALIBRATION_DATE': "",
        }
    else:
        f2ttl_dict = {
            'F2TTL_DARK_THRESH': f2ttl_params['F2TTL_DARK_THRESH'],
            'F2TTL_LIGHT_THRESH': f2ttl_params['F2TTL_LIGHT_THRESH'],
            'F2TTL_CALIBRATION_DATE':
            datetime.datetime.now().date().isoformat(),
        }
        if 'COM_F2TTL' in f2ttl_params:
            f2ttl_dict.update({'COM_F2TTL': f2ttl_params['COM_F2TTL']})
        elif 'F2TTL_COM' in f2ttl_params:
            f2ttl_dict.update({'COM_F2TTL': f2ttl_params['F2TTL_COM']})
        if 'F2TTL_CALIBRATION_DATE' in f2ttl_params:
            f2ttl_dict.update({
                'F2TTL_CALIBRATION_DATE':
                f2ttl_params['F2TTL_CALIBRATION_DATE']
            })

    # Save locally
    final_dict = {}
    final_dict.update({'NAME': get_board_name()})  # from GUI
    final_dict.update(com_dict)
    final_dict.update(f2ttl_dict)
    final_dict.update(water_dict)
    write_params_file(data=final_dict, force=True)
    # upload to Alyx board
    alyx.write_board_params(data=final_dict, force=True)
    # Delete old comports file
    if comports_file.exists():
        bk = Path(
            path_helper.get_iblrig_params_folder()) / '.bpod_comports.json_bk'
        shutil.copy(str(comports_file), str(bk))
        comports_file.unlink()
    return