-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage_5_convert_metadata.py
54 lines (39 loc) · 1.43 KB
/
stage_5_convert_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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(config_filename: str = "config.json") -> None:
filename: str = config_filename
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)