-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement xESMF based regridding operation #127
Conversation
17b68ec
to
5d8328d
Compare
@jbednar Whenever you have a minute it would be good if you could review this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Minor suggestions only.
geoviews/operation/regrid.py
Outdated
grids using the xESMF library, supporting all the ESMF regridding | ||
algorithms including bilinear, conservative and nearest neighbour | ||
regridding. In addition to these different interpolation options | ||
it supports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...?
geoviews/operation/regrid.py
Outdated
if issubclass(self.p.target.interface, XArrayInterface): | ||
ds_out = self.p.target.data | ||
ds_out.rename({tx.name: 'lon', ty.name: 'lat'}, | ||
inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look very far into it, but is renaming in place safe (here and below)? Seems like that would leave people with altered data.
"source": [ | ||
"The xESMF library is specifically designed to provide an easy way to correctly resample grids defined in geographic coordinate systems and differs significantly from the simpler approach used by datashader, which applies simple upsampling and downsampling. xESMF is a wrapper around the [ESMF regridding algorithms](https://www.earthsystemcog.org/projects/esmf/regridding), which compute an interpolation weight matrix which is applied to remap the values of the source grid onto the destination grid. \n", | ||
"\n", | ||
"In GeoViews these algorithms are made available via the simple ``weighted_regrid`` operation, which supports the different interpolation modes including: 'bilinear', 'nearest_s2d', 'nearest_d2s' and 'conservative'. Since generating the sparse weight matrix takes much longer than applying it the operation will cache the weight matrix on disk for later use, this optimization can be disabled via the ``reuse_weights`` parameter or customized by defining a custom ``file_pattern``." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "simple"? I'd take that out, unless you are comparing it against some more complicated option we also provide (in which case that should be described here). Also, as usual, "use, this" needs to be "use; this" or "use. This".
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If we want to explore a very large grid it therefore often makes sense to resample the data onto a rectilinear grid, which can be rendered much more efficiently. Once again we have the option of using the datashader based approach or the more correct xESMF based approach." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say "more accurate" rather than "more correct"; there are varying levels of accuracy but correctness is Boolean. Neither approach is unequivocally "correct"; one can always use more and more complex models (given that the earth isn't actually precisely spherical, for instance).
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To regrid a ``QuadMesh`` using GeoViews we can import the ``rasterize`` operation. In the background the operation will convert the ``QuadMesh`` into a ``TriMesh``, which datashader understands. To optimize this conversion so it occurs only when aggregating the ``QuadMesh`` for the first time we can activate the ``precompute`` option. Additionally we have to define an aggregator, in this case to compute the mean ``Tair`` value in a pixel:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tair
(air temperature)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel stupid now, I've been puzzling over this a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my guess. :-)
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Another commonly used mesh/grid type are trimeshes, here we will load a 3dm file and demonstrate how to visualize it using HoloViews:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another comma splice; needs to be "trimeshes; here".
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"This is a reasonably large mesh with >1 million triangles and cannot easily be displayed directly with matplotlib or especially bokeh. Therefore we will once again regrid this dataset onto a rectilinear grid. Additionally, to speed up plotting of meshes, we can do two things, first of all since all data displayed with bokeh is first projected to Web Mercator coordinates we can project the mesh immediately, secondly we can use the ``precompute`` during rasterization, which will cache an optimized mesh datastructure:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"two things: first, since ....; second, we can"
7f1bfec
to
73d4931
Compare
73d4931
to
06a3647
Compare
Tests passing. Merging. |
Adds a xESMF based regridding operation along with a user guide on how to use it. Depends on holoviz/holoviews#2265. The draft user guide can be seen here: https://anaconda.org/philippjfr/resampling_grids/notebook