rcaneill / xnemogcm

Interface to open NEMO global circulation model output dataset with xarray and create a xgcm grid.
https://xnemogcm.readthedocs.io/
MIT License
21 stars 10 forks source link

Opening surface data #7

Closed rcaneill closed 3 years ago

rcaneill commented 3 years ago

Due to the fact that surface data do not have a depth dimension, xnemogcm raises an error at line: https://github.com/rcaneill/xnemogcm/blob/d792269bd86f51fa7631b5d544491b3fb156e232/xnemogcm/nemo.py#L41

A simple fix is replacing lines 41 to 47 by:

    try:
        z_nme = [i for i in ds.dims.keys() if "depth" in i][0]
    except IndexError:
        # This means that there is no depth dependence of the data (surface data)
        z_nme = None
    x_nme = "x"  # could be an argument / metadata
    y_nme = "y"
    ds = ds.rename({x_nme: point.x, y_nme: point.y})
    if z_nme:
        ds = ds.rename({z_nme: point.z})
    # setting z_c/z_f/x_c/etc to be the same as in domcfg
    points = [point.x, point.y]
    if z_nme:
        points += [point.z]
    for xyz in points:
        ds.coords[xyz] = domcfg[xyz]

However a better solution could be found to handle the same problem along x and y.

rcaneill commented 3 years ago

I will implement this as soon as I will have produced a test file for the surface data.

rcaneill commented 3 years ago

Closed by #8