creating a cube with 2d lat/lon coords

837 views
Skip to first unread message

Andreas Hilboll

unread,
May 28, 2014, 12:36:18 PM5/28/14
to scitoo...@googlegroups.com
Hi iris gurus,

how can I create a cube with 2d lat/lon coordinates (i.e., I have 2 2d
arrays of shape x,y holding latitudes and longitudes, and they do not
define a regular grid)? A DimCoord only accepts 1d points, and when I
add latitude and longitude as 2d AuxCoord instances, then the cube
doesn't seem to "recognize" the coordinates (i.e., when I plot the cube
using cartopy, the lats/lons of the data are wrong and seem to
correspond to the indices of the data array).

Thanks for your insight!
Andreas.

Andrew Dawson

unread,
May 28, 2014, 1:38:37 PM5/28/14
to scitoo...@googlegroups.com, li...@hilboll.de
AuxCoords are the way to go for 2D coordinates. When you come to plotting note that the 2D plot functions take a 'coords' keyword which you can use to specify which coordinates on the cube are used to represent each dimension of the plot (in x-y order). You should be able to use this to plot your data with 2D coordinates properly I think. I can't test it right now but I think something like this should work:

iplt.contourf(cube, coords=['lon2d', 'lat2d'])

where 'lon2d' and 'lat2d' are the names of your 2d coordinates. Give it a go, and shout back if it doesn't work!

Andreas Hilboll

unread,
May 28, 2014, 2:36:08 PM5/28/14
to scitoo...@googlegroups.com
Thanks, Andrew! Works well with contourf. Any idea how I can make this
work with pcolormesh?

ValueError: The coordinate 'longitude' is multi-dimensional and cannot
be used in a cell-based plot.


On 28.05.2014 19:38, Andrew Dawson wrote:
> AuxCoords are the way to go for 2D coordinates. When you come to
> plotting note that the 2D plot functions take a 'coords' keyword which
> you can use to specify which coordinates on the cube are used to
> represent each dimension of the plot (in x-y order). You should be able
> to use this to plot your data with 2D coordinates properly I think. I
> can't test it right now but I think something like this should work:
>
> |
> iplt.contourf(cube,coords=['lon2d','lat2d'])
> |
>
> where 'lon2d' and 'lat2d' are the names of your 2d coordinates. Give it
> a go, and shout back if it doesn't work!
>
> On Wednesday, 28 May 2014 17:36:18 UTC+1, Andreas Hilboll wrote:
>
> Hi iris gurus,
>
> how can I create a cube with 2d lat/lon coordinates (i.e., I have 2 2d
> arrays of shape x,y holding latitudes and longitudes, and they do not
> define a regular grid)? A DimCoord only accepts 1d points, and when I
> add latitude and longitude as 2d AuxCoord instances, then the cube
> doesn't seem to "recognize" the coordinates (i.e., when I plot the cube
> using cartopy, the lats/lons of the data are wrong and seem to
> correspond to the indices of the data array).
>
> Thanks for your insight!
> Andreas.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Iris" 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.


--
-- Andreas.

Andrew Dawson

unread,
May 28, 2014, 3:41:46 PM5/28/14
to scitoo...@googlegroups.com, li...@hilboll.de
You can't really. pcolormesh needs bounds to be plotted correctly. We can't automatically calculate bounds for 2D coordinates, and I don't think we support this at the moment even if your 2D coordinates already have bounds, there are a lot of tricky cases to handle.

If your data is defined on a regular grid in some other projection supported by cartopy then you can try and create 1d DimCoords in that coordinate system (e.g. limited area Lambert Conformal grid).

LeonH

unread,
Jun 12, 2014, 9:33:49 AM6/12/14
to scitoo...@googlegroups.com, li...@hilboll.de
I was initially quite excited about the coords keyword mentioned above, as the NEMO ocean model uses 2d-coords. But when I used it all I got was a garbled mess. Has anyone managed to get this keyword to work with a NEMO field?

marqh

unread,
Jun 18, 2014, 10:05:44 AM6/18/14
to scitoo...@googlegroups.com, li...@hilboll.de
Hello Leon

pcolormesh can only handle 1d coordinates, it is inherent in the way it produces plots.  if you pass it 2d coords things get quite confused.

For NEMO data you have a few options, including:
 - pcolor is a generic polygon creation and plotting process in matplotlib, it creates a polygon for every data point.  For medium resolution ocean data sets on ORCA grids this can take a long time, for high res data sets things gets out of hand.
 - you can resample your data for plotting purposes, which is often delivers a plot with plenty of resolution for any reasonable sized graphic; it is fit for many purposes.
   - I have put an example of this in the gallery which will be part of the 1.7 documentation.  It is in the source now so you can have a look and see if this is sufficient for your needs:
   - https://github.com/SciTools/iris/blob/master/docs/iris/example_code/graphics/orca_projection.py


Phil Elson

unread,
Jul 12, 2014, 3:53:41 PM7/12/14
to marqh, scitoo...@googlegroups.com, andreas-h
Only a month too late, but I posted something to show the reproject some time ago: http://nbviewer.ipython.org/gist/pelson/6219116

HTH


--
You received this message because you are subscribed to the Google Groups "Iris" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iri...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages