create 1D lat and lon coordinates from 2D lat and lon auxillary coordinates

147 views
Skip to first unread message

MichelleMc

unread,
Jul 30, 2020, 12:39:06 PM7/30/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
I have a sea ice file on an ocean grid which when it loads does not have latitude and longitude as dimension coords. Its does however have them as auxiliary coordinates. I have seen this done for time coordinate through promote_aux_coord_to_dim_coord however these wont promote to dim_coords as they are 2D so I was wondering if anyone had a work around to create lat/lon dimension coords from the auxiliary or simply create lat/lon Dimension coords from this. 



sea_ice_area_fraction / (%)         (time: 780; -- : 294; -- : 362)

     Dimension coordinates:

          time                           x         -         -

     Auxiliary coordinates:

          year                           x         -         -

          latitude                       -         x         x

          longitude                      -         x         x

Denis Sergeev

unread,
Jul 30, 2020, 1:22:40 PM7/30/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi Michelle,

Presumably the lat/lon coordinates are 2d here because each of them vary both in x- and y-direction. The only thing to do here, I think, is to create a pair of dummy 1D coordinates and make them dimensional. For example:

ny = sic_cube.shape[-2]
nx = sic_cube.shape[-1]

xc = iris.coords.DimCoord(np.arange(nx), units="1", standard_name="projection_x_coordinate")
yc = iris.coords.DimCoord(np.arange(ny), units="1", standard_name="projection_y_coordinate")

sic_cube.add_dim_coord(yc, 1)
sic_cube.add_dim_coord(xc, 2)

Though of course these coordinates are not very useful - they are essentially just array indices.

Another option is to regrid your data to rectangular lat/lon grid, which will make actual latitude and longitude 1D dimensional coordinates.

HTH

MichelleMc

unread,
Jul 30, 2020, 2:30:17 PM7/30/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi Denis, 

Thanks for this, I was doing something similar but with auxiliary and then trying to promote to a dim_coord as I had done before, forgot to just simply try and make a dim coord. 

This does as you say in that it creates and 1D Dim coord which is great, but your suggestion to regrid suits better because when I try to regrid with the new dim_coord it shoots an error about finding multiple coordinates, however I can regrid it in its current form to a regular lat/lon grid and thus solving the problem.

Thanks again for your help
Reply all
Reply to author
Forward
0 new messages