CDAT / cdms

8 stars 10 forks source link

Consider creating MPAS convention for generic grids #27

Open chaosphere2112 opened 7 years ago

chaosphere2112 commented 7 years ago

MPAS files have a Conventions attribute with the value 'MPAS'; we could use this to generate a new Convention object in CDMS that uses the appropriate variables/axes in the file to construct the correct grid for the variables.

This is the algorithm I used to construct the generic grids for the data; it creates meshfill-able data. I'll post a link to a file to use as a test, if it's decided that we should support this.

import cdms2
import numpy

f = cdms2.open("average.nc")
cell_x = f("xCell")
cell_y = f("yCell")

vert_ids = f("indexToVertexID")
cell_verts = f("verticesOnCell")
vert_x = f("xVertex")
vert_y = f("yVertex")

# This can be improved dramatically by someone better at numpy than me
def extract_cell_bounds(cells, vertex_coord):
    cell_bounds = numpy.zeros(cells.shape)
    for i in range(len(cells)):
        cell_bounds[i] = numpy.take(vertex_coord, cells[i] - 1)
    return cell_bounds

xbounds = extract_cell_bounds(cell_verts, vert_x)
ybounds = extract_cell_bounds(cell_verts, vert_y)

virt_axis = f.getAxis("nCells")
yaxis = cdms2.auxcoord.TransientAuxAxis1D(cell_y, axes=(virt_axis,), bounds=ybounds, id="latitude")
xaxis = cdms2.auxcoord.TransientAuxAxis1D(cell_x, axes=(virt_axis,), bounds=xbounds, id="longitude")
generic_grid = cdms2.gengrid.TransientGenericGrid(yaxis, xaxis, id="mpas_grid")
chaosphere2112 commented 7 years ago

http://uvcdat.llnl.gov/cdat/sample_data/mpas/average.nc

durack1 commented 7 years ago

@chaosphere2112 the unstructured grids will be more and more the default in CMIP6+, so while it will be impossible to anticipate all the new grids that are coming down the pipe paying attention to what ESMF/ESMpy is doing and ensuring that all their latest functionality works with cdms would be what I would advocate for

chaosphere2112 commented 7 years ago

@durack1 Yeah, that's definitely the priority. This is just filed away so I don't have to keep track of the source code on my laptop indefinitely; it would be a "nice to have" for ACME users, since they're using MPAS for the ocean model there.