re-shaping a cube list

40 views
Skip to first unread message

Bernd Becker

unread,
May 1, 2013, 5:18:15 AM5/1/13
to scitoo...@googlegroups.com
I have a list of global fields in a pp-file with duff headers.
This pp-file is a simple container for some HIT counts as you would find in a contingency table.

I can read the data OK with:
fname='some file name holding 400 global fields in pp format'
hit_cube=iris.load_raw(fname)

len(hit_cube)  returns 400

I would like to re-shape the hit_cube(400) to new_hit_cube(2,10,4,5)

2 variables
10 "layers"
4 lead times
5 "classes"


I tried :
 c = np.arange(2*10*4*5)
 nc=c.reshape(2,10,4,5)

nhit_cube=hit_cube.reshape(2,10,4,5))

and

new_hit_cube=hit_cube[nc]

to no avail.

How would you do it?

many thanks,
Bernd.

Rutger Dankers

unread,
May 1, 2013, 7:00:28 AM5/1/13
to scitoo...@googlegroups.com
Hi Bernd

Instead of "reshaping" your cube list, have you thought about adding coordinates for layers, lead times and classes? I.e. you would end up with two cubes, one for each variable, and you could subset each by selecting any combination of layer, lead time and class you want.

HTH
Rutger

bblay

unread,
May 1, 2013, 11:42:54 AM5/1/13
to scitoo...@googlegroups.com
Yes, that seems the best advice, Bernd.

You'd write a callback that added z, t and 'class' coordinates.
The following code would give you data that was already the correct shape:

cubes = iris.load(filename, my_callback)
cubes
[0].shape
 
(10, 4, 5)
cubes[1].shape
  (10, 4, 5)

Note: the cubes would already be the correct shape because they would have gone through the merge process.
For more on callbacks, please see here.
Reply all
Reply to author
Forward
0 new messages