Пример #1
0
def load_session(directory: str, session_name: str) -> pd.DataFrame:
    session = {}
    experiment_fname = directory + "session" + session_name + ".mat"
    params_fname = directory + "sessionParams" + session_name + ".mat"
    experiment_dict = strip_mat_metadata(load_mat(experiment_fname, False))
    for k, v in experiment_dict.items():
        if "neuron" in k:
            df = pd.DataFrame(v).transpose()
            session[k] = df
    params_data = strip_mat_metadata(load_mat(params_fname, False))["params"]
    session["params"] = pd.DataFrame(params_data, columns=["StimOn", "SignalOn", "LeverUp", "Coh1", "Coh2"]).dropna()
    session["params"]["LeverDelay"] = get_session_lever_delay(session["params"])
    session["params"]["LeverSuccess"] = get_session_lever_success(session["params"]["LeverDelay"])
    session["params"]["Session"] = pd.Series([session_name] * len(session["params"]))
    session["params"].index.name = "Trial"
    return session
Пример #2
0
def hierarchical_mat_to_dir(mat: str, out_prefix = "", show_debug = False, fmt="%.2f") -> bool:
    data = strip_mat_metadata(load_mat(mat, show_debug))
    if not out_prefix == "":
        if out_prefix[-1] == "/":
            if not os.path.exists(out_prefix):
                os.makedirs(out_prefix)
    for k, v in data.items():
        df = pd.DataFrame(v)
        df.to_csv(out_prefix + k + ".csv")
Пример #3
0
def hierarchical_mat_to_dir(mat: str,
                            out_prefix="",
                            show_debug=False,
                            fmt="%.2f") -> bool:
    data = strip_mat_metadata(load_mat(mat, show_debug))
    if not out_prefix == "":
        if out_prefix[-1] == "/":
            if not os.path.exists(out_prefix):
                os.makedirs(out_prefix)
    for k, v in data.items():
        df = pd.DataFrame(v)
        df.to_csv(out_prefix + k + ".csv")
Пример #4
0
def load_session_corr_signal(directory: str, session_name: str) -> pd.DataFrame:
    scs = {}
    session_fname = directory + "sessionCorrSignal" + session_name + ".mat"
    session_dict = strip_mat_metadata(load_mat(session_fname))
    for k, v in session_dict.items():
        scs[k] = pd.DataFrame(v)
    for col in scs["corrC"].columns:
        scs["time-" + str(col)] = pd.DataFrame(
                {"correlation": scs["corrC"][col], "mutual_information": scs["MIC"][col],
                 "label": [1] * len(scs["corrC"][col])})
        scs["time-" + str(col)] = scs["time-" + str(col)].append(
                pd.DataFrame({"correlation": scs["corrF"][col], "mutual_information": scs["MIF"][col],
                              "label": [0] * len(scs["corrF"][col])})).reset_index(drop=True)
    return scs
Пример #5
0
def preprocess_directory_of_raw_mats(directory: str) -> None:
    for f in os.listdir(directory):
        if f[-3:] == "mat":
            if "Params" in f:
                out_prefix = f[:-4] + "/raw/"
                out_prefix = out_prefix.replace("Params", "")
            else:
                out_prefix = f[:-4] + "/raw/"
            data = strip_mat_metadata(load_mat(f, False))
            if not os.path.exists(out_prefix):
                os.makedirs(out_prefix)
            for k, v in data.items():
                df = pd.DataFrame(v)
                if "neuron" in k:
                    df.transpose()
                df.to_csv(out_prefix + k + ".csv")