Skip to content

Commit a17de8e

Browse files
authoredMar 22, 2024··
Merge pull request #3609 from mauriliogenovese/origin/fix/dcm2niix_crop
[FIX] Add cropped files to dcm2niix output
2 parents 685a1fb + cf926c0 commit a17de8e

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed
 

‎.zenodo.json

+5
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,11 @@
910910
"name": "Anijärv, Toomas Erik",
911911
"orcid": "0000-0002-3650-4230"
912912
},
913+
{
914+
"affiliation": "Azienda Ospedaliero-Universitaria di Modena",
915+
"name": "Genovese, Maurilio",
916+
"orcid": "0000-0002-8154-8224"
917+
},
913918
{
914919
"affiliation": "Department of Psychology, Stanford University",
915920
"name": "Gorgolewski, Krzysztof J.",

‎nipype/interfaces/dcm2nii.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def _parse_files(self, filenames):
470470

471471
for filename in filenames:
472472
# search for relevant files, and sort accordingly
473-
for fl in search_files(filename, outtypes):
473+
for fl in search_files(filename, outtypes, self.inputs.crop):
474474
if (
475475
fl.endswith(".nii")
476476
or fl.endswith(".gz")
@@ -508,7 +508,15 @@ def _list_outputs(self):
508508

509509

510510
# https://stackoverflow.com/a/4829130
511-
def search_files(prefix, outtypes):
512-
return it.chain.from_iterable(
511+
def search_files(prefix, outtypes, search_crop):
512+
found = it.chain.from_iterable(
513513
iglob(glob.escape(prefix + outtype)) for outtype in outtypes
514514
)
515+
if search_crop:
516+
found = it.chain(
517+
it.chain.from_iterable(
518+
iglob(glob.escape(prefix) + "_Crop_*" + outtype) for outtype in outtypes
519+
),
520+
found,
521+
)
522+
return found

‎nipype/interfaces/tests/test_dcm2nii.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@
55

66

77
@pytest.mark.parametrize(
8-
"fname, extension",
8+
"fname, extension, search_crop",
99
[
10-
("output_1", ".txt"),
11-
("output_w_[]_meta_1", ".json"),
12-
("output_w_**^$?_meta_2", ".txt"),
10+
("output_1", ".txt", False),
11+
("output_w_[]_meta_1", ".json", False),
12+
("output_w_**^$?_meta_2", ".txt", False),
13+
("output_cropped", ".txt", True),
1314
],
1415
)
15-
def test_search_files(tmp_path, fname, extension):
16+
def test_search_files(tmp_path, fname, extension, search_crop):
1617
tmp_fname = fname + extension
1718
test_file = tmp_path / tmp_fname
1819
test_file.touch()
19-
actual_files_list = dcm2nii.search_files(str(tmp_path / fname), [extension])
20+
if search_crop:
21+
tmp_cropped_fname = fname + "_Crop_1" + extension
22+
test_cropped_file = tmp_path / tmp_cropped_fname
23+
test_cropped_file.touch()
24+
25+
actual_files_list = dcm2nii.search_files(
26+
str(tmp_path / fname), [extension], search_crop
27+
)
2028
for f in actual_files_list:
21-
assert str(test_file) == f
29+
if search_crop:
30+
assert f in (str(test_cropped_file), str(test_file))
31+
else:
32+
assert str(test_file) == f

0 commit comments

Comments
 (0)
Please sign in to comment.