-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbidsmreye.py
More file actions
executable file
·123 lines (94 loc) · 3.3 KB
/
bidsmreye.py
File metadata and controls
executable file
·123 lines (94 loc) · 3.3 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
"""Main script."""
from __future__ import annotations
import json
import sys
from pathlib import Path
from bidsmreye._version import __version__
from bidsmreye.configuration import Config
from bidsmreye.defaults import default_log_level
from bidsmreye.logger import bidsmreye_log
log = bidsmreye_log(name="bidsmreye")
def bidsmreye(
bids_dir: str,
output_dir: str,
analysis_level: str,
action: str,
participant_label: list[str] | None = None,
space: list[str] | None = None,
task: list[str] | None = None,
run: list[str] | None = None,
debug: bool | None = None,
model_weights_file: str | None = None,
reset_database: bool | None = None,
bids_filter_file: str | None = None,
linear_coreg: bool = False,
log_level_name: str | None = None,
force: bool = False,
) -> None:
bids_filter = None
if bids_filter_file is not None and Path(bids_filter_file).is_file():
with open(Path(bids_filter_file)) as f:
bids_filter = json.load(f)
if reset_database is None:
reset_database = False
cfg = Config(
bids_dir,
output_dir,
subjects=participant_label or None,
space=space or None,
task=task or None,
run=run or None,
debug=debug,
model_weights_file=model_weights_file,
reset_database=reset_database,
bids_filter=bids_filter,
linear_coreg=linear_coreg,
force=force,
) # type: ignore
if log_level_name is None:
log_level_name = default_log_level()
log.setLevel(log_level_name)
print(log_level_name)
log.warning(
f"log level: {log_level_name}",
)
log.info(f"Running bidsmreye version {__version__}")
if cfg.debug:
log.debug("DEBUG MODE")
log.debug(f"Configuration:\n{cfg}")
log.debug(f"{analysis_level=} {action=}")
if action in {"all", "generalize"} and isinstance(cfg.model_weights_file, str):
from bidsmreye.download import download
model_output_dir = cfg.output_dir / "models"
model_output_dir.mkdir(exist_ok=True, parents=True)
cfg.model_weights_file = download(
cfg.model_weights_file, output_dir=model_output_dir
)
dispatch(analysis_level=analysis_level, action=action, cfg=cfg)
def dispatch(analysis_level: str, action: str, cfg: Config) -> None:
if analysis_level == "group":
if action == "qc":
from bidsmreye.visualize import group_report
group_report(cfg=cfg)
else:
log.error("Unknown group level action")
sys.exit(1)
elif analysis_level == "participant":
if action == "all":
from bidsmreye.generalize import generalize
from bidsmreye.prepare_data import prepare_data
prepare_data(cfg)
generalize(cfg)
elif action == "prepare":
from bidsmreye.prepare_data import prepare_data
prepare_data(cfg)
elif action == "generalize":
from bidsmreye.generalize import generalize
generalize(cfg)
elif action == "qc":
from bidsmreye.quality_control import quality_control_input
quality_control_input(cfg)
else:
log.error("Unknown participant level action")
sys.exit(1)