# Irregular grid, 3-dim interpolation \[depth,lat,lon\] using python/dask?

**URL:** <https://nemo-ocean.discourse.group/t/irregular-grid-3-dim-interpolation-depth-lat-lon-using-python-dask/745>\
**Category:** v4.0.x\
**Created:** [28 August 2024 10:47 UTC](https://nemo-ocean.discourse.group/t/irregular-grid-3-dim-interpolation-depth-lat-lon-using-python-dask/745 "2024-08-28T10:47:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnebca](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@arnebca](https://nemo-ocean.discourse.group/u/arnebca)\
**Post date:** [28 August 2024 10:47 UTC](https://nemo-ocean.discourse.group/t/irregular-grid-3-dim-interpolation-depth-lat-lon-using-python-dask/745/1 "2024-08-28T10:47:29Z")

</div>

Dear community,

I am looking for suggestions on irregular grid, 3-dim interpolation [depth,lat,lon] using python/dask. My data is stored in a zarr store. Specifically, I need to interpolate u and v on gridT. I need to do so for each time step. Since I have hourly output (8760 time steps), I am interested in the most efficient procedure. Total domain size is [125,853,788].

The reason for the 3-dim interpolation lies in the fact that the water column depths may strongly vary among the different grids (gridU,gridV,gridT) for a given grid point, particularly in regions with strong bathymetric slopes. Also note that my model-configuration features a partial-step z-coordinate, where each e3\* metric may vary from its horizontal neighbors.

Any advice on this? I also appreciate recommendations for interpolation not using python.

Thanks!

---

<div class="post-metadata">

**Author:** ![dbruciaf](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dbruciaf](https://nemo-ocean.discourse.group/u/dbruciaf)\
**Post date:** [28 August 2024 12:57 UTC](https://nemo-ocean.discourse.group/t/irregular-grid-3-dim-interpolation-depth-lat-lon-using-python-dask/745/2 "2024-08-28T12:57:18Z")

</div>

Hi, I use xarray - below some code I wrote to regrid u,v components from U and V grids, resepctively, to T-grid for a model using generalised vertical coordinates (i.e., e3(i,j,k,t)).

```auto
Tgrd = 'path_to_your_T_grid_file'
Ugrd = 'path_to_your_U_grid_file'
Vgrd = 'path_to_your_V_grid_file'

ds_T = xr.open_dataset(Tgrd, chunks={}, drop_variables=("deptht"))
ds_U = xr.open_dataset(Ugrd, chunks={}, drop_variables=("depthu"))
ds_V = xr.open_dataset(Vgrd, chunks={}, drop_variables=("depthv"))
ds_T = ds_T.rename_dims({'deptht':'z'})
ds_U = ds_U.rename_dims({'depthu':'z'})
ds_V = ds_V.rename_dims({'depthv':'z'})

# Computing cell's volume
vol_t = ds_T.area * ds_T.thkcello
vol_u = ds_U.area * ds_U.thkcello
vol_v = ds_V.area * ds_V.thkcello

# Interpolating (u,v) from U and V grids on T grids
uT = (ds_U.uo * vol_u).rolling(x=2).mean().fillna(0.) / vol_t
vT = (ds_V.vo * vol_v).rolling(y=2).mean().fillna(0.) / vol_t

```

This code should be consistent with NEMO - see subroutine `trd_ken` in [trdken.F90](https://forge.nemo-ocean.eu/nemo/nemo/-/blob/main/src/OCE/TRD/trdken.F90?ref_type=heads) module.

I hope this helps a bit.

Cheers,

Diego
