Grid Visualization
In this section, you’ll learn about:
Plotting the edges of an unstructured grid
Plotting the coordinates of an unstructured grid
Related Documentation
Time to learn: 10 minutes
Introduction
Unstructured grids play a vital role in scientific computing and numerical simulations. UXarray’s Grid
data structure provides a robust foundation for working with these grids by managing essential variables like coordinates and connectivity information. Before conducting complex data analysis or running simulations, it’s often crucial to visualize and verify the grid geometry.
This visualization capability serves multiple purposes: It helps users understand the mesh topology, identify potential issues in grid generation, and verify boundary conditions. For example, when preparing to run a dynamical core simulation, scientists often examine the computational grid to ensure it meets their requirements for spatial resolution and element quality.
To demonstrate these visualization techniques, we’ll work with a straightforward example: An unstructured grid consisting of four hexagonal elements.
import uxarray as ux
grid_path = "../../meshfiles/hex.grid.nc"
uxgrid = ux.open_grid(grid_path)
uxgrid
<uxarray.Grid> Original Grid Type: UGRID Grid Dimensions: * n_node: 16 * n_edge: 19 * n_face: 4 * n_max_face_nodes: 6 * n_nodes_per_face: (4,) Grid Coordinates (Spherical): * node_lon: (16,) * node_lat: (16,) * edge_lon: (19,) * edge_lat: (19,) * face_lon: (4,) * face_lat: (4,) Grid Coordinates (Cartesian): Grid Connectivity Variables: * face_node_connectivity: (4, 6) Grid Descriptor Variables: * n_nodes_per_face: (4,)
Plotting Accessor
UXarray provides streamlined access to all visualization methods through the Grid.plot
accessor. This interface serves as the central entry point for grid visualization, with each grid object supporting a default visualization method when calling Grid.plot()
.
uxgrid.plot(title="Default Plot Function")
Accessing specific plotting functions is showcased below.
Visualizing Edges
Edge visualization is a fundamental technique for understanding the unstructured grid topology. By plotting the edges between grid elements, we can examine the mesh structure, verify connectivity patterns, and assess the overall grid quality. The edge representation provides an intuitive view of how elements are arranged and connected.
uxgrid.plot.edges(title="Edge Plot")
Visualizing Coordinates
Unstructured grids incorporate three distinct types of geometric coordinates, each serving a specific purpose in defining the grid’s spatial structure and properties.
Corner Nodes
Corner nodes define the fundamental geometry of each grid element through their latitude and longitude coordinates, which are stored in the Grid.node_lat
and Grid.node_lon
variables.
uxgrid.plot.corner_nodes(title="Corner Nodes") * uxgrid.plot()
Face Centers
Face centers represent the geometric centroid of each grid element, with their latitude and longitude coordinates stored in the Grid.face_lat
and Grid.face_lon
variables.
uxgrid.plot.face_centers(title="Face Centers") * uxgrid.plot()
Edge Centers
Edge centers denote the midpoint of each grid boundary segment, with their spatial coordinates stored in the Grid.edge_lat
and Grid.edge_lon
variables.
uxgrid.plot.edge_centers(title="Face Centers") * uxgrid.plot()
Plotting Everything Together
By combining the visualization of edges, face centers, corner nodes, and edge centers, we can generate a comprehensive representation of the unstructured grid’s geometry. This allows us to example the complete spatial structure of our grid.
(
uxgrid.plot.edges(color="black")
* uxgrid.plot.nodes(marker="o", size=150).relabel("Corner Nodes")
* uxgrid.plot.face_centers(marker="s", size=150).relabel("Face Centers")
* uxgrid.plot.edge_centers(marker="^", size=150).relabel("Edge Centers")
).opts(title="Grid Coordinates", legend_position="top_right")