NCAR / pop-tools

Tools to support analysis of POP2-CESM model solutions
https://pop-tools.readthedocs.io
Apache License 2.0
22 stars 29 forks source link

ugrid_to_tgrid.... #46

Open matt-long opened 4 years ago

matt-long commented 4 years ago

We should have a UGRID to TGRID function...and the reverse.

dcherian commented 4 years ago

with xgcm master and metrics specified this becomes

# TGRID to UGRID
Xu = grid.interp(Xt, axis=“XY”, metric_weighted=”XY”)

#UGRID to TGRID
Xt = grid.interp(Xu, axis=“XY”)
matt-long commented 4 years ago

Do you think it's worth having a method in grid? It could look something like this.

def ugrid_to_tgrid(arr_ugrid):
    """
    Interpolates values at U points on a B grid to T points.
    """
    with xr.set_options(keep_attrs=True):
        return 0.25 * (
            arr_ugrid +  # j, i
            arr_ugrid.roll(nlat=1, roll_coords=False) + # j-1, i
            arr_ugrid.roll(nlon=1, roll_coords=False) + # j, i-1
            arr_ugrid.roll(nlat=1, nlon=1, roll_coords=False) #j-1, i-1
        )
dcherian commented 4 years ago

Maybe as a convenience method so you can do it without xgcm?

it is really convenient once xgcm makes a release...