60
60
force_syn = false
61
61
hires = true
62
62
ignore = []
63
- internal_spaces = "MNI152NLin2009cAsym"
64
63
longitudinal = false
65
64
medial_surface_nan = false
66
65
run_reconall = true
@@ -368,7 +367,8 @@ class execution(_Config):
368
367
output_dir = None
369
368
"""Folder where derivatives will be stored."""
370
369
output_spaces = None
371
- """List of (non)standard spaces designated as spatial references for outputs."""
370
+ """List of (non)standard spaces designated (with the ``--output-spaces`` flag of
371
+ the command line) as spatial references for outputs."""
372
372
reports_only = False
373
373
"""Only build the reports, based on the reportlets found in a cached working directory."""
374
374
run_uuid = '%s_%s' % (strftime ('%Y%m%d-%H%M%S' ), uuid4 ())
@@ -435,8 +435,6 @@ class workflow(_Config):
435
435
"""Run FreeSurfer ``recon-all`` with the ``-hires`` flag."""
436
436
ignore = None
437
437
"""Ignore particular steps for *fMRIPrep*."""
438
- internal_spaces = None
439
- """Standard and nonstandard spaces."""
440
438
longitudinal = False
441
439
"""Run FreeSurfer ``recon-all`` with the ``-logitudinal`` flag."""
442
440
medial_surface_nan = None
@@ -454,7 +452,8 @@ class workflow(_Config):
454
452
skull_strip_template = "OASIS30ANTs"
455
453
"""Change default brain extraction template."""
456
454
spaces = None
457
- """Standard and nonstandard spaces."""
455
+ """Keeps the :py:class:`~niworkflows.utils.spaces.SpatialReferences`
456
+ instance keeping standard and nonstandard spaces."""
458
457
t2s_coreg = None
459
458
"""Co-register echos before generating the T2\\ * reference of
460
459
:abbr:`ME-EPI (multi-echo echo-planar imaging)`."""
@@ -513,6 +512,7 @@ def load(filename):
513
512
if sectionname != 'environment' :
514
513
section = getattr (sys .modules [__name__ ], sectionname )
515
514
section .load (configs )
515
+ init_nipype ()
516
516
init_loggers ()
517
517
init_spaces ()
518
518
init_layout ()
@@ -564,6 +564,7 @@ def init_layout():
564
564
565
565
def init_loggers ():
566
566
"""Set the current log level to all loggers."""
567
+ from nipype import config as ncfg
567
568
_handler = logging .StreamHandler (stream = sys .stdout )
568
569
_handler .setFormatter (
569
570
logging .Formatter (fmt = loggers ._fmt , datefmt = loggers ._datefmt )
@@ -574,35 +575,78 @@ def init_loggers():
574
575
loggers .interface .setLevel (execution .log_level )
575
576
loggers .workflow .setLevel (execution .log_level )
576
577
loggers .utils .setLevel (execution .log_level )
578
+ ncfg .update_config ({
579
+ 'logging' : {
580
+ 'log_directory' : str (execution .log_dir ),
581
+ 'log_to_file' : True
582
+ },
583
+ })
577
584
578
585
579
586
def init_spaces (checkpoint = True ):
580
587
"""Initialize the :attr:`~workflow.spaces` setting."""
581
588
from niworkflows .utils .spaces import Reference , SpatialReferences
582
- if (
583
- getattr (workflow , 'spaces' )
584
- and isinstance (workflow .spaces , SpatialReferences )
585
- ):
586
- return
587
-
588
589
spaces = execution .output_spaces
589
- if spaces is not None and not isinstance (spaces , _SRs ):
590
+ if not isinstance (spaces , SpatialReferences ):
590
591
spaces = SpatialReferences (
591
592
[ref for s in execution .output_spaces .split (' ' )
592
593
for ref in Reference .from_string (s )]
593
594
)
594
- if spaces is None :
595
- spaces = _SRs ()
595
+
596
+ # Add the default standard space if not already present (required by several sub-workflows)
597
+ if "MNI152NLin2009cAsym" not in spaces .get_spaces (nonstandard = False , dim = (3 ,)):
598
+ spaces .add (
599
+ Reference ("MNI152NLin2009cAsym" , {"res" : "native" })
600
+ )
596
601
597
602
if checkpoint :
598
603
spaces .checkpoint ()
599
604
600
- if workflow .internal_spaces :
601
- internal = [
602
- Reference .from_string (ref )
603
- for ref in workflow .internal_spaces .strip ().split (' ' )
604
- ]
605
- spaces += [
606
- ref [0 ] for ref in internal if ref [0 ].fullname not in spaces
607
- ]
605
+ # Ensure user-defined spatial references for outputs are correctly parsed.
606
+ # Certain options require normalization to a space not explicitly defined by users.
607
+ # These spaces will not be included in the final outputs.
608
+ if workflow .use_aroma :
609
+ # Make sure there's a normalization to FSL for AROMA to use.
610
+ spaces .add (
611
+ Reference ("MNI152NLin6Asym" , {"res" : "2" })
612
+ )
613
+
614
+ cifti_output = workflow .cifti_output
615
+ if cifti_output :
616
+ # CIFTI grayordinates to corresponding FSL-MNI resolutions.
617
+ vol_res = '2' if cifti_output == '91k' else '1'
618
+ spaces .add (
619
+ Reference ("fsaverage" , {"den" : "164k" })
620
+ )
621
+ spaces .add (
622
+ Reference ("MNI152NLin6Asym" , {"res" : vol_res })
623
+ )
624
+
625
+ # Make the SpatialReferences object available
608
626
workflow .spaces = spaces
627
+
628
+
629
+ def init_nipype ():
630
+ """Set NiPype configurations."""
631
+ from nipype import config as ncfg
632
+
633
+ # Configure resource_monitor
634
+ if nipype .resource_monitor :
635
+ ncfg .update_config ({
636
+ 'monitoring' : {
637
+ 'enabled' : nipype .resource_monitor ,
638
+ 'sample_frequency' : '0.5' ,
639
+ 'summary_append' : True ,
640
+ }
641
+ })
642
+ ncfg .enable_resource_monitor ()
643
+
644
+ # Nipype config (logs and execution)
645
+ ncfg .update_config ({
646
+ 'execution' : {
647
+ 'crashdump_dir' : str (execution .log_dir ),
648
+ 'crashfile_format' : nipype .crashfile_format ,
649
+ 'get_linked_libs' : nipype .get_linked_libs ,
650
+ 'stop_on_first_crash' : nipype .stop_on_first_crash ,
651
+ }
652
+ })
0 commit comments