a better way to print cube dimensions?

24 views
Skip to first unread message

Bernd Becker

unread,
Aug 8, 2018, 10:25:03 AM8/8/18
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
is there a better way to print a cube dimension than:

print cube.coord('realization').points.shape[0]

?



Klaus Zimmermann

unread,
Aug 8, 2018, 10:30:14 AM8/8/18
to scitoo...@googlegroups.com
Hi Bernd,

well, both the cube itself and the coordinate have shape attributes as
well, so if you are reasonably confident about the order of your axis,
you can just do

print(cube.shape)

otherwise

print(cube.coord('realization').shape)

would be equivalent to what you wrote.
And of course you can always just do

print(cube)

to get a quick overview.

Anyway don't forget the parentheses around the stuff you are printing.
Right now you get away without it, but soon[1] python 2 will be a thing
of the past and python 3 requires them.

Cheers
Klaus

[1] https://pythonclock.org/
> --
> You received this message because you are subscribed to the Google
> Groups "SciTools (iris, cartopy, cf_units, etc.) -
> https://github.com/scitools" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scitools-iri...@googlegroups.com
> <mailto:scitools-iri...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages