@@ -558,6 +558,61 @@ def _run_interface(self, runtime):
558
558
return runtime
559
559
560
560
561
+ class CreateSurfaceROIInputSpec (TraitedSpec ):
562
+ subject_id = traits .Str (desc = 'subject ID' )
563
+ hemisphere = traits .Enum (
564
+ "L" ,
565
+ "R" ,
566
+ mandatory = True ,
567
+ desc = 'hemisphere' ,
568
+ )
569
+ thickness_file = File (exists = True , mandatory = True , desc = 'input GIFTI file' )
570
+
571
+
572
+ class CreateSurfaceROIOutputSpec (TraitedSpec ):
573
+ roi_file = File (desc = 'output GIFTI file' )
574
+
575
+
576
+ class CreateSurfaceROI (SimpleInterface ):
577
+ """Prepare GIFTI shape file for use in"""
578
+
579
+ input_spec = CreateSurfaceROIInputSpec
580
+ output_spec = CreateSurfaceROIOutputSpec
581
+
582
+ def _run_interface (self , runtime ):
583
+ subject , hemi = self .inputs .subject_id , self .inputs .hemisphere
584
+ if not isdefined (subject ):
585
+ subject = 'sub-XYZ'
586
+ img = nb .GiftiImage .from_filename (self .inputs .thickness_file )
587
+ # wb_command -set-structure
588
+ img .meta ["AnatomicalStructurePrimary" ] = {'L' : 'CortexLeft' , 'R' : 'CortexRight' }[hemi ]
589
+ darray = img .darrays [0 ]
590
+ # wb_command -set-map-names
591
+ meta = darray .meta
592
+ meta ['Name' ] = f"{ subject } _{ hemi } _ROI"
593
+ # wb_command -metric-palette calls have no effect on ROI files
594
+
595
+ # Compiling an odd sequence of math operations that works out to:
596
+ # wb_command -metric-math "abs(var * -1) > 0"
597
+ roi = np .abs (darray .data ) > 0
598
+
599
+ darray = nb .gifti .GiftiDataArray (
600
+ roi ,
601
+ intent = darray .intent ,
602
+ datatype = darray .datatype ,
603
+ encoding = darray .encoding ,
604
+ endian = darray .endian ,
605
+ coordsys = darray .coordsys ,
606
+ ordering = darray .ind_ord ,
607
+ meta = meta ,
608
+ )
609
+
610
+ out_filename = os .path .join (runtime .cwd , f"{ subject } .{ hemi } .roi.native.shape.gii" )
611
+ img .to_filename (out_filename )
612
+ self ._results ["roi_file" ] = out_filename
613
+ return runtime
614
+
615
+
561
616
def normalize_surfs (in_file , transform_file , newpath = None ):
562
617
"""
563
618
Re-center GIFTI coordinates to fit align to native T1w space.
0 commit comments