@@ -707,29 +707,91 @@ def agg_data(self, intent_code=None):
707707
708708 Examples
709709 --------
710- >>> import nibabel as nib
711- >>> from nibabel.testing import test_data
712- >>> surf_gii_fname = test_data('gifti', 'ascii.gii')
713- >>> surf_gii_img = nib.load(surf_gii_fname)
714- >>> func_gii_fname = test_data('gifti', 'task.func.gii')
715- >>> func_gii_img = nib.load(func_gii_fname)
716-
717- Retrieve data without passing ``intent code``
718-
719- >>> surf_data = surf_gii_img.agg_data()
720- >>> func_data = func_gii_img.agg_data()
721710
722- When passig matching intend codes ``intent_code``
711+ Consider a surface GIFTI file:
723712
724- >>> pointset_data = surf_gii_img.agg_data('pointset') # surface pointset
725- >>> triangle_data = surf_gii_img.agg_data('triangle') # surface triangle
726- >>> ts_data = func_gii_img.agg_data('time series') # functional file
727-
728- When passing mismatching ``intent_code``, the function return a empty ``tuple``
729-
730- >>> surf_gii_img.agg_data('time series')
713+ >>> import nibabel as nib
714+ >>> from nibabel.testing import test_data
715+ >>> surf_img = nib.load(test_data('gifti', 'ascii.gii'))
716+
717+ The coordinate data, which is indicated by the ``NIFTI_INTENT_POINTSET``
718+ intent code, may be retrieved using any of the following equivalent
719+ calls:
720+
721+ >>> coords = surf_img.agg_data('NIFTI_INTENT_POINTSET')
722+ >>> coords_2 = surf_img.agg_data('pointset')
723+ >>> coords_3 = surf_img.agg_data(1008) # Numeric code for pointset
724+ >>> print(np.array2string(coords, precision=3))
725+ [[-16.072 -66.188 21.267]
726+ [-16.706 -66.054 21.233]
727+ [-17.614 -65.402 21.071]]
728+ >>> np.array_equal(coords, coords_2)
729+ True
730+ >>> np.array_equal(coords, coords_3)
731+ True
732+
733+ Similarly, the triangle mesh can be retrieved using various intent
734+ specifiers:
735+
736+ >>> triangles = surf_img.agg_data('NIFTI_INTENT_TRIANGLE')
737+ >>> triangles_2 = surf_img.agg_data('triangle')
738+ >>> triangles_3 = surf_img.agg_data(1009) # Numeric code for pointset
739+ >>> print(np.array2string(triangles))
740+ [0 1 2]
741+ >>> np.array_equal(triangles, triangles_2)
742+ True
743+ >>> np.array_equal(triangles, triangles_3)
744+ True
745+
746+ All arrays can be retrieved as a ``tuple`` by omitting the intent
747+ code:
748+
749+ >>> coords_4, triangles_4 = surf_img.agg_data()
750+ >>> np.array_equal(coords, coords_4)
751+ True
752+ >>> np.array_equal(triangles, triangles_4)
753+ True
754+
755+ Finally, a tuple of intent codes may be passed in order to select
756+ the arrays in a specific order:
757+
758+ >>> triangles_5, coords_5 = surf_img.agg_data(('triangle', 'pointset'))
759+ >>> np.array_equal(triangles, triangles_5)
760+ True
761+ >>> np.array_equal(coords, coords_5)
762+ True
763+
764+ The following image is a GIFTI file with ten (10) data arrays of the same
765+ size, and with intent code 2001 (``NIFTI_INTENT_TIME_SERIES``):
766+
767+ >>> func_img = nib.load(test_data('gifti', 'task.func.gii'))
768+
769+ When aggregating time series data, these arrays are concatenated into
770+ a single, vertex-by-timestep array:
771+
772+ >>> series = func_img.agg_data()
773+ >>> series.shape
774+ (642, 10)
775+
776+ In the case of a GIFTI file with unknown data arrays, it may be preferable
777+ to specify the intent code, so that a time series array is always returned:
778+
779+ >>> series_2 = func_img.agg_data('NIFTI_INTENT_TIME_SERIES')
780+ >>> series_3 = func_img.agg_data('time series')
781+ >>> series_4 = func_img.agg_data(2001)
782+ >>> np.array_equal(series, series_2)
783+ True
784+ >>> np.array_equal(series, series_3)
785+ True
786+ >>> np.array_equal(series, series_4)
787+ True
788+
789+ Requesting a data array from a GIFTI file with no matching intent codes
790+ will result in an empty tuple:
791+
792+ >>> surf_img.agg_data('time series')
731793 ()
732- >>> func_gii_img .agg_data('triangle')
794+ >>> func_img .agg_data('triangle')
733795 ()
734796 """
735797
0 commit comments