JiaweiZhuang / xESMF

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

Gridding sparse data (fine to coarse) #33

Closed NicWayand closed 6 years ago

NicWayand commented 6 years ago

hi @JiaweiZhuang, I am trying to regrid sparse (~1 km) Ice Bridge data (airborne flight transects) to a coarser 25 km grid, using the new conservative_normed method from your master branch. But I am getting only NaNs out.

Even if there is only one non-NaN fine cell within a coarse cell, it should assign that only fine cell's value to the coarse cell, correct?

A runable example can be found here.

JiaweiZhuang commented 6 years ago

In your case, getting all NaNs is the expected, default behavior for most algorithms, as explained in https://github.com/JiaweiZhuang/xESMF/issues/22#issuecomment-399280598.

To get rid of NaNs, you need to apply masking like https://github.com/JiaweiZhuang/xESMF/issues/22#issuecomment-410810471. conservative vs conservative_normed only affects the magnitude of the regridding result, not the occurrence of NaNs.

JiaweiZhuang commented 6 years ago

There should be a ds_fine['mask'] that masks all cells out of your data trajectory (i.e. all NaNs in the input data).

NicWayand commented 6 years ago

Ah thanks! I had the ds_target['mask']but forgot the ds_fine['mask'].

Now getting non-nan values in the coarse grid as expected: image

However, now all other coarse cells were set to 0, when I would have expected them to be NaN. From past convos I understand this is the expected current behavior.

Using the add offset, mask > offset, subtract offset, workaround works for now but feels a little hacky. Thanks for all the work on #22!

image