@@ -682,9 +682,46 @@ def get_arrays_from_intent(self, intent):
682
682
683
683
def agg_data (self , intent_code = None ):
684
684
"""
685
- Retrun a numpy arrary of aggregated GiftiDataArray of the same intent code
686
- or
687
- Retrun GiftiDataArray in tuples for surface files
685
+ Aggregate GIFTI data arrays into an ndarray or tuple of ndarray
686
+
687
+ In the general case, the numpy data array is extracted from each ``GiftiDataArray``
688
+ object and returned in a ``tuple``, in the order they are found in the GIFTI image.
689
+
690
+ If all ``GiftiDataArray``s have ``intent`` of 2001 (``NIFTI_INTENT_TIME_SERIES``),
691
+ then the data arrays are concatenated as columns, producing a vertex-by-time array.
692
+ If an ``intent_code`` is passed, data arrays are filtered by the selected intents,
693
+ before being aggregated.
694
+ This may be useful for images containing several intents, or ensuring an expected
695
+ data type in an image of uncertain provenance.
696
+ If ``intent_code`` is a ``tuple``, then a ``tuple`` will be returned with the result of
697
+ ``agg_data`` for each element, in order.
698
+ This may be useful for ensuring that expected data arrives in a consistent order.
699
+
700
+ Examples:
701
+ >>> import nibabel as nib
702
+ >>> gii_fname = # something/something.surf.gii
703
+ >>> gii_img = nib.load(gii_fname)
704
+
705
+ When not passing anything to``intent_code``
706
+ >>> gii_img.agg_data()
707
+
708
+ When passig matching intend codes ``intent_code``
709
+ >>> gii_img.agg_data('pointset')
710
+
711
+ >>> gii_img.agg_data('triangle')
712
+
713
+ >>> gii_img.agg_data('time series')
714
+
715
+ When passing mismatching intent codes ``intent_code``
716
+ >>> gii_img.agg_data('time series')
717
+ () # return a empty ``tuple``
718
+
719
+ When passing tuple ``intent_code``
720
+ >>> gii_img.agg_data(('pointset', 'triangle'))
721
+
722
+ >>> gii_img.agg_data(('triangle', 'pointset'))
723
+
724
+
688
725
689
726
Parameters
690
727
----------
@@ -705,18 +742,15 @@ def agg_data(self, intent_code=None):
705
742
706
743
darrays = self .darrays if intent_code is None else self .get_arrays_from_intent (intent_code )
707
744
all_data = tuple (da .data for da in darrays )
708
- all_intent = {da .intent for da in darrays }
745
+ all_intent = {intent_codes . niistring [ da .intent ] for da in darrays }
709
746
710
- # Gifti files allows usually one or more data array of the same intent code
711
- # surf.gii is a special case of having two data array of different intent code
747
+ if all_intent == { 'NIFTI_INTENT_TIME_SERIES' }: # stack when the gifti is a timeseries
748
+ return np . column_stack ( all_data )
712
749
713
- if self .numDA > 1 and len (all_intent ) == 1 :
714
- if all_intent == 'NIFTI_INTENT_TIME_SERIES' : # stack when the gifti is a timeseries
715
- return np .column_stack (all_data )
716
- else :
717
- return all_data
718
- else :
719
- return all_data
750
+ if len (all_data ) == 1 :
751
+ all_data = all_data [0 ]
752
+
753
+ return all_data
720
754
721
755
@deprecate_with_version (
722
756
'getArraysFromIntent method deprecated. '
0 commit comments