JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

vertical interpolation onto a tracer coordinate #89

Open miniufo opened 4 years ago

miniufo commented 4 years ago

I love the high-level API of this package and it's efficient. There are lots of geoscience applications that need vertical-coordinate transformation, like converting the pressure-level data to isentropic levels in atmospheric context and converting z-level data to denstiy levels in oceanic context.

Just wonder if I can do this using the current xESMF functionality, possibly keeping the conservative property. I've searched around for such a tool and hope this wonderful one could help me out so that I won't need many similar tools.

zxdawn commented 4 years ago

@miniufo I met a similar problem with xarray. You can try xr.apply_ufunc(). But, that's not conservative. Maybe, @JiaweiZhuang has a better solution.

miniufo commented 4 years ago

Hi @zxdawn, thanks, I know there are many 1D interpolation methods, but I need one to do the conservative interpolation. I need to ensure that the total tracer amount should be exactly the same before and after the interp.

zxdawn commented 4 years ago

@miniufo Got it! It's tricky to interpolate data to vertical levels conservatively, maybe we need some assumptions, such as the constant concentration between each level.

Em ... Have no idea how to code. Waiting for the answer from @JiaweiZhuang ;)

zxdawn commented 4 years ago

As mentioned in https://github.com/JiaweiZhuang/xESMF/issues/24:

ESMPy does support 3D grid, but this is generally an overkill.

miniufo commented 4 years ago

ESMPy does support 3D grid, but this is generally an overkill.

Hi @zxdawn, for the case of z-to-z interpolation (different z-levels), I guess xESMF could handle well, even under the conservative constraint. As for the z-to-density case, not so sure. One may need to check the monotonicity of density and thus get a one-to-one relation z(rho) between z and density.

maybe we need some assumptions, such as the constant concentration between each level.

I think this is the very assumption of discretization, that variables are assumed to be constant within a single grid cell.

bradyrx commented 3 years ago

I haven't tried it out, but I believe something like xlayers might help https://github.com/cspencerjones/xlayers.