@@ -19,17 +19,17 @@ disk.
19
19
20
20
Nibabel does not load the image array from the proxy when you ``load `` the
21
21
image. 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:
23
23
24
- >>> data = img.get_data ()
24
+ >>> data = img.get_fdata ()
25
25
>>> data.shape
26
26
(128, 96, 24, 2)
27
27
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
29
29
(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 () ``:
31
31
32
- >>> data_again = img.get_data ()
32
+ >>> data_again = img.get_fdata ()
33
33
>>> data is data_again
34
34
True
35
35
@@ -64,7 +64,7 @@ in cache, and True when it is in cache:
64
64
>>> img = nib.load(example_file)
65
65
>>> img.in_memory
66
66
False
67
- >>> data = img.get_data ()
67
+ >>> data = img.get_fdata ()
68
68
>>> img.in_memory
69
69
True
70
70
73
73
Using ``uncache ``
74
74
*****************
75
75
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
77
77
the cached array:
78
78
79
- >>> data_again = img.get_data ()
79
+ >>> data_again = img.get_fdata ()
80
80
>>> data_again is data # same array returned from cache
81
81
True
82
82
@@ -85,34 +85,34 @@ You can uncache a proxy image with the ``uncache()`` method:
85
85
>>> img.uncache()
86
86
>>> img.in_memory
87
87
False
88
- >>> data_once_more = img.get_data ()
88
+ >>> data_once_more = img.get_fdata ()
89
89
>>> data_once_more is data # a new copy read from disk
90
90
False
91
91
92
92
``uncache() `` has no effect if the image is an array image, or if the cache is
93
93
already empty.
94
94
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
96
96
proxy images, because ``uncache `` will then change the result you get back
97
- from ``get_data () ``:
97
+ from ``get_fdata () ``:
98
98
99
99
>>> 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
101
101
>>> data[0 , 0 , 0 , 0 ]
102
- 0
102
+ 0.0
103
103
>>> 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
105
105
>>> data_again[0 , 0 , 0 , 0 ] # cached array modified
106
- 99
106
+ 99.0
107
107
108
108
So far the proxy image behaves the same as an array image. ``uncache() `` has
109
109
no effect on an array image, but it does have an effect on the returned array
110
110
of a proxy image:
111
111
112
112
>>> 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
114
114
>>> data_once_more[0 , 0 , 0 , 0 ] # array modifications discarded
115
- 0
115
+ 0.0
116
116
117
117
*************
118
118
Saving memory
@@ -126,8 +126,8 @@ use the ``uncache()`` method:
126
126
127
127
>>> img.uncache()
128
128
129
- Use the array proxy instead of ``get_data () ``
130
- =============================================
129
+ Use the array proxy instead of ``get_fdata () ``
130
+ ==============================================
131
131
132
132
The ``dataobj `` property of a proxy image is an array proxy. We can ask the
133
133
proxy 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:
145
145
>>> type (data_array)
146
146
<... 'numpy.ndarray'>
147
147
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
149
149
``np.asarray(img.dataobj) ``.
150
150
151
- Use the ``caching `` keyword to ``get_data () ``
152
- =============================================
151
+ Use the ``caching `` keyword to ``get_fdata () ``
152
+ ==============================================
153
153
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
155
155
cache, if it is empty. This corresponds to the default ``'fill' `` value
156
156
to the ``caching `` keyword. So, this:
157
157
158
158
>>> proxy_img = nib.load(example_file)
159
- >>> data = proxy_img.get_data () # default caching='fill'
159
+ >>> data = proxy_img.get_fdata () # default caching='fill'
160
160
>>> proxy_img.in_memory
161
161
True
162
162
163
163
is the same as this:
164
164
165
165
>>> proxy_img = nib.load(example_file)
166
- >>> data = proxy_img.get_data (caching = ' fill' )
166
+ >>> data = proxy_img.get_fdata (caching = ' fill' )
167
167
>>> proxy_img.in_memory
168
168
True
169
169
170
170
Sometimes you may want to avoid filling the cache, if it is empty. In this
171
171
case, you can use ``caching='unchanged' ``:
172
172
173
173
>>> proxy_img = nib.load(example_file)
174
- >>> data = proxy_img.get_data (caching = ' unchanged' )
174
+ >>> data = proxy_img.get_fdata (caching = ' unchanged' )
175
175
>>> proxy_img.in_memory
176
176
False
177
177
178
178
``caching='unchanged' `` will leave the cache full if it is already full.
179
179
180
- >>> data = proxy_img.get_data (caching = ' fill' )
180
+ >>> data = proxy_img.get_fdata (caching = ' fill' )
181
181
>>> proxy_img.in_memory
182
182
True
183
- >>> data = proxy_img.get_data (caching = ' unchanged' )
183
+ >>> data = proxy_img.get_fdata (caching = ' unchanged' )
184
184
>>> proxy_img.in_memory
185
185
True
186
186
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.
189
189
190
190
**********************
191
191
Saving time and memory
@@ -202,7 +202,7 @@ For example, let us say you only wanted the second volume from the example
202
202
dataset. You could do this:
203
203
204
204
>>> proxy_img = nib.load(example_file)
205
- >>> data = proxy_img.get_data ()
205
+ >>> data = proxy_img.get_fdata ()
206
206
>>> data.shape
207
207
(128, 96, 24, 2)
208
208
>>> vol1 = data[... , 1 ]
0 commit comments