diff --git a/geci_loader.py b/geci_loader.py index 95826ae..56596df 100644 --- a/geci_loader.py +++ b/geci_loader.py @@ -4,22 +4,53 @@ import argh # mouse:int = 0, 1, 2, 3, 4 -def loader(mouse:int = 0, fpath:str = "/data_1/hendrik/gevi") -> None: - +def loader(mouse: int = 0, fpath: str = "/data_1/hendrik/gevi") -> None: + mouse_name = [ - 'M_Sert_Cre_41', - 'M_Sert_Cre_42', - 'M_Sert_Cre_45', - 'M_Sert_Cre_46', - 'M_Sert_Cre_49' + "M_Sert_Cre_41", + "M_Sert_Cre_42", + "M_Sert_Cre_45", + "M_Sert_Cre_46", + "M_Sert_Cre_49", ] n_tris = [ - [15, 15, 30, 30, 30, 30,], # 0 in cond 7 - [15, 15, 30, 30, 30, 30,], # 0 in cond 7 - [15, 15, 30, 30, 30, 30,], # 0 in cond 7 - [20, 40, 20, 20,], # 0, 0, 0 in cond 5-7 - [20, 40, 20, 20,], # 0, 0, 0 in cond 5-7 + [ + 15, + 15, + 30, + 30, + 30, + 30, + ], # 0 in cond 7 + [ + 15, + 15, + 30, + 30, + 30, + 30, + ], # 0 in cond 7 + [ + 15, + 15, + 30, + 30, + 30, + 30, + ], # 0 in cond 7 + [ + 20, + 40, + 20, + 20, + ], # 0, 0, 0 in cond 5-7 + [ + 20, + 40, + 20, + 20, + ], # 0, 0, 0 in cond 5-7 ] # 41, 42, 45, 46, 49: @@ -32,11 +63,32 @@ def loader(mouse:int = 0, fpath:str = "/data_1/hendrik/gevi") -> None: # "7": "grating 3s" lbs = [ - ['control', 'visual control', 'op20 50 5', 'op20 100 5', 'op20 50 grat', 'op20 100 grat'], - ['control', 'visual control', 'op20 50 5', 'op20 100 5', 'op20 50 grat', 'op20 100 grat'], - ['control', 'visual control', 'op20 50 5', 'op20 100 5', 'op20 50 grat', 'op20 100 grat'], - ['control', 'visual control', 'op20 50 5', 'op20 100 5'], - ['control', 'visual control', 'op20 50 5', 'op20 100 5'] + [ + "control", + "visual control", + "op20 50 5", + "op20 100 5", + "op20 50 grat", + "op20 100 grat", + ], + [ + "control", + "visual control", + "op20 50 5", + "op20 100 5", + "op20 50 grat", + "op20 100 grat", + ], + [ + "control", + "visual control", + "op20 50 5", + "op20 100 5", + "op20 50 grat", + "op20 100 grat", + ], + ["control", "visual control", "op20 50 5", "op20 100 5"], + ["control", "visual control", "op20 50 5", "op20 100 5"], ] n_exp = len(n_tris[mouse]) @@ -45,9 +97,11 @@ def loader(mouse:int = 0, fpath:str = "/data_1/hendrik/gevi") -> None: n_tri = n_tris[mouse][i_exp] for i_tri in range(n_tri): - experiment_name: str = f"Exp{i_exp+1:03d}_Trial{i_tri+1:03d}" + experiment_name: str = f"Exp{i_exp + 1:03d}_Trial{i_tri + 1:03d}" tmp_fname = os.path.join( - fpath, "output_" + mouse_name[mouse], experiment_name + "_acceptor_donor.npz" + fpath, + "output_" + mouse_name[mouse], + experiment_name + "_acceptor_donor.npz", ) print(f'Processing file "{tmp_fname}"...') tmp = np.load(tmp_fname) @@ -67,5 +121,6 @@ def loader(mouse:int = 0, fpath:str = "/data_1/hendrik/gevi") -> None: np.save("lsq_" + mouse_name[mouse], light_signal) np.save("msq_" + mouse_name[mouse], mask) + if __name__ == "__main__": argh.dispatch_command(loader) diff --git a/geci_plot.py b/geci_plot.py index f7b45d6..94cfdfa 100644 --- a/geci_plot.py +++ b/geci_plot.py @@ -79,7 +79,7 @@ def plot( trials = get_trials(raw_data_path, experiment).numpy() assert trials.shape[0] > 0 - with open(os.path.join(raw_data_path, f"Exp{experiment:03d}_Trial{trials[0]:03d}_Part001_meta.txt"), "r") as file: + with open(f"meta_{config["mouse_identifier"]}_exp{experiment:03d}.json", "r") as file: metadata = json.loads(jsmin(file.read())) experiment_names = metadata['sessionMetaData']['experimentNames'][str(experiment)] diff --git a/stage_5_convert_metadata.py b/stage_5_convert_metadata.py new file mode 100644 index 0000000..1e5e7c2 --- /dev/null +++ b/stage_5_convert_metadata.py @@ -0,0 +1,52 @@ +import json +import os +import argh +from jsmin import jsmin # type:ignore +from functions.get_trials import get_trials +from functions.get_experiments import get_experiments + + +def converter(filename: str = "config_M_Sert_Cre_49.json") -> None: + + if os.path.isfile(filename) is False: + print(f"{filename} is missing") + exit() + + with open(filename, "r") as file: + config = json.loads(jsmin(file.read())) + + raw_data_path: str = os.path.join( + config["basic_path"], + config["recoding_data"], + config["mouse_identifier"], + config["raw_path"], + ) + + if os.path.isdir(raw_data_path) is False: + print(f"ERROR: could not find raw directory {raw_data_path}!!!!") + exit() + + experiments = get_experiments(raw_data_path).numpy() + + for experiment in experiments: + + trials = get_trials(raw_data_path, experiment).numpy() + assert trials.shape[0] > 0 + + with open( + os.path.join( + raw_data_path, + f"Exp{experiment:03d}_Trial{trials[0]:03d}_Part001_meta.txt", + ), + "r", + ) as file: + metadata = json.loads(jsmin(file.read())) + + filename_out: str = f"meta_{config["mouse_identifier"]}_exp{experiment:03d}.json" + + with open(filename_out, 'w') as file: + json.dump(metadata, file) + + +if __name__ == "__main__": + argh.dispatch_command(converter)