Skip to content

Commit faf317c

Browse files
committed
wkg
1 parent 31f263b commit faf317c

15 files changed

+923
-771
lines changed

notebooks/.notebook_shadow_copies/Mesh_Connectivities_demo.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ import numpy as np
2727
from pv_conversions import pv_from_lfric_cube
2828
```
2929

30-
```python
31-
## TODO : remove later -- this bit is temporary, for initial testing with C48 data
32-
from testdata_fetching import switch_data
33-
switch_data(use_newer_smaller_c48_data=True)
34-
```
35-
3630
```python
3731
from testdata_fetching import lfric_rh_singletime_2d
3832
cube = lfric_rh_singletime_2d()
@@ -61,7 +55,7 @@ x_nodes_coord
6155
```
6256

6357
---
64-
## Find the number of the node nearest one corner of the cubesphere
58+
## Find the number of the node nearest to one corner of the cubesphere
6559

6660
```python
6761
xx = x_nodes_coord.points
@@ -84,7 +78,7 @@ print(' ', xy_dists[i_node_nearest_corner - 2:i_node_nearest_corner + 3]
8478
## Find the faces which touch that (corner) node
8579

8680
```python
87-
# (spoiler alert : if we specced the corner right, there are probably 3 of them)
81+
# (spoiler alert : if we specified the corner correctly, there should be 3 of these)
8882
face_nodes = cube.mesh.face_node_connectivity.indices
8983
assert face_nodes.ndim == 2 and face_nodes.shape[1] == 4
9084
```
@@ -104,7 +98,11 @@ cube.data[corner_faces] = marks
10498

10599
# Plot the cube
106100
pv = pv_from_lfric_cube(cube)
107-
pv.plot(show_edges=True, jupyter_backend='static')
101+
plt = pv.plot(show_edges=True, jupyter_backend='static')
102+
```
103+
104+
```python
105+
108106
```
109107

110108
---

notebooks/.notebook_shadow_copies/Mesh_Tutorial_Intro.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jupyter:
1414

1515
# LFRic + Iris tutorial : Unstructured meshes
1616

17+
The tutorial is provided as a set of Jupyter notebooks, best viewed in Juptyer lab.
18+
Please see list below for the individual topics.
19+
1720

1821
## Important Preliminary : use + stability of notebooks
1922

@@ -44,7 +47,7 @@ We suggest that you launch the Jupyter server _itself_ in the dedicated (conda)
4447

4548

4649
---
47-
## Tutorial sections : --> individual notebooks
50+
## Tutorial sections : _links_ to individual notebooks
4851
* [01 - Load and Examine some LFRic data](./Sec_01_Load_and_Examine.ipynb)
4952
* [02 - Mesh concepts and Meshes in Iris](./Sec_02_Meshes.ipynb)
5053
* [03 - Plotting and Visualisation](./Sec_03_Plotting.ipynb)

notebooks/.notebook_shadow_copies/Sec_02_Meshes.md

Lines changed: 27 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ Extra Notes:
5555

5656
<!-- #endregion -->
5757

58+
### Construction of an abstract Mesh in Iris
59+
This is too complex to cover in detail here.
60+
For those interested, this is explained in the bonus notebook ["mesh_from_numbers.ipynb"](./mesh_from_numbers.ipynb).
61+
62+
5863
## Actual LFRic meshes
5964

6065
The most common usage (at least in LFRic output), is to have a mesh which defines nodes + faces,
@@ -66,22 +71,24 @@ Here is an example of what that looks like :--
6671
![Picture of nodes and faces](LFRic_mesh.svg)
6772

6873

69-
This demonstrates the relationship between face-numbers, node-numbers and node coordinates.
74+
This diagram demonstrates the relationship between face-numbers, node-numbers and node coordinates.
7075
Note that no _edges_ are shown here : In UGRID, and Iris, mesh faces do not depend on edges, but are built only from nodes.
7176

77+
Technically, the LFRic mesh is a "**cubesphere**".
78+
* the surface of the globe is divided into 6 equal 'panels', analagous to the 6 faces of a cube
79+
* each panel is subdivided into N * N cells, giving 6.N^2 total cells
80+
* the above view shows the neighbourhood of one cubesphere 'corner'
81+
82+
**We will next load some actual LFRic data and look at how the mesh appears in Iris.**
83+
7284

7385
---
7486

75-
## Fetch some sample unstructured data, as used in Section#01
87+
### Fetch some sample unstructured data
88+
As used in Section#01
7689

7790
**Import the data-access routine `lfric_rh_singletime_2d` from `testdata_fetching`, and call it to get a single two-dimensional test cube.**
7891

79-
```python
80-
## TODO : remove later -- this bit is temporary, for initial testing with C48 data
81-
from testdata_fetching import switch_data
82-
switch_data(use_newer_smaller_c48_data=True)
83-
```
84-
8592
```python
8693
from testdata_fetching import lfric_rh_singletime_2d
8794
lfric_rh = lfric_rh_singletime_2d()
@@ -95,111 +102,44 @@ print('\n----\n')
95102
print(lfric_rh.mesh)
96103
```
97104

98-
```python
99-
# TODO: work this up for user input
105+
### Details of the Iris mesh content
100106

101-
# Simply plot that ..
102-
from pv_conversions import pv_from_lfric_cube
103-
pv = pv_from_lfric_cube(lfric_rh)
104-
pv.plot() #jupyter_backend='static')
105-
```
106-
107-
```python
108-
109-
```
110-
111-
### Investigate the Iris mesh content
112-
113-
Details of how the Iris mesh is constructed are not usually relevant to working with the cube data in Iris, nor to plotting it with PyVista.
107+
How Iris represents the mesh is not usually very relevant to working with cube data in Iris, nor to plotting it with PyVista.
114108
So that is beyond the scope of an introductory tutorial.
115109

116-
However, for those interested, bonus material is provided showing some of this [in this additional notebook](./Mesh_Connectivities_demo.ipynb)
110+
However, for those interested, there is a bonus notebook showing some of this : ["Mesh_Connectivities_demo.ipynb"](./Mesh_Connectivities_demo.ipynb)
117111

118112

119113

120-
## Plotting mesh data : minimal 3D visualisation of a 2D cube
114+
### Plotting mesh data : minimal 3D visualisation of a 2D cube
121115

122-
<!-- #region -->
123-
First, slice the cube to get the first timestep only
124-
-- as we can only (easily) plot a 2d cube.
125116

126-
**Ex: Put this in a new cube variable, which is our 2D cube.**
127-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
117+
This is just a quick preview of the next section (Sec_03_Plotting), to show a basic 3D plot.
128118

129-
```python
130-
rh_t0 = lfric_rh[0]
131-
```
132-
</details>
133-
<!-- #endregion -->
134-
135-
```python
136-
from testdata_fetching import lfric_rh_singletime_2d
137-
138-
rh_t0 = lfric_rh_singletime_2d()
139-
```
140119

141120
<!-- #region jp-MarkdownHeadingCollapsed=true tags=[] -->
142-
### Convert a cube to PyVista form for plotting
121+
**Convert a cube to PyVista form for plotting**
143122

144123
There are as yet *no* facilities in Iris for plotting unstructed cubes.
145124
We can do that using PyVista, but we need first to convert the data to a PyVista format.
146125

147126
So first,
148-
**Ex: import the routine `pv_from_lfric_cube` from the package `pv_conversions` (provided here in the tutorial).**
149-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
127+
**Import the routine** `pv_conversions.pv_from_lfric_cube` **(provided here in the tutorial).
128+
And call that..**
150129

151-
```python
152-
from pv_conversions import pv_from_lfric_cube
153-
```
154-
</details>
155130
<!-- #endregion -->
156131

157132
```python
158133
from pv_conversions import pv_from_lfric_cube
159-
```
160134

161-
<!-- #region -->
162-
**Ex: now call that function, passing it our 2D RH cube, to get a PyVista object.**
163-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
164-
165-
```python
166135
pv = pv_from_lfric_cube(rh_t0)
167136
```
168-
</details>
169-
<!-- #endregion -->
170137

171-
```python
172-
pv = pv_from_lfric_cube(rh_t0)
173-
```
174-
175-
<!-- #region -->
176138
This produces a PyVista ["PolyData" object](https://docs.pyvista.org/api/core/_autosummary/pyvista.PolyData.html#pyvista-polydata).
177-
Which is a thing we can plot.
178-
179-
**Now just print that + see what it looks like ...**
180-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
181-
182-
```python
183-
pv
184-
```
185-
</details>
186-
<!-- #endregion -->
187-
188-
```python
189-
pv
190-
```
191-
192-
***TODO:*** some notes here on what the detail means ?
193-
194-
195-
( Note: like `Cube`s + `CubeList`s, these `PolyData` objects are provided with a specific visible within the Jupyter notebooks. This is displayed when you just enter the variable in a cell.
196-
You can also use "print(x)" to display the standard string representation of the object, but usually the notebook-style output is a bit more useful. )
139+
Which is a thing we can plot, by simply calling its `.plot()` method.
197140

198141

199142
---
200-
### Quick 3d plotting
201-
202-
For a really quick, basic plot, you can display a PolyData as a VTK view with PyVista, by simply calling its `.plot` method.
203143

204144
**Call the `plot` routine of the PolyData object. An output should appear.**
205145

@@ -213,72 +153,13 @@ pv.plot()
213153
* To ***remove*** a plot output, use "Clear Output" from the "Edit" menu (or from right-click on the cell)
214154
* alternatively, set the keyword `jupyter_backend='static'` in the command, for output as a plain image
215155

216-
There are a lot more keywords available to [the `PolyData.plot()` method](https://docs.pyvista.org/api/core/_autosummary/pyvista.PolyData.plot.html), but it is not ideal to overcomplicate these calls. :
156+
There are a lot more keywords available to [the `PolyData.plot()` method](https://docs.pyvista.org/api/core/_autosummary/pyvista.PolyData.plot.html), but it is not ideal to overcomplicate these calls.
217157
Finer control is better achieved in a different ways : See more detail on plotting in [the Plotting section](./Sec_03_Plotting.ipynb).
218158

219159

220-
<!-- #region tags=[] -->
221-
### Create a plotter, and display 3D visualisation
222-
223-
Finally, we will plot the 'PolyData' object via PyVista.
224-
This requires a few additional steps ...
225-
226-
First, we need a [PyVista "plotter"](https://docs.pyvista.org/api/plotting/_autosummary/pyvista.Plotter.html#pyvista.Plotter) object to display things in 3D.
227-
Since our data is geo-located, we will use a special type of plotter from [GeoVista](https://github.com/bjlittle/geovista#philisophy) for this.
228-
229-
**Import the class `GeoPlotter` from the `geovista` package, and create one** (with no arguments)
230-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
160+
## Next notebook
161+
See the next section : [03 - Plotting and Visualisation](./Sec_03_Plotting.ipynb)
231162

232163
```python
233-
from geovista import GeoPlotter
234-
plotter = GeoPlotter()
235-
```
236-
</details>
237-
<!-- #endregion -->
238164

239-
```python
240-
from geovista import GeoPlotter
241-
plotter = GeoPlotter()
242165
```
243-
244-
<!-- #region -->
245-
Call the plotter `add_mesh` function, passing in our PolyData object with the Rh cube data in it.
246-
( **N.B.** don't worry about the object which this passes back -- just discard it ).
247-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
248-
249-
```python
250-
_ = plotter.add_mesh(pv)
251-
```
252-
</details>
253-
<!-- #endregion -->
254-
255-
```python
256-
_ = plotter.add_mesh(pv)
257-
```
258-
259-
<!-- #region -->
260-
Now simply plot this, by calling the plotter function "show" (with no args).
261-
<details><summary>Sample code solution : <b>click to reveal</b></summary>
262-
263-
```python
264-
plotter.show()
265-
```
266-
</details>
267-
<!-- #endregion -->
268-
269-
```python
270-
plotter.show()
271-
```
272-
273-
**Some odd notes:**
274-
* By default, `plotter.show()` opens an interactive window : **you can rotate and zoom it with the mouse**.
275-
* you can instead generate static output
276-
* in a notebook, you do this with `jupyter_backend='static'`
277-
* or in a Python session, try `interactive=False`
278-
* VTK/PyVista doesn't use plot "types".
279-
Instead, you add meshes to a plotter + can subsequently control the presentation.
280-
* GeoVista can also produce more familiar 2D plots (see on ...)
281-
282-
283-
284-
***TODO:*** can suggest some of these as follow-on exercises

0 commit comments

Comments
 (0)