Skip to content

Commit

Permalink
deploy: 14f5059
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc2 committed Apr 5, 2024
1 parent db51d2c commit b71e3ae
Show file tree
Hide file tree
Showing 11 changed files with 7,895 additions and 2,607 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

245 changes: 147 additions & 98 deletions _preview/11/_sources/notebooks/03-uxarray-vis/03-polygons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
}
},
"source": [
"In most simulations, such as Global Climate Models, Unstructured Grids are composed of nodes that are connected with edges to form faces that discretize the surface of a sphere (i.e. Earth). For visualization, these faces can be geometrically represented as Polygons and shaded by a corresponding face-centered data variable.\n",
"Unstructured Grids are often used in the Dynamical Cores of climate models because of their ability to represent complex geometries effectively. Because of the complexity of the geometry, it is often difficult to produce quick and fast visualizations.\n",
"\n",
"This notebook showcases how UXarray can visualize unstructured grids as polygons.\n",
"As was discussed in the DATA MAPPING section, data variables are typically mapped to the geometric elements that make up the entire unstructured grid (nodes, edges, and faces).\n",
"\n",
"<div class=\"admonition alert alert-warning\">\n",
" <p class=\"admonition-title\" style=\"font-weight:bold\">Important!</p>\n",
" This cookbook builds the SpatialPandas library from source (i.e. from the latest commit to Github). If running this notebook locally, please\n",
" install SpatialPandas using the following command:\n",
" <br>\n",
" ``pip install git+https://github.com/holoviz/spatialpandas.git``\n",
" <br>\n",
" No action is needed if running this cookbook through Binder.\n",
"</div>"
"When data is mapped to the faces, each face is shaded with the value of the data variable. We can treat these faces as Polygons on a plane for visualization.\n",
"\n",
"\n",
"This notebook showcases how UXarray can visualization data as polygons."
]
},
{
Expand Down Expand Up @@ -116,6 +111,129 @@
"uxds_geoflow = ux.open_dataset(grid_filename_geoflow, data_filename_geoflow)"
]
},
{
"cell_type": "markdown",
"source": [
"## Vector Polygon Plots"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.polygons(width=600, height=300)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.polygons(width=600, height=300, xlim=(-20, 0), ylim=(-5, 5))"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"## Rasterized Polygon Plots"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.polygons(backend='matplotlib')"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.rasterize(method='polygon', width=600, height=300)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.rasterize(method='polygon', width=600, height=300, xlim=(-20, 0), ylim=(-5, 5))"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"(uxds_mpas[\"bottomDepth\"].plot.rasterize(aspect=2, backend='matplotlib', xlim=(-20, 0), ylim=(-5, 5), pixel_ratio=2.0) +\n",
"uxds_mpas[\"bottomDepth\"].plot.rasterize(aspect=2, backend='matplotlib', xlim=(-20, 0), ylim=(-5, 5), pixel_ratio=4.0)).opts(fig_size=150)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"## Polygons Around Antimeridian\n",
"\n",
"When attempting to visualize unstructured meshes that reside on a sphere, it's necessary to consider the behavior of geometric elements near the Antimeridian. Elements that exist on or cross the antimeridian need to be corrected to properly visualize them. UXarray uses the antimeridian package to split faces along the antimeridian. More details can be found in their [documentation](https://antimeridian.readthedocs.io/en/stable/).\n",
"\n",
"\n",
"![antimeridian example](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Earth_map_with_180th_meridian.jpg/640px-Earth_map_with_180th_meridian.jpg)\n"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"(uxds_mpas[\"bottomDepth\"].plot.polygons(aspect=2, backend='matplotlib', xlim=(-185, -175), ylim=(-5, 5), exclude_antimeridian=False) +\n",
"uxds_mpas[\"bottomDepth\"].plot.polygons(aspect=2, backend='matplotlib', xlim=(175, 185), ylim=(-5, 5), exclude_antimeridian=False)).opts(fig_size=150)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"(uxds_mpas[\"bottomDepth\"].plot.polygons(aspect=2, backend='matplotlib', xlim=(-185, -175), ylim=(-5, 5), exclude_antimeridian=True) +\n",
"uxds_mpas[\"bottomDepth\"].plot.polygons(aspect=2, backend='matplotlib', xlim=(175, 185), ylim=(-5, 5), exclude_antimeridian=True)).opts(fig_size=150)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -126,7 +244,9 @@
},
"source": [
"## Conversion Methods\n",
"UXarray represents Unstructured Grids through a set of coordinate and connectivity variables (i.e. `node_lon`, `node_lat`, `face_node_connectivity`, etc.). These variables need to be manipulated to obtain geometries and data structures that are compatible with visualuzation libraries (i.e. HoloViews, Datashader, Matplotlib, etc.)"
"\n",
"\n",
"UXarray represents Unstructured Grids through a set of coordinate and connectivity variables (i.e. `node_lon`, `node_lat`, `face_node_connectivity`, etc.). These variables can be manipulated to generate geometries (in our case Polygons) that can be fed into visualization libraries (i.e. HoloViews, Datashader, Matplotlib, etc.)\n"
]
},
{
Expand All @@ -138,7 +258,10 @@
}
},
"source": [
"### Representation as a `GeoDataFrame`\n",
"### Representation as a `spatialpandas.GeoDataFrame`\n",
"\n",
"The primary conversion\n",
"\n",
"\n",
"Each face is converted into a Polygon and stored within a SpatialPandas `GeoDataFrame`, which is the expected data structured by the HoloViz stack of packages for visualizing polygons.\n",
"\n"
Expand Down Expand Up @@ -215,61 +338,37 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"uxds_geoflow[\"v1\"].nodal_average()[0][0].to_geodataframe()"
]
},
{
"cell_type": "markdown",
],
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"## Vector Polygon Plots\n",
"\n",
"UXarray provides the `plot.polygons()` method, which renders each polygon as a vector graphic using HoloViews.\n",
"\n"
]
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"uxds_mpas[\"bottomDepth\"].plot.polygons(width=900, height=400)"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"uxds_geoflow[\"v1\"].nodal_average()[0][0].plot.polygons(\n",
" cmap=\"coolwarm\", width=900, height=400\n",
")"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -341,23 +440,6 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"source": [
"## Handling Antimeridian Polygons\n",
"\n",
"When attempting to visualize unstructured meshes that reside on a sphere, it's necessary to consider the behavior of geometric elements near the Antimeridian. Elements that exist on or cross the antimeridian need to be corrected to properly visualize them. UXarray uses the antimeridian package to split faces along the antimeridian. More details can be found in their [documentation](https://antimeridian.readthedocs.io/en/stable/).\n",
"\n",
"\n",
"![antimeridian example](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Earth_map_with_180th_meridian.jpg/640px-Earth_map_with_180th_meridian.jpg)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -375,39 +457,6 @@
" visualization.\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"(\n",
" uxds_geoflow[\"v1\"]\n",
" .nodal_average()[0][0]\n",
" .plot.polygons(\n",
" exclude_antimeridian=False,\n",
" cmap=\"coolwarm\",\n",
" title=\"With Antimeridian Faces\",\n",
" width=900,\n",
" height=400,\n",
" )\n",
" + uxds_geoflow[\"v1\"]\n",
" .nodal_average()[0][0]\n",
" .plot.polygons(\n",
" exclude_antimeridian=True,\n",
" cmap=\"coolwarm\",\n",
" title=\"Without Antimeridian Faces\",\n",
" width=900,\n",
" height=400,\n",
" )\n",
").cols(1)"
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ <h2>Structured Grids<a class="headerlink" href="#structured-grids" title="Link t
warnings.warn(f&#39;Downloading: {url}&#39;, DownloadWarning)
</pre></div>
</div>
<img alt="../../_images/b4010254347df0da49cc6ba8c11dbe94eec5d0b607c3c680b88e1a1ed7bde5a0.png" src="../../_images/b4010254347df0da49cc6ba8c11dbe94eec5d0b607c3c680b88e1a1ed7bde5a0.png" />
<img alt="../../_images/550581dcf7a088dbc166a4e8a26354cb8085df9bbc631e5e1264a05073c5df2c.png" src="../../_images/550581dcf7a088dbc166a4e8a26354cb8085df9bbc631e5e1264a05073c5df2c.png" />
</div>
</div>
</section>
Expand Down
Loading

0 comments on commit b71e3ae

Please sign in to comment.