-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_scalardefs.py
96 lines (85 loc) · 3.6 KB
/
update_scalardefs.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
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
import pandas as pd
from qsirecon.interfaces import recon_scalars
from qsirecon.data import load as load_data
from qsirecon.utils.misc import load_yaml
def scalars_to_csv(scalar_def, output_csv):
print("creating", output_csv)
as_data = [
{
"Model": value["bids"]["model"],
"Parameter": value["bids"].get("param", ""),
"Description": value["metadata"].get("Description", ""),
}
for value in scalar_def.values()
]
df = pd.DataFrame(as_data).sort_values(["Model", "Parameter"])
df.to_csv(output_csv, header=False, index=None)
## TORTOISE.yaml
scalars_to_csv(recon_scalars.tortoise_scalars, "recon_scalars/tortoise.csv")
## amico_noddi.yaml
scalars_to_csv(recon_scalars.amico_scalars, "recon_scalars/amico_noddi.csv")
## csdsi_3dshore.yaml
scalars_to_csv(recon_scalars.brainsuite_3dshore_scalars, "recon_scalars/csdsi_3dshore.csv")
## dipy_3dshore.yaml
scalars_to_csv(recon_scalars.brainsuite_3dshore_scalars, "recon_scalars/dipy_3dshore.csv")
## dipy_dki.yaml
scalars_to_csv(recon_scalars.dipy_dki_scalars, "recon_scalars/dipy_dki.csv")
## dipy_mapmri.yaml
scalars_to_csv(recon_scalars.dipy_mapmri_scalars, "recon_scalars/dipy_mapmri.csv")
## dsi_studio_gqi.yaml
scalars_to_csv(recon_scalars.dsistudio_scalars, "recon_scalars/dsi_studio_gqi.csv")
## hbcd_scalar_maps.yaml
scalars_to_csv(
recon_scalars.dipy_dki_scalars
| recon_scalars.tortoise_scalars
| recon_scalars.dsistudio_scalars,
"recon_scalars/hbcd_scalar_maps.csv",
)
def output_to_filepattern(bids):
file_pattern = []
if "space" in bids:
file_pattern.append(f"space-{bids['space']}")
if "seg" in bids:
file_pattern.append(f"seg-{bids['seg']}")
if "bundle" in bids:
file_pattern.append(f"bundle-{bids['bundle']}")
if "bundles" in bids:
file_pattern.append(f"bundles-{bids['bundles']}")
if "model" in bids:
file_pattern.append(f"model-{bids['model']}")
if "param" in bids:
file_pattern.append(f"param-{bids['param']}")
if "label" in bids:
file_pattern.append(f"label-{bids['label']}")
extension = bids.get("extension", "\*")
file_pattern.append(f"_{bids.get('suffix', 'dwimap')}.{extension}")
return "\*" + "\*".join(file_pattern)
def outputs_to_csv(output_def, output_csv):
as_data = [
{
"File": output_to_filepattern(value["bids"]),
"Description": value["metadata"]["Description"].replace("\n", " "),
}
for value in output_def.values()
]
df = pd.DataFrame(as_data).sort_values("File")
df.to_csv(output_csv, header=False, index=None)
outputs_to_csv(load_yaml(load_data("nonscalars/amico_noddi.yaml")), "nonscalars/amico_noddi.csv")
outputs_to_csv(load_yaml(load_data("nonscalars/dipy_dki.yaml")), "nonscalars/dipy_dki.csv")
outputs_to_csv(load_yaml(load_data("nonscalars/dipy_mapmri.yaml")), "nonscalars/dipy_mapmri.csv")
outputs_to_csv(
load_yaml(load_data("nonscalars/dsistudio_gqi.yaml")), "nonscalars/dsistudio_gqi.csv"
)
outputs_to_csv(
load_yaml(load_data("nonscalars/dsistudio_autotrack.yaml")),
"nonscalars/dsistudio_autotrack.csv",
)
outputs_to_csv(load_yaml(load_data("nonscalars/tortoise.yaml")), "nonscalars/tortoise.csv")
outputs_to_csv(
load_yaml(load_data("nonscalars/csdsi_3dshore.yaml")), "nonscalars/csdsi_3dshore.csv"
)
outputs_to_csv(
load_yaml(load_data("nonscalars/ss3t_autotrack.yaml")), "nonscalars/ss3t_autotrack.csv"
)
outputs_to_csv(load_yaml(load_data("nonscalars/mrtrix_dwi.yaml")), "nonscalars/mrtrix_dwi.csv")
outputs_to_csv(load_yaml(load_data("nonscalars/mrtrix_anat.yaml")), "nonscalars/mrtrix_anat.csv")