cube.copy()- cube.data.mask arrays are not always deep copies

265 views
Skip to first unread message

Daley Calvert

unread,
Sep 15, 2014, 11:59:43 AM9/15/14
to scitoo...@googlegroups.com
Hi all,

I've observed an odd problem when using Iris 1.7.

When I repeat a cube.copy() operation, the mask of the resultant cube will use the same memory address as that of the target cube's mask. The cube memory address however will be different:

>>> test
<iris 'Cube' of ocean_mixed_layer_thickness_defined_by_sigma_theta / (m) (time: 1; -- : 1021; -- : 1442)>
>>> copy=test.copy() ; copy2=copy.copy() ; copy3=copy.copy()        
>>> id(test) ; id(copy) ; id(copy2) ; id(copy3)
43104528
43970064
44415120
44342736
>>> id(test.data.mask) ; id(copy.data.mask) ; id(copy2.data.mask) ; id(copy3.data.mask)
42458352
43322064
15349264
43013792
>>> copy=test.copy() ; copy2=copy.copy() ; copy3=copy.copy()
>>> id(test) ; id(copy) ; id(copy2) ; id(copy3)
43104528
140249701731344
43970064
44415120
>>> id(test.data.mask) ; id(copy.data.mask) ; id(copy2.data.mask) ; id(copy3.data.mask)
42458352
42458352
42458352
42458352

Any ideas?


Daley

Andrew Dawson

unread,
Sep 23, 2014, 10:38:39 AM9/23/14
to scitoo...@googlegroups.com
When the data are copied iris uses the copy.copy() function (from the standard library's copy module). I think it should be using the copy() method of the data object (numpy array or masked array).

Andrew Dawson

unread,
Sep 23, 2014, 11:08:04 AM9/23/14
to scitoo...@googlegroups.com
Or deepcopy, as the object might be a biggus array rather than a numpy array.

Andrew Dawson

unread,
Sep 25, 2014, 8:20:35 AM9/25/14
to scitoo...@googlegroups.com
This should be fixed on the v1.7.x branch, which means the fix will be in the next release.

Andrew Dawson

unread,
Sep 25, 2014, 8:20:54 AM9/25/14
to scitoo...@googlegroups.com

Daley Calvert

unread,
Sep 30, 2014, 11:25:43 AM9/30/14
to scitoo...@googlegroups.com
Great, thanks Andrew!
Reply all
Reply to author
Forward
0 new messages