22
22
#
23
23
"""Parser."""
24
24
import sys
25
+
25
26
from .. import config
26
27
27
28
@@ -30,15 +31,14 @@ def _build_parser(**kwargs):
30
31
31
32
``kwargs`` are passed to ``argparse.ArgumentParser`` (mainly useful for debugging).
32
33
"""
34
+ from argparse import ArgumentDefaultsHelpFormatter , ArgumentParser
33
35
from functools import partial
34
36
from pathlib import Path
35
- from argparse import (
36
- ArgumentParser ,
37
- ArgumentDefaultsHelpFormatter ,
38
- )
37
+
38
+ from niworkflows .utils .spaces import OutputReferencesAction , Reference
39
39
from packaging .version import Version
40
+
40
41
from .version import check_latest , is_flagged
41
- from niworkflows .utils .spaces import Reference , OutputReferencesAction
42
42
43
43
def _path_exists (path , parser ):
44
44
"""Ensure a given path exists."""
@@ -61,25 +61,24 @@ def _min_one(value, parser):
61
61
return value
62
62
63
63
def _to_gb (value ):
64
- scale = {"G" : 1 , "T" : 10 ** 3 , "M" : 1e-3 , "K" : 1e-6 , "B" : 1e-9 }
64
+ scale = {"G" : 1 , "T" : 10 ** 3 , "M" : 1e-3 , "K" : 1e-6 , "B" : 1e-9 }
65
65
digits = "" .join ([c for c in value if c .isdigit ()])
66
- units = value [len (digits ):] or "M"
66
+ units = value [len (digits ) :] or "M"
67
67
return int (digits ) * scale [units [0 ]]
68
68
69
69
def _drop_sub (value ):
70
70
return value [4 :] if value .startswith ("sub-" ) else value
71
71
72
72
def _filter_pybids_none_any (dct ):
73
73
import bids
74
+
74
75
return {
75
- k : bids .layout .Query .NONE
76
- if v is None
77
- else (bids .layout .Query .ANY if v == "*" else v )
76
+ k : bids .layout .Query .NONE if v is None else (bids .layout .Query .ANY if v == "*" else v )
78
77
for k , v in dct .items ()
79
78
}
80
79
81
80
def _bids_filter (value , parser ):
82
- from json import loads , JSONDecodeError
81
+ from json import JSONDecodeError , loads
83
82
84
83
if value :
85
84
if Path (value ).exists ():
@@ -98,17 +97,16 @@ def _slice_time_ref(value, parser):
98
97
try :
99
98
value = float (value )
100
99
except ValueError :
101
- raise parser .error ("Slice time reference must be number, 'start', or 'middle'. "
102
- f"Received { value } ." )
100
+ raise parser .error (
101
+ "Slice time reference must be number, 'start', or 'middle'. " f"Received { value } ."
102
+ )
103
103
if not 0 <= value <= 1 :
104
104
raise parser .error (f"Slice time reference must be in range 0-1. Received { value } ." )
105
105
return value
106
106
107
107
verstr = f"fMRIPrep v{ config .environment .version } "
108
108
currentv = Version (config .environment .version )
109
- is_release = not any (
110
- (currentv .is_devrelease , currentv .is_prerelease , currentv .is_postrelease )
111
- )
109
+ is_release = not any ((currentv .is_devrelease , currentv .is_prerelease , currentv .is_postrelease ))
112
110
113
111
parser = ArgumentParser (
114
112
description = "fMRIPrep: fMRI PREProcessing workflows v{}" .format (
@@ -206,7 +204,7 @@ def _slice_time_ref(value, parser):
206
204
metavar = "PATH" ,
207
205
type = Path ,
208
206
help = "Path to a PyBIDS database folder, for faster indexing (especially "
209
- "useful for large datasets). Will be created if not present."
207
+ "useful for large datasets). Will be created if not present." ,
210
208
)
211
209
212
210
g_perfm = parser .add_argument_group ("Options to handle performance" )
@@ -239,8 +237,7 @@ def _slice_time_ref(value, parser):
239
237
g_perfm .add_argument (
240
238
"--low-mem" ,
241
239
action = "store_true" ,
242
- help = "attempt to reduce memory usage (will increase disk usage "
243
- "in working directory)" ,
240
+ help = "attempt to reduce memory usage (will increase disk usage " "in working directory)" ,
244
241
)
245
242
g_perfm .add_argument (
246
243
"--use-plugin" ,
@@ -250,9 +247,7 @@ def _slice_time_ref(value, parser):
250
247
type = IsFile ,
251
248
help = "nipype plugin configuration file" ,
252
249
)
253
- g_perfm .add_argument (
254
- "--anat-only" , action = "store_true" , help = "run anatomical workflows only"
255
- )
250
+ g_perfm .add_argument ("--anat-only" , action = "store_true" , help = "run anatomical workflows only" )
256
251
g_perfm .add_argument (
257
252
"--boilerplate_only" ,
258
253
action = "store_true" ,
@@ -321,7 +316,7 @@ def _slice_time_ref(value, parser):
321
316
default = False ,
322
317
help = """\
323
318
Output individual echo time series with slice, motion and susceptibility correction. \
324
- Useful for further Tedana processing post-fMRIPrep."""
319
+ Useful for further Tedana processing post-fMRIPrep.""",
325
320
)
326
321
327
322
g_conf .add_argument (
@@ -370,9 +365,9 @@ def _slice_time_ref(value, parser):
370
365
default = None ,
371
366
type = SliceTimeRef ,
372
367
help = "The time of the reference slice to correct BOLD values to, as a fraction "
373
- "acquisition time. 0 indicates the start, 0.5 the midpoint, and 1 the end "
374
- "of acquisition. The alias `start` corresponds to 0, and `middle` to 0.5. "
375
- "The default value is 0.5." ,
368
+ "acquisition time. 0 indicates the start, 0.5 the midpoint, and 1 the end "
369
+ "of acquisition. The alias `start` corresponds to 0, and `middle` to 0.5. "
370
+ "The default value is 0.5." ,
376
371
)
377
372
g_conf .add_argument (
378
373
"--dummy-scans" ,
@@ -438,8 +433,7 @@ def _slice_time_ref(value, parser):
438
433
action = "store" ,
439
434
default = 1.5 ,
440
435
type = float ,
441
- help = "Threshold for flagging a frame as an outlier on the basis of standardised "
442
- "DVARS" ,
436
+ help = "Threshold for flagging a frame as an outlier on the basis of standardised " "DVARS" ,
443
437
)
444
438
445
439
# ANTs options
@@ -499,7 +493,7 @@ def _slice_time_ref(value, parser):
499
493
const = "error" ,
500
494
default = False ,
501
495
help = "EXPERIMENTAL: Use fieldmap-free distortion correction; "
502
- "if unable, error (default) or warn based on optional argument." ,
496
+ "if unable, error (default) or warn based on optional argument." ,
503
497
)
504
498
g_syn .add_argument (
505
499
"--force-syn" ,
@@ -562,7 +556,7 @@ def _slice_time_ref(value, parser):
562
556
help = "Organization of outputs. bids (default) places fMRIPrep derivatives "
563
557
"directly in the output directory, and defaults to placing FreeSurfer "
564
558
"derivatives in <output-dir>/sourcedata/freesurfer. legacy creates "
565
- "derivative datasets as subdirectories of outputs."
559
+ "derivative datasets as subdirectories of outputs." ,
566
560
)
567
561
g_other .add_argument (
568
562
"-w" ,
@@ -597,7 +591,8 @@ def _slice_time_ref(value, parser):
597
591
action = "store" ,
598
592
metavar = "FILE" ,
599
593
help = "Use pre-generated configuration file. Values in file will be overridden "
600
- "by command-line arguments." )
594
+ "by command-line arguments." ,
595
+ )
601
596
g_other .add_argument (
602
597
"--write-graph" ,
603
598
action = "store_true" ,
@@ -608,8 +603,7 @@ def _slice_time_ref(value, parser):
608
603
"--stop-on-first-crash" ,
609
604
action = "store_true" ,
610
605
default = False ,
611
- help = "Force stopping on first crash, even if a work directory"
612
- " was specified." ,
606
+ help = "Force stopping on first crash, even if a work directory" " was specified." ,
613
607
)
614
608
g_other .add_argument (
615
609
"--notrack" ,
@@ -665,6 +659,7 @@ def _slice_time_ref(value, parser):
665
659
def parse_args (args = None , namespace = None ):
666
660
"""Parse args and run further checks on the command line."""
667
661
import logging
662
+
668
663
from niworkflows .utils .spaces import Reference , SpatialReferences
669
664
670
665
parser = _build_parser ()
@@ -680,6 +675,7 @@ def parse_args(args=None, namespace=None):
680
675
681
676
if not config .execution .notrack :
682
677
import pkgutil
678
+
683
679
if pkgutil .find_loader ("sentry_sdk" ) is None :
684
680
config .execution .notrack = True
685
681
config .loggers .cli .warning ("Telemetry disabled because sentry_sdk is not installed." )
@@ -759,9 +755,7 @@ def parse_args(args=None, namespace=None):
759
755
760
756
build_log .info (f"Clearing previous fMRIPrep working directory: { work_dir } " )
761
757
if not clean_directory (work_dir ):
762
- build_log .warning (
763
- f"Could not clear all contents of working directory: { work_dir } "
764
- )
758
+ build_log .warning (f"Could not clear all contents of working directory: { work_dir } " )
765
759
766
760
# Update the config with an empty dict to trigger initialization of all config
767
761
# sections (we used `init=False` above).
@@ -793,9 +787,7 @@ def parse_args(args=None, namespace=None):
793
787
"Making sure the input data is BIDS compliant (warnings can be ignored in most "
794
788
"cases)."
795
789
)
796
- validate_input_dir (
797
- config .environment .exec_env , opts .bids_dir , opts .participant_label
798
- )
790
+ validate_input_dir (config .environment .exec_env , opts .bids_dir , opts .participant_label )
799
791
800
792
# Setup directories
801
793
config .execution .log_dir = config .execution .fmriprep_dir / "logs"
0 commit comments