@@ -19,17 +19,17 @@ disk.
1919
2020Nibabel does not load the image array from the proxy when you ``load `` the
2121image. It waits until you ask for the array data. The standard way to ask
22- for the array data is to call the ``get_data () `` method:
22+ for the array data is to call the ``get_fdata () `` method:
2323
24- >>> data = img.get_data ()
24+ >>> data = img.get_fdata ()
2525>>> data.shape
2626(128, 96, 24, 2)
2727
28- We also saw in :ref: `proxies-caching ` that this call to ``get_data () `` will
28+ We also saw in :ref: `proxies-caching ` that this call to ``get_fdata () `` will
2929(by default) load the array data into an internal image cache. The image
30- returns the cached copy on the next call to ``get_data () ``:
30+ returns the cached copy on the next call to ``get_fdata () ``:
3131
32- >>> data_again = img.get_data ()
32+ >>> data_again = img.get_fdata ()
3333>>> data is data_again
3434True
3535
@@ -64,7 +64,7 @@ in cache, and True when it is in cache:
6464>>> img = nib.load(example_file)
6565>>> img.in_memory
6666False
67- >>> data = img.get_data ()
67+ >>> data = img.get_fdata ()
6868>>> img.in_memory
6969True
7070
7373Using ``uncache ``
7474*****************
7575
76- As y'all know, the proxy image has the array in cache, ``get_data () `` returns
76+ As y'all know, the proxy image has the array in cache, ``get_fdata () `` returns
7777the cached array:
7878
79- >>> data_again = img.get_data ()
79+ >>> data_again = img.get_fdata ()
8080>>> data_again is data # same array returned from cache
8181True
8282
@@ -85,34 +85,34 @@ You can uncache a proxy image with the ``uncache()`` method:
8585>>> img.uncache()
8686>>> img.in_memory
8787False
88- >>> data_once_more = img.get_data ()
88+ >>> data_once_more = img.get_fdata ()
8989>>> data_once_more is data # a new copy read from disk
9090False
9191
9292``uncache() `` has no effect if the image is an array image, or if the cache is
9393already empty.
9494
95- You need to be careful when you modify arrays returned by ``get_data () `` on
95+ You need to be careful when you modify arrays returned by ``get_fdata () `` on
9696proxy images, because ``uncache `` will then change the result you get back
97- from ``get_data () ``:
97+ from ``get_fdata () ``:
9898
9999>>> proxy_img = nib.load(example_file)
100- >>> data = proxy_img.get_data () # array cached and returned
100+ >>> data = proxy_img.get_fdata () # array cached and returned
101101>>> data[0 , 0 , 0 , 0 ]
102- 0
102+ 0.0
103103>>> data[0 , 0 , 0 , 0 ] = 99 # modify returned array
104- >>> data_again = proxy_img.get_data () # return cached array
104+ >>> data_again = proxy_img.get_fdata () # return cached array
105105>>> data_again[0 , 0 , 0 , 0 ] # cached array modified
106- 99
106+ 99.0
107107
108108So far the proxy image behaves the same as an array image. ``uncache() `` has
109109no effect on an array image, but it does have an effect on the returned array
110110of a proxy image:
111111
112112>>> proxy_img.uncache() # cached array discarded from proxy image
113- >>> data_once_more = proxy_img.get_data () # new copy of array loaded
113+ >>> data_once_more = proxy_img.get_fdata () # new copy of array loaded
114114>>> data_once_more[0 , 0 , 0 , 0 ] # array modifications discarded
115- 0
115+ 0.0
116116
117117*************
118118Saving memory
@@ -126,8 +126,8 @@ use the ``uncache()`` method:
126126
127127>>> img.uncache()
128128
129- Use the array proxy instead of ``get_data () ``
130- =============================================
129+ Use the array proxy instead of ``get_fdata () ``
130+ ==============================================
131131
132132The ``dataobj `` property of a proxy image is an array proxy. We can ask the
133133proxy to return the array directly by passing ``dataobj `` to the numpy
@@ -145,47 +145,47 @@ This also works for array images, because ``np.asarray`` returns the array:
145145>>> type (data_array)
146146<... 'numpy.ndarray'>
147147
148- If you want to avoid caching you can avoid ``get_data () `` and always use
148+ If you want to avoid caching you can avoid ``get_fdata () `` and always use
149149``np.asarray(img.dataobj) ``.
150150
151- Use the ``caching `` keyword to ``get_data () ``
152- =============================================
151+ Use the ``caching `` keyword to ``get_fdata () ``
152+ ==============================================
153153
154- The default behavior of the ``get_data () `` function is to always fill the
154+ The default behavior of the ``get_fdata () `` function is to always fill the
155155cache, if it is empty. This corresponds to the default ``'fill' `` value
156156to the ``caching `` keyword. So, this:
157157
158158>>> proxy_img = nib.load(example_file)
159- >>> data = proxy_img.get_data () # default caching='fill'
159+ >>> data = proxy_img.get_fdata () # default caching='fill'
160160>>> proxy_img.in_memory
161161True
162162
163163is the same as this:
164164
165165>>> proxy_img = nib.load(example_file)
166- >>> data = proxy_img.get_data (caching = ' fill' )
166+ >>> data = proxy_img.get_fdata (caching = ' fill' )
167167>>> proxy_img.in_memory
168168True
169169
170170Sometimes you may want to avoid filling the cache, if it is empty. In this
171171case, you can use ``caching='unchanged' ``:
172172
173173>>> proxy_img = nib.load(example_file)
174- >>> data = proxy_img.get_data (caching = ' unchanged' )
174+ >>> data = proxy_img.get_fdata (caching = ' unchanged' )
175175>>> proxy_img.in_memory
176176False
177177
178178``caching='unchanged' `` will leave the cache full if it is already full.
179179
180- >>> data = proxy_img.get_data (caching = ' fill' )
180+ >>> data = proxy_img.get_fdata (caching = ' fill' )
181181>>> proxy_img.in_memory
182182True
183- >>> data = proxy_img.get_data (caching = ' unchanged' )
183+ >>> data = proxy_img.get_fdata (caching = ' unchanged' )
184184>>> proxy_img.in_memory
185185True
186186
187- See the :meth: `get_data () docstring
188- <nibabel.spatialimages.SpatialImage.get_data > ` for more detail.
187+ See the :meth: `get_fdata () docstring
188+ <nibabel.spatialimages.SpatialImage.get_fdata > ` for more detail.
189189
190190**********************
191191Saving time and memory
@@ -202,7 +202,7 @@ For example, let us say you only wanted the second volume from the example
202202dataset. You could do this:
203203
204204>>> proxy_img = nib.load(example_file)
205- >>> data = proxy_img.get_data ()
205+ >>> data = proxy_img.get_fdata ()
206206>>> data.shape
207207(128, 96, 24, 2)
208208>>> vol1 = data[... , 1 ]
0 commit comments