JiaweiZhuang / xESMF

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

Add option to allow degenerated grid cells #61

Closed JiaweiZhuang closed 4 years ago

JiaweiZhuang commented 5 years ago

Addresses #60

By using xe.Regridder(grid_in, grid_out, 'conservative', ignore_degenerate=True), ESMF won't throw an error when seeing degenerated cells like triangles. But it might give nan for such cells. Should probably still throw an error by default, as this helps detecting bad/illegal grid coordinates. Ref: https://github.com/JiaweiZhuang/xESMF/issues/22#issuecomment-403165146.

@bradyrx could you see whether this works properly for your problem?

TODO:

Welcome to contribute test cases.

codecov-io commented 5 years ago

Codecov Report

Merging #61 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #61      +/-   ##
==========================================
+ Coverage   95.75%   95.76%   +0.01%     
==========================================
  Files           6        6              
  Lines         259      260       +1     
==========================================
+ Hits          248      249       +1     
  Misses         11       11
Impacted Files Coverage Δ
xesmf/backend.py 96% <ø> (ø) :arrow_up:
xesmf/frontend.py 93.98% <100%> (+0.04%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b811764...bf6075b. Read the comment docs.

JiaweiZhuang commented 5 years ago

Weirdly, setting ignore_degenerate=False also seems to suppress the error. Only ignore_degenerate=None behaves as default / throws error. Not 100% sure what's happening under ESMPy...

I can add something like

if not ignore_degenerate:
    ignore_degenerate = None

so that both False and None will behave as default. Not sure worth fixing this in xesmf level. Maybe @bekozi can comment more.

bradyrx commented 5 years ago

Thanks @JiaweiZhuang for the quick turnaround on this. I will give this a try over the weekend.

bradyrx commented 4 years ago

Hi @JiaweiZhuang, this method works. Here is an updated gist: https://nbviewer.jupyter.org/gist/bradyrx/421627385666eefdb0a20567c2da9976. Note that this broke prior to using this keyword.