5
5
from pydra .engine .specs import ShellSpec , ShellOutSpec , File , Directory , SpecInfo
6
6
7
7
8
- def out_file_path (out_dir , filename , file_suffix , ext ):
8
+ def out_file_path (out_dir , filename , file_postfix , ext ):
9
9
"""Attempting to handle the different suffixes that are appended to filenames
10
10
created by Dcm2niix (see https://github.com/rordenlab/dcm2niix/blob/master/FILENAMING.md)
11
11
"""
12
12
13
- fpath = Path (out_dir ) / filename
14
- fpath = fpath .with_suffix (( file_suffix if file_suffix else "" ) + ext ). absolute ()
13
+ fpath = Path (out_dir ) / ( filename + ( file_postfix if file_postfix else "" ) + ext )
14
+ fpath = fpath .absolute ()
15
15
16
16
# Check to see if multiple echos exist in the DICOM dataset
17
17
if not fpath .exists ():
18
- if file_suffix is not None : # NB: doesn't match attrs.NOTHING
18
+ if file_postfix is not None : # NB: doesn't match attrs.NOTHING
19
19
neighbours = [
20
20
str (p ) for p in fpath .parent .iterdir () if p .name .endswith (ext )
21
21
]
22
22
raise ValueError (
23
- f"\n Did not find expected file '{ fpath } ' (file_suffix= { file_suffix } ) "
23
+ f"\n Did not find expected file '{ fpath } ' (file_postfix= { file_postfix } ) "
24
24
"after DICOM -> NIfTI conversion, please see "
25
25
"https://github.com/rordenlab/dcm2niix/blob/master/FILENAMING.md for the "
26
- "list of suffixes that dcm2niix produces and provide an appropriate "
27
- "suffix , or set suffix to None to ignore matching a single file and use "
26
+ "list of postfixes that dcm2niix produces and provide an appropriate "
27
+ "postfix , or set postfix to None to ignore matching a single file and use "
28
28
"the list returned in 'out_files' instead. Found the following files "
29
29
"with matching extensions:\n " + "\n " .join (neighbours )
30
30
)
@@ -34,20 +34,20 @@ def out_file_path(out_dir, filename, file_suffix, ext):
34
34
return fpath
35
35
36
36
37
- def dcm2niix_out_file (out_dir , filename , suffix , compress ):
37
+ def dcm2niix_out_file (out_dir , filename , file_postfix , compress ):
38
38
39
39
ext = ".nii"
40
40
# If compressed, append the zip extension
41
41
if compress in ("y" , "o" , "i" ):
42
42
ext += ".gz"
43
43
44
- return out_file_path (out_dir , filename , suffix , ext )
44
+ return out_file_path (out_dir , filename , file_postfix , ext )
45
45
46
46
47
- def dcm2niix_out_json (out_dir , filename , suffix , bids ):
47
+ def dcm2niix_out_json (out_dir , filename , file_postfix , bids ):
48
48
# Append echo number of NIfTI echo to select is provided
49
- if bids in ("y" , "o" ):
50
- fpath = out_file_path (out_dir , filename , suffix , ".json" )
49
+ if bids is attrs . NOTHING or bids in ("y" , "o" ):
50
+ fpath = out_file_path (out_dir , filename , file_postfix , ".json" )
51
51
else :
52
52
fpath = attrs .NOTHING
53
53
return fpath
@@ -88,21 +88,19 @@ def dcm2niix_out_files(out_dir, filename):
88
88
{"argstr" : "-f '{filename}'" , "help_string" : "The output name for the file" },
89
89
),
90
90
(
91
- "file_suffix " ,
91
+ "file_postfix " ,
92
92
str ,
93
93
{
94
94
"help_string" : (
95
- "The suffix appended to the output filename, used to select which "
95
+ "The postfix appended to the output filename. Used to select which "
96
96
"of the disambiguated nifti files created by dcm2niix to return "
97
97
"in this field (see https://github.com/"
98
98
"rordenlab/dcm2niix/blob/master/FILENAMING.md"
99
99
"#file-name-post-fixes-image-disambiguation). Set to None to skip "
100
100
"matching a single file (out_file will be set to attrs.NOTHING if the "
101
- "base filepath without suffixes doesn't exist) and handle the list of "
101
+ "base path without postfixes doesn't exist) and handle the list of "
102
102
"output files returned in 'out_files' instead."
103
103
),
104
- "xor" : ["echo" ],
105
- "allowed_values" : ["Eq" , "ph" , "imaginary" , "MoCo" , "real" , "phMag" ],
106
104
},
107
105
),
108
106
(
@@ -355,8 +353,11 @@ def dcm2niix_out_files(out_dir, filename):
355
353
File ,
356
354
{
357
355
"help_string" : (
358
- "output NIfTI image. If multiple nifti files are created and 'suffix' "
359
- "is provided then " ,
356
+ "output NIfTI image. If multiple nifti files are created (e.g. for "
357
+ "different echoes), then the 'file_postfix' input can be provided to "
358
+ "select which of them is considered the 'out_file'. Otherwise it "
359
+ "should be set to None and 'out_files' used instead (in which case "
360
+ "'out_file' will be set to attrs.NOTHING)" ,
360
361
),
361
362
"callable" : dcm2niix_out_file ,
362
363
"mandatory" : True ,
@@ -389,7 +390,7 @@ def dcm2niix_out_files(out_dir, filename):
389
390
),
390
391
(
391
392
"out_files" ,
392
- ty . List [ File ] ,
393
+ list ,
393
394
{
394
395
"help_string" : (
395
396
"all output files in a list, including files disambiguated "
0 commit comments