Skip to content

Commit 7273179

Browse files
committed
Tidy + improve mesh-from-numbers bonues example.
1 parent 3def071 commit 7273179

File tree

2 files changed

+85
-34
lines changed

2 files changed

+85
-34
lines changed

notebooks/.notebook_shadow_copies/mesh_from_numbers.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ jupyter:
1212
name: python3
1313
---
1414

15-
```python
16-
17-
```
18-
19-
## Constructing an Iris mesh from bare numbers
15+
# Constructing an Iris mesh from bare numbers
2016

2117
```python
22-
# Construct a test mesh from scratch ??
18+
# Construct a test mesh from scratch : define a mesh in numbers
2319

20+
# define some node X and Y points
2421
import numpy as np
2522
big_points_x = np.array([6.0, 3, 5, 1, 5, 3, 5, 5, 4, 2, 1, 6, 3, 5, 3, 6, 2, 6, 1, 2, 2, 4, 1, 4, 4, 3, 4, 6, 2, 1])
2623
big_points_y = np.array([2.5, 1, 3, 0, 2, 0, 0, 4, 3.5, 2.5, 1, 4.5, 4, 1, 3, 3.5, 0.5, 0.5, 3, 4.5, 1.5, 2.5, 4, 1.5, 4.5, 2, 0.5, 1.5, 3.5, 2])
@@ -29,6 +26,7 @@ big_points = np.stack([big_points_x, big_points_y]).T
2926

3027
big_data = 100 * np.random.rand(30)
3128

29+
# define which faces use which points
3230
big_faces = [
3331
[22, 28, 19],
3432
[18, 28, 22],
@@ -59,16 +57,21 @@ for face in big_faces:
5957
big_face_plottable_x[-1].append(big_points_x[face[0]])
6058
big_face_plottable_y[-1].append(big_points_y[face[0]])
6159

62-
# Find coordinates in the middle of the faces
63-
60+
61+
# Calculate coordinates of locations in the "middle" of each face
62+
# N.B. except, means of lats + lons are not true centres !
6463
face_coordinates_x = [np.mean(xs) for xs in big_face_plottable_x]
6564
face_coordinates_y = [np.mean(ys) for ys in big_face_plottable_y]
6665

67-
big_face_data = np.random.rand(face_count)
66+
# Calculate some random data for the cube 'payload'.
67+
np.random.seed(seed=1234)
68+
big_face_data = np.random.uniform(0, 100, face_count)
6869
```
6970

7071
```python
71-
### We know about this stuff
72+
# Create the component coordinates and connectivities.
73+
74+
import iris.experimental.ugrid
7275
from iris.coords import AuxCoord
7376

7477
# node coordinates
@@ -91,7 +94,8 @@ face_coords_and_axes = [
9194
```
9295

9396
```python
94-
# I'll be shocked if you ever make a mesh like this
97+
# Make a mesh by passing the coordinates + connectivities
98+
# N.B. it's pretty unusual to be calling this directly, but the API does exist
9599

96100
from iris.experimental.ugrid.mesh import Mesh
97101

@@ -106,7 +110,8 @@ print(my_first_mesh)
106110

107111
```python
108112
# Here we make a cube with data attached to **faces**
109-
# (one mesh can be attached to different cubes, with those cubes using the same or different locations)
113+
# N.B. a mesh may be shared by multiple cubes, the cubes may use the same or different locations
114+
110115
from iris.cube import Cube
111116

112117
x_coord = iris.experimental.ugrid.mesh.MeshCoord(my_first_mesh, "face", "x")
@@ -122,3 +127,15 @@ my_first_mesh_cube = iris.cube.Cube(
122127

123128
my_first_mesh_cube
124129
```
130+
131+
```python
132+
# Assign some data to the cube, convert to a PolyData and plot it
133+
134+
from pv_conversions import pv_from_lfric_cube
135+
pv = pv_from_lfric_cube(my_first_mesh_cube)
136+
pv.plot(jupyter_backend='static')
137+
```
138+
139+
```python
140+
141+
```

0 commit comments

Comments
 (0)