Skip to content

Commit 5960164

Browse files
committed
Self-contained runnable sample code for basic mesh plotting.
1 parent 064e6ee commit 5960164

File tree

2 files changed

+37
-42
lines changed

2 files changed

+37
-42
lines changed
166 KB
Loading

docs/src/further_topics/ugrid/operations.rst

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,32 @@ earlier:
483483

484484
.. code-block:: python
485485
486+
>>> import iris
487+
>>> from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD
488+
>>>
486489
>>> from geovista import GeoPlotter, Transform
487-
>>> from geovista.common import to_xyz
488-
489-
490-
# We'll re-use this to plot some real global data later.
490+
>>> from geovista.common import to_cartesian as to_xyz
491+
>>>
492+
>>> testdata_path = iris.sample_data_path("mesh_C4_synthetic_float.nc")
493+
>>> with PARSE_UGRID_ON_LOAD.context():
494+
... cube = iris.load_cube(testdata_path)
495+
...
496+
>>> print(cube)
497+
synthetic / (1) (-- : 96)
498+
Mesh coordinates:
499+
latitude x
500+
longitude x
501+
Mesh:
502+
name Topology data of 2D unstructured mesh
503+
location face
504+
Attributes:
505+
NCO 'netCDF Operators version 4.7.5 (Homepage = http://nco.sf.net, Code = h ...'
506+
history 'Mon Apr 12 01:44:41 2021: ncap2 -s synthetic=float(synthetic) mesh_C4_synthetic.nc ...'
507+
nco_openmp_thread_number 1
491508
>>> def cube_faces_to_polydata(cube):
492509
... lons, lats = cube.mesh.node_coords
493510
... face_node = cube.mesh.face_node_connectivity
494511
... indices = face_node.indices_by_location()
495-
...
496512
... mesh = Transform.from_unstructured(
497513
... lons.points,
498514
... lats.points,
@@ -502,50 +518,29 @@ earlier:
502518
... start_index=face_node.start_index,
503519
... )
504520
... return mesh
505-
506-
>>> print(face_cube)
507-
face_data / (K) (-- : 2; height: 3)
508-
Dimension coordinates:
509-
height - x
510-
Mesh coordinates:
511-
latitude x -
512-
longitude x -
513-
Attributes:
514-
Conventions 'CF-1.7'
515-
516-
# Convert our mesh+data to a PolyData object.
517-
# Just plotting a single height level.
518-
>>> face_polydata = cube_faces_to_polydata(face_cube[:, 0])
521+
...
522+
>>> face_polydata = cube_faces_to_polydata(cube)
519523
>>> print(face_polydata)
520-
PolyData (0x7ff4861ff4c0)
521-
N Cells: 2
522-
N Points: 5
523-
X Bounds: 9.903e-01, 1.000e+00
524-
Y Bounds: 0.000e+00, 1.392e-01
525-
Z Bounds: 6.123e-17, 5.234e-02
526-
N Arrays: 2
527-
528-
# Create the GeoVista plotter and add our mesh+data to it.
524+
PolyData (0x7f179a6b2800)
525+
N Cells: 96
526+
N Points: 98
527+
N Strips: 0
528+
X Bounds: -1.000e+00, 1.000e+00
529+
Y Bounds: -1.000e+00, 1.000e+00
530+
Z Bounds: -1.000e+00, 1.000e+00
531+
N Arrays: 4
532+
>>>
529533
>>> my_plotter = GeoPlotter()
530-
>>> my_plotter.add_coastlines(color="black")
531-
>>> my_plotter.add_base_layer(color="grey")
532-
>>> my_plotter.add_mesh(face_polydata)
533-
534-
# Centre the camera on the data.
535-
>>> camera_region = to_xyz(
536-
... face_cube.coord("longitude").points,
537-
... face_cube.coord("latitude").points,
538-
... radius=3,
539-
... )
540-
>>> camera_pos = camera_region.mean(axis=0)
541-
>>> my_plotter.camera.position = camera_pos
542-
534+
>>> my_plotter.background_color = "#502020ff"
535+
>>> _ = my_plotter.add_coastlines(color="white", radius=1.01)
536+
>>> _ = my_plotter.add_mesh(face_polydata, radius=1.0)
537+
>>>
543538
>>> my_plotter.show()
544539
545540
.. image:: images/plotting_basic.png
546541
:alt: A GeoVista plot of the basic example Mesh.
547542

548-
This artificial data makes West Africa rather chilly!
543+
This artificial data is very low resolution !
549544

550545
Here's another example using a global cubed-sphere data set:
551546

0 commit comments

Comments
 (0)