pangeo-data / xESMF

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

Masking out-of-source-domain data points for nearest neighbour remapping #317

Open sol1105 opened 10 months ago

sol1105 commented 10 months ago

When remapping to a larger domain with the method nearest_s2d, data points outside the original domain will - by the nature of this method - be extrapolated, i. e. have values from the edge of the original domain.

This PR introduces a Regridder option to apply a "domain mask" that is generated by creating remapping weights with the bilinear method as an extra step (while having unmapped_to_nan activated) before creating the nearest neighbour remapping weights. This way, all data points that would count as unmapped for the bilinear method will also be masked for nearest_s2d.

This is useful when remapping data on regional grids such as CORDEX data. A demonstration can be seen here at the bottom of Masking.ipynb: https://github.com/sol1105/xESMF/blob/domain_mask/doc/notebooks/Masking.ipynb

I added it as an option to the Regridder but the linting suggests that the __init__ method gets too complex with this addition. I could also add this masking option as a separate function or Regridder method. But before putting more work into this I would welcome your general feedback (and if you welcome the general idea of this masking option, also specific feedback on how to preferably deal with the complexity issue).

review-notebook-app[bot] commented 10 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

sol1105 commented 9 months ago

@huard Thanks for your reply. I integrated it in the Regridder since creating the mask requires creating a Regridder object as well and so all the checks related to the dataset were required only once. However, since the Regridder initialisation then fails the linting checks with regards to the added complexity, I will have to move it to a separate method or function. I will try to find a general approach so it will be possible to later add further methods to generate masks.

huard commented 9 months ago

Don't worry too much about the linter.