Skip to content

Commit 566b4b2

Browse files
Port v1.5.2 bugfixes into dev-v2.0.0 (#329)
* fix for using T1T2w model run_inference was only accepting a single input image, this makes it accept a list of images too, and makes it so --force-nnunet-model T1T2w grabs both T1w and T2w as inputs. * hipp curvature was being used always, instead of wildcard this didn't affect any workflow computations, just the subsequent dscalar.nii and spec file that would have the wrong curvature map * fix logical error * Bump version to 1.5.2-pre.1 * Bump version to 1.5.2-pre.2 * keep pipeline_description changes --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f1e90ab commit 566b4b2

File tree

3 files changed

+50
-35
lines changed

3 files changed

+50
-35
lines changed

hippunfold/pipeline_description.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"DatasetType": "derivative",
55
"GeneratedBy": [
66
{
7-
"Name": "hippunfold",
8-
"Version": "1.5.4",
9-
"CodeURL": "https://github.com/khanlab/hippunfold",
10-
"Author": "Jordan DeKraker & Ali Khan",
11-
"AuthorEmail": "ali.khan@uwo.ca"
12-
}
13-
]
7+
"Name": "hippunfold",
8+
"Version": "1.5.2-pre.2",
9+
"CodeURL": "https://github.com/khanlab/hippunfold",
10+
"Author": "Jordan DeKraker & Ali Khan",
11+
"AuthorEmail": "ali.khan@uwo.ca"
12+
}
13+
]
1414
}

hippunfold/workflow/rules/gifti.smk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ rule normalize_curvature2:
978978
space="{space}",
979979
hemi="{hemi}",
980980
desc="unnorm",
981-
label="hipp",
981+
label="{autotop}",
982982
**inputs.subj_wildcards
983983
),
984984
output:

hippunfold/workflow/rules/nnunet.smk

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@ import re
22

33

44
def get_nnunet_input(wildcards):
5-
if config["modality"] == "T2w":
6-
nii = (
7-
bids(
8-
root=work,
9-
datatype="anat",
10-
**inputs.subj_wildcards,
11-
suffix="T2w.nii.gz",
12-
space="corobl",
13-
desc="preproc",
14-
hemi="{hemi}",
15-
),
16-
)
5+
T1w_nii = bids(
6+
root=work,
7+
datatype="anat",
8+
space="corobl",
9+
desc="preproc",
10+
hemi="{hemi}",
11+
suffix="T1w.nii.gz",
12+
**inputs.subj_wildcards,
13+
)
14+
T2w_nii = bids(
15+
root=work,
16+
datatype="anat",
17+
space="corobl",
18+
desc="preproc",
19+
hemi="{hemi}",
20+
suffix="T2w.nii.gz",
21+
**inputs.subj_wildcards,
22+
)
23+
if (config["modality"] == "T1w" or config["modality"] == "T2w") and config[
24+
"force_nnunet_model"
25+
] == "T1T2w":
26+
return (T1w_nii, T2w_nii)
27+
28+
elif config["modality"] == "T2w":
29+
return T2w_nii
1730
elif config["modality"] == "T1w":
18-
nii = (
19-
bids(
20-
root=work,
21-
datatype="anat",
22-
**inputs.subj_wildcards,
23-
suffix="T1w.nii.gz",
24-
space="corobl",
25-
desc="preproc",
26-
hemi="{hemi}",
27-
),
28-
)
31+
return T1w_nii
2932
elif config["modality"] == "hippb500":
30-
nii = bids(
33+
return bids(
3134
root=work,
3235
datatype="dwi",
3336
hemi="{hemi}",
@@ -37,7 +40,6 @@ def get_nnunet_input(wildcards):
3740
)
3841
else:
3942
raise ValueError("modality not supported for nnunet!")
40-
return nii
4143

4244

4345
def get_model_tar():
@@ -94,14 +96,27 @@ def parse_trainer_from_tar(wildcards, input):
9496
return trainer
9597

9698

99+
def get_cmd_copy_inputs(wildcards, input):
100+
in_img = input.in_img
101+
if isinstance(in_img, str):
102+
# we have one input image
103+
return f"cp {in_img} tempimg/temp_0000.nii.gz"
104+
else:
105+
cmd = []
106+
# we have multiple input images
107+
for i, img in enumerate(input.in_img):
108+
cmd.append(f"cp {img} tempimg/temp_{i:04d}.nii.gz")
109+
return " && ".join(cmd)
110+
111+
97112
rule run_inference:
98113
""" This rule uses either GPU or CPU .
99114
It also runs in an isolated folder (shadow), with symlinks to inputs in that folder, copying over outputs once complete, so temp files are not retained"""
100115
input:
101116
in_img=get_nnunet_input,
102117
model_tar=get_model_tar(),
103118
params:
104-
temp_img="tempimg/temp_0000.nii.gz",
119+
cmd_copy_inputs=get_cmd_copy_inputs,
105120
temp_lbl="templbl/temp.nii.gz",
106121
model_dir="tempmodel",
107122
in_folder="tempimg",
@@ -148,7 +163,7 @@ rule run_inference:
148163
# run inference
149164
#copy from temp output folder to final output
150165
"mkdir -p {params.model_dir} {params.in_folder} {params.out_folder} && "
151-
"cp {input.in_img} {params.temp_img} && "
166+
"{params.cmd_copy_inputs} && "
152167
"tar -xf {input.model_tar} -C {params.model_dir} && "
153168
"export RESULTS_FOLDER={params.model_dir} && "
154169
"export nnUNet_n_proc_DA={threads} && "

0 commit comments

Comments
 (0)