Skip to content

Commit 1ecaa26

Browse files
committed
Move the docstring to test
1 parent 0447bbc commit 1ecaa26

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

nibabel/gifti/gifti.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -721,65 +721,24 @@ def agg_data(self, intent_code=None):
721721
When not passing anything to ``intent_code``
722722
723723
>>> surf_gii_img.agg_data() # surface file
724-
(array([[-16.07201 , -66.187515, 21.266994],
725-
[-16.705893, -66.05434 , 21.232786],
726-
[-17.61435 , -65.40164 , 21.071466]], dtype=float32), array([0, 1, 2], dtype=int32))
727724
>>> func_gii_img.agg_data() # functional file
728-
array([[ 545.4326 , 535.8471 , 537.5014 , ..., 540.2762 ,
729-
539.53827 , 541.3617 ],
730-
[ 640.0118 , 634.727 , 630.03784 , ..., 635.21936 ,
731-
641.19586 , 638.7647 ],
732-
[ 612.9056 , 607.3228 , 606.1355 , ..., 608.2441 ,
733-
615.8239 , 613.0585 ],
734-
...,
735-
[ 101.28482 , 101.41192 , 99.21213 , ..., 100.47232 ,
736-
99.258316, 99.440796],
737-
[ 371.81592 , 367.02896 , 363.90207 , ..., 365.52597 ,
738-
363.44937 , 363.10278 ],
739-
[ 268.6521 , 262.0212 , 259.06717 , ..., 262.5381 ,
740-
257.8245 , 259.7127 ]], dtype=float32)
741725
742726
When passig matching intend codes ``intent_code``
743727
744728
>>> surf_gii_img.agg_data('pointset') # surface pointset
745-
array([[-16.07201 , -66.187515, 21.266994],
746-
[-16.705893, -66.05434 , 21.232786],
747-
[-17.61435 , -65.40164 , 21.071466]], dtype=float32)
748729
>>> surf_gii_img.agg_data('triangle') # surface triangle
749-
array([0, 1, 2], dtype=int32)
750730
>>> func_gii_img.agg_data('time series') # functional file
751-
array([[ 545.4326 , 535.8471 , 537.5014 , ..., 540.2762 ,
752-
539.53827 , 541.3617 ],
753-
[ 640.0118 , 634.727 , 630.03784 , ..., 635.21936 ,
754-
641.19586 , 638.7647 ],
755-
[ 612.9056 , 607.3228 , 606.1355 , ..., 608.2441 ,
756-
615.8239 , 613.0585 ],
757-
...,
758-
[ 101.28482 , 101.41192 , 99.21213 , ..., 100.47232 ,
759-
99.258316, 99.440796],
760-
[ 371.81592 , 367.02896 , 363.90207 , ..., 365.52597 ,
761-
363.44937 , 363.10278 ],
762-
[ 268.6521 , 262.0212 , 259.06717 , ..., 262.5381 ,
763-
257.8245 , 259.7127 ]], dtype=float32)
764731
765732
When passing mismatching ``intent_code``, the function return a empty ``tuple``
766733
767734
>>> surf_gii_img.agg_data('time series')
768-
()
769735
>>> func_gii_img.agg_data('triangle')
770-
()
771736
772737
When passing tuple ``intent_code``, the output will follow
773738
the order of ``intent_code`` in the tuple
774739
775740
>>> surf_gii_img.agg_data(('pointset', 'triangle'))
776-
(array([[-16.07201 , -66.187515, 21.266994],
777-
[-16.705893, -66.05434 , 21.232786],
778-
[-17.61435 , -65.40164 , 21.071466]], dtype=float32), array([0, 1, 2], dtype=int32))
779741
>>> surf_gii_img.agg_data(('triangle', 'pointset'))
780-
(array([0, 1, 2], dtype=int32), array([[-16.07201 , -66.187515, 21.266994],
781-
[-16.705893, -66.05434 , 21.232786],
782-
[-17.61435 , -65.40164 , 21.071466]], dtype=float32))
783742
"""
784743

785744
# Allow multiple intents to specify the order

nibabel/gifti/tests/test_gifti.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,74 @@
1717
from numpy.testing import (assert_array_almost_equal,
1818
assert_array_equal)
1919
from nose.tools import (assert_true, assert_false, assert_equal, assert_raises)
20-
from nibabel.testing import clear_and_catch_warnings
20+
from nibabel.testing import clear_and_catch_warnings, test_data
2121
from .test_parse_gifti_fast import (DATA_FILE1, DATA_FILE2, DATA_FILE3,
2222
DATA_FILE4, DATA_FILE5, DATA_FILE6)
2323
import itertools
2424

2525

26+
def test_agg_data():
27+
"""
28+
Aggregate GIFTI data arrays into an ndarray or tuple of ndarray
29+
30+
Examples
31+
--------
32+
33+
Load two kinds of Gifti files: a surface file containing two types of intent code;
34+
a functional file storing time series data only.
35+
36+
>>> import nibabel as nib
37+
>>> from nibabel.testing import test_data
38+
>>> surf_gii_fname = test_data('gifti', 'ascii.gii')
39+
>>> surf_gii_img = nib.load(surf_gii_fname)
40+
>>> func_gii_fname = test_data('gifti', 'task.func.gii')
41+
>>> func_gii_img = nib.load(func_gii_fname)
42+
43+
When not passing anything to ``intent_code``
44+
45+
>>> surf_gii_img.agg_data() # surface file
46+
>>> func_gii_img.agg_data() # functional file
47+
48+
When passig matching intend codes ``intent_code``
49+
50+
>>> surf_gii_img.agg_data('pointset') # surface pointset
51+
>>> surf_gii_img.agg_data('triangle') # surface triangle
52+
>>> func_gii_img.agg_data('time series') # functional file
53+
54+
When passing mismatching ``intent_code``, the function return a empty ``tuple``
55+
56+
>>> surf_gii_img.agg_data('time series')
57+
>>> func_gii_img.agg_data('triangle')
58+
59+
When passing tuple ``intent_code``, the output will follow
60+
the order of ``intent_code`` in the tuple
61+
62+
>>> surf_gii_img.agg_data(('pointset', 'triangle'))
63+
>>> surf_gii_img.agg_data(('triangle', 'pointset'))
64+
"""
65+
66+
surf_gii_fname = test_data('gifti', 'ascii.gii')
67+
surf_gii_img = nib.load(surf_gii_fname)
68+
func_gii_fname = test_data('gifti', 'task.func.gii')
69+
func_gii_img = nib.load(func_gii_fname)
70+
71+
point_data = surf_gii_img.get_arrays_from_intent('pointset')[0].data
72+
triangle_data = surf_gii_img.get_arrays_from_intent('triangle')[0].data
73+
func_da = func_gii_img.get_arrays_from_intent('time series')
74+
func_data = np.column_stack(tuple(da.data for da in func_da))
75+
76+
assert_equal(surf_gii_img.agg_data(), (point_data, triangle_data)) # surface file
77+
assert_array_equal(func_gii_img.agg_data(), func_data) # functional
78+
assert_array_equal(surf_gii_img.agg_data('pointset'), point_data) # surface pointset
79+
assert_array_equal(surf_gii_img.agg_data('triangle'), triangle_data) # surface triangle
80+
assert_array_equal(func_gii_img.agg_data('time series'), func_data) # functional
81+
82+
assert_equal(surf_gii_img.agg_data('time series'), ())
83+
assert_equal(func_gii_img.agg_data('triangle'), ())
84+
85+
assert_equal(surf_gii_img.agg_data(('pointset', 'triangle')), (point_data, triangle_data))
86+
assert_equal(surf_gii_img.agg_data(('triangle', 'pointset')), (triangle_data, point_data))
87+
2688
def test_gifti_image():
2789
# Check that we're not modifying the default empty list in the default
2890
# arguments.

0 commit comments

Comments
 (0)