コード例 #1
0
def load_params() -> dict:
    params_local = load_params_file()
    params_alyx = alyx.load_alyx_params(params_local["NAME"])
    if params_alyx is None:
        log.warning("Could not load board params from Alyx.")
    if params_alyx != params_local:
        log.warning("Local data and Alyx data mismatch. Trying to update Alyx.")
        alyx.update_alyx_params(data=params_local, force=True)
    return params_local
コード例 #2
0
def try_migrate_to_params(force=False):
    params_file = Path(ph.get_iblrig_params_folder()) / ".iblrig_params.json"
    comports_file = Path(ph.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 = ph.get_water_calibration_range_file()
    func_file = ph.get_water_calibration_func_file()
    if (str(func_file) != "."
            and str(range_file) != ".") and (func_file.parent
                                             == range_file.parent):
        water_dict.update(ph.load_water_calibraition_range_file(range_file))
        water_dict.update(ph.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(ph.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_alyx_params(get_pybpod_board_name())
    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_alyx_params(data=final_dict, force=True)
    # Delete old comports file
    if comports_file.exists():
        bk = Path(ph.get_iblrig_params_folder()) / ".bpod_comports.json_bk"
        shutil.copy(str(comports_file), str(bk))
        comports_file.unlink()
    return