Regridding using xESMF with 3D Mask

Hello everyone!

Hopefully this is the right place to ask this question:

I am currently trying to create initial conditions for a high-resolution, regional ocean model (based on ROMS) from the GLORYS12v1 reanalysis dataset. Since the model grids and vertical coordinate systems are different I am interpolating the three-dimensional (longitude, latitude, depth) GLORYS data horizontally onto the model grid using the xESMF module which generally works like a charm.

To account for the differences in the land/sea masks between my model and the reanalysis, I am using the extrapolation feature described here. This requires a mask variable which can only be 2D because of the underlying ESMF design.

However, the land/sea mask in GLORYS12v1 changes with depth, so that I have to apply the regridding for each vertical level separately. Is there any preferred way to do that?

Suppose that ds a xarray.Dataset() with dimensions depth, lon, and lat containing multiple variables including a 3D mask. Off the top of my hat, I can think of two options (both untested):

  1. Iterate over depth dimension, build the xesmf.Regridder() for each level and manually create an output dataset ds_int with the interpolated data. I’m afraid that this could be quite slow.
  2. Write a dummy function that takes 2D fields as input arguments and applies the regridding for an individual model level. I would then apply this function to all depth levels using the xarray.apply_ufunc() method.

Do you have any other suggestions, tips, or tricks how to best approach this (in the best case computationally efficiently)?

Many thanks in advance!

1 Like

Thanks for your question @christophrenkl!

Since no one has replied here, I’m guessing your issue is a little too technical for the forum. You’re probably best off opening an xesmf issue:

Thank you for your suggestion, @rabernat! I just opened an issue on GitHub.