I've had another thought about this now (and chat with @esc24) , and I'm changing my mind on what this is actually about.
It is true that cubes are not 'writeable' : i.e.
.. they don't have a __setitem__ method
.. so you can't write 'cube[i,j] = newdata'
But then, you might ask, what would you set part of a cube
to ?
Logically, slicing or indexing a cube yields another cube, which is 'part of' the parent, containing a section of its data
and its coordinates (plus all other metadata).
As part of a cube is a cube, the only sensible thing you could write into this would be another cube.
However, it makes no general sense to overwrite 'parts' of coordinates, as there are tight validity constraints on the values.
So basically, it would make no sense to assign a cube into part of another cube, unless it had the same (part-)coordinates, which basically means it could not change the coordinate values.
( Similarly, writing one cube into 'part' of another would only makes sense if the units are the same )
So it seems that the only thing about a cube that can sensibly be 'partly changed' is the data.
So .. you can simply
assign to the data instead.
There is really nothing wrong with this. The data is a mutable part of the cube which you have full access to.
The only catch is that you must not change it's shape. Unfortunately we have not managed to come up with a clean way of preventing that, so this remains a unenforced "convention".
I think this also shows why when you do index or slice cubes, the result has to be a new, independent cube with its own, separate coordinates : It can't be a 'view' on the old one, because then any changes to its metadata could make nonsense of the parent.
I'm still wondering, though, whether we could preserve a view on the original cube's
data, allowing you to manipulate data in an iteration over slices.
At present, as I wrote in an earlier, offline conversation :
When subindexing, extraction or slicing cubes, all data is actually copied, so that the resulting subcubes are always entirely separate from the original.
This is much simpler, and quite intentional.
It is true that in in principle it would be possible to yield a 'sub view' of the data, at least for simple slicing. That is what NumPy does (at least for simple indexing), so you might expect that
But we haven't implemented that because it was felt that copying is more straightforward, and having different cubes sharing data was potentially just too dangerous.
It does mean that some things that work on arrays will not work with cubes. For example, code like "subarea = cube[i:j, 2]; subarea[zero_indices] = 0".