JiaweiZhuang / xESMF

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

Option to normalize conservative regridding result by overlapping area #17

Open JiaweiZhuang opened 6 years ago

JiaweiZhuang commented 6 years ago

There are actually two types of conservative regridding, controlled by the NormType option in ESMPy.

Say that's the input data covering a limited region: input

The option currently used by xESMF's conservative regridding will "dilute" the boundary cells. That's because the cell on the input grid's boundary are "averaged" with non-existing "cells" outside the boundary (which are assumed to have zero values). default

The other option (not in xESMF yet) will normalize boundary cells so they are not "diluted": normed

The two options are only different at boundaries: diff

(Full code available in this gist, which was about an already-fixed bug)

I chose the first option mainly for multi-tile grids (regrid one by one and add up). The second option perhaps makes more sense for single-tile grids, but will double count the boundary cells in multi-tile grids. If the second option is useful I can add a new 'conservative_normed' method.

zxdawn commented 4 years ago

@JiaweiZhuang Yes. This is useful. Here's the example of regridding WRF pressure: image

zxdawn commented 4 years ago

If I use conservative_normed method and set ignore_degenerate=True, I would get this error:

  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/xesmf/frontend.py", line 236, in __init__
    self._write_weight_file()
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/xesmf/frontend.py", line 280, in _write_weight_file
    ignore_degenerate=self.ignore_degenerate)
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/xesmf/backend.py", line 290, in esmf_regrid_build
    ignore_degenerate=ignore_degenerate)
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/ESMF/util/decorators.py", line 64, in new_func
    return func(*args, **kwargs)
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/ESMF/api/regrid.py", line 150, in __init__
    dstFracField=dst_frac_field)
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/ESMF/util/decorators.py", line 52, in new_func
    return func(*args, **kwargs)
  File "/home/xin/miniconda3/envs/satpy/lib/python3.7/site-packages/ESMF/interface/cbindings.py", line 2148, in ESMP_FieldRegridStoreFile
    '.    '+constants._errmsg)
ValueError: ESMC_FieldRegridStoreFile() failed with rc = 506.    Please check the log files (named "*ESMF_LogFile").

@JiaweiZhuang Any suggestion on this situation? Thanks!