Skip to content
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

Merged
merged 12 commits into from
Feb 2, 2018
Merged

Conversation

philippjfr
Copy link
Member

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

@philippjfr
Copy link
Member Author

@jbednar Whenever you have a minute it would be good if you could review this.

Copy link
Member

@jbednar jbednar left a 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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...?

if issubclass(self.p.target.interface, XArrayInterface):
ds_out = self.p.target.data
ds_out.rename({tx.name: 'lon', ty.name: 'lat'},
inplace=True)
Copy link
Member

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``."
Copy link
Member

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."
Copy link
Member

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:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tair (air temperature)?

Copy link
Member Author

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.

Copy link
Member

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:"
Copy link
Member

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:"
Copy link
Member

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"

@philippjfr
Copy link
Member Author

Tests passing. Merging.

@philippjfr philippjfr merged commit 4f8dca8 into master Feb 2, 2018
@philippjfr philippjfr deleted the regrid_operations branch March 22, 2020 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants