Skip to content

Commit 3446bcd

Browse files
authored
Merge pull request #10 from pp-mo/rearrange_sections
Tidy + rearrange existing sections
2 parents 795c4af + 61dc28a commit 3446bcd

13 files changed

+2858
-3867
lines changed

notebooks/.notebook_shadow_copies/Mesh Tutorial Intro.md renamed to notebooks/.notebook_shadow_copies/Mesh_Tutorial_Intro.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ jupyter:
1414

1515
# LFRic + Iris tutorial : Unstructured meshes
1616

17-
<!-- #region tags=[] -->
18-
---
19-
20-
Some important initial setup (always do first) ..
21-
<!-- #endregion -->
2217

23-
## Important : use + stability of notebooks
18+
## Important Preliminary : use + stability of notebooks
2419

2520
A good deal of the content relies on code which is still experimental.
2621
We must expect that there are various outstanding problems, and things sometimes crash.
@@ -49,6 +44,9 @@ whenever something seems to be taking a long time with no result...
4944
* [01 - Load and Examine some LFRic data](./Sec_01_Load_and_Examine.ipynb)
5045
* [02 - Mesh concepts and Meshes in Iris](./Sec_02_Meshes.ipynb)
5146
* [03 - Plotting and Visualisation](./Sec_03_Plotting.ipynb)
47+
* [04 - Regional Extraction](./Sec_04_RegionExtraction.ipynb)
48+
* [05 - Regridding and UM data comparison](./Sec_05_Regridding.ipynb)
49+
5250

5351

5452
## Reference : terminology (probably, a separate linked glossary ??)
@@ -65,7 +63,7 @@ whenever something seems to be taking a long time with no result...
6563

6664

6765
<!-- #region -->
68-
# **TOPICS LIST?**
66+
# Work To Do : **TOPICS LIST**
6967

7068
A draft list of topics for discussion.
7169
NOTE : all these basically need re-casting as interactive sections lead by task questions.

notebooks/.notebook_shadow_copies/Sec_01_Load_and_Examine.md

Lines changed: 62 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,128 +14,109 @@ jupyter:
1414

1515
# Section 1 : Loading and Examining some LFRic data
1616

17-
Let's dive right in by taking a look at some output file contents.
18-
19-
**TODO: data needs to be available somewhere sensible**
20-
21-
```python tags=[]
22-
from pathlib import Path
23-
datadir = Path('/scratch/sworsley/lfric_data')
24-
datadir.exists()
25-
```
17+
First run some preliminary Python setup, imports etc ...
2618

2719
```python
28-
%ls -1l {datadir}
29-
```
30-
31-
```python
32-
# !ncdump -h /scratch/sworsley/lfric_data/latlon_surface.nc | head -n 100
33-
```
20+
# import the top-level Iris package
21+
import iris
3422

35-
```python
36-
!ncdump -h /scratch/sworsley/lfric_data/20210324T0000Z_lf_ugrid.nc | head -n 100
23+
# import local routines handling access to some test data
24+
from testdata_fetching import lfric_filepth
3725
```
3826

39-
## Relationship to existing Iris usage
40-
41-
Much the same ...
27+
<!-- #region -->
28+
## Iris unstructured loading
29+
Let's dive right in by taking a look at some mesh content.
4230

31+
"Unstructured" data can be loaded from UGRID files (i.e. netCDF files containing a UGRID-style mesh).
32+
This is just like normal Iris loading, except that we must *enable* the interpretion of UGRID content,
33+
roughly like this ...
4334

4435
```python
45-
import iris
46-
iris.FUTURE.datum_support = True # avoids some irritating warnings
47-
```
48-
49-
```python
50-
# From these, grab one UM and one LFRic datafile, which roughly correspond
36+
with PARSE_UGRID_ON_LOAD.context():
37+
cube_list = iris.load(path [, constraints])
38+
# ..and/or..
39+
single_cube = iris.load_cube(path [, constraints])
40+
# ..and/or..
41+
selected_cubes = iris.load_cubes(path, cube_constraints)
5142

52-
um_filepth = datadir / '20210324T0000Z_um_latlon.nc'
53-
lfric_filepth = datadir / '20210324T0000Z_lf_ugrid.nc'
5443
```
5544

56-
<!-- #region tags=[] -->
57-
## Just for reference : some UM data, and what that looks like in Iris ...
45+
**Exercise : first import the `PARSE_UGRID_ON_LOAD` object from iris.experimental.ugrid.load**
5846
<!-- #endregion -->
5947

6048
```python
61-
um_cubes = iris.load(um_filepth)
49+
from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD
6250
```
6351

64-
```python
65-
print("n(UM-cubes) = ", len(um_cubes))
66-
print("first 10 cubes ...")
67-
um_cubes[:10]
68-
```
52+
<!-- #region -->
53+
---
6954

70-
```python
71-
um_rh = um_cubes.extract_cube('relative_humidity')
72-
um_rh
73-
```
55+
The variable `lfric_filepath` is already set up, pointing to a suitable test file.
7456

75-
<!-- #region -->
76-
### NOTE: loading a single cube
77-
You could instead load a single cube directly from the file.
78-
```python
79-
um_rh = iris.load_cube(um_filepth, 'relative_humidity')
80-
```
81-
This is in fact rather faster, from a file like this with lots of data-variables (i.e. diagnostics).
82-
<!-- #endregion -->
57+
**Exercise : Load all data from `lfric_filepath`, with the UGRID loading enabled, and print the first 10 cubes.**
58+
Use the plain 'load' method, as shown above.
59+
NOTE : ***expect this to take a few seconds to complete.***
60+
61+
<details><summary>Sample code solution <b>click to reveal</b></summary>
8362

8463
```python
64+
with PARSE_UGRID_ON_LOAD.context():
65+
cubes = iris.load(lfric_)
8566

67+
cubes[:10]
8668
```
69+
</details>
70+
<!-- #endregion -->
8771

88-
## What's in the LFRic files ?
72+
```python
73+
# ... space for user code ...
8974

90-
Let's start with a quick look at a dump of the file
91-
-- but not actually all of it, as there are ***dozens*** of disagnostic variables ...
92-
75+
with PARSE_UGRID_ON_LOAD.context():
76+
cubes = iris.load(lfric_filepth)
9377

94-
```python
95-
!ncdump -h {lfric_filepth} | head -n 120
78+
cubes[:10]
9679
```
9780

98-
The mesh metadata alone can be better viewed using the "ugrid checker" program, which knows how to interpret it ...
99-
( NOTE: this is a public utility, also designed here in AVD : see https://github.com/pp-mo/ugrid-checks#readme )
10081

101-
```python
102-
!ugrid-checker -sqe {lfric_filepth} | head -n 24
103-
```
82+
**NOTEs :**
83+
* putting just `cubes` at the end triggers notebook printing output
84+
* this also means you can click on each cube to "expand" it into a detail view -- try it
85+
* the effect of `print(cubes)` is different -- try it
10486

105-
---
87+
<!-- #region -->
88+
## Loading a single cube
89+
You can instead load a single cube directly from the file.
90+
This is considerably _faster_ in this case, since the whole file contains ~100 data-variables (i.e. diagnostics).
10691

107-
Let's not bother any more with that : Instead, we can load it into Iris which does a reasonable job of interpreting the mesh-structured data.
92+
**Load just the cube named `relative_humidity_at_screen_level`, from the same file, and show that.**
93+
Hint : it's nicer to use the `load_cube` function
10894

95+
<details><summary>Sample code solution <b>click to reveal</b></summary>
10996

11097
```python
111-
# Load the LFRic single datafile
112-
113-
from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD
114-
# Note the use of the special context. This is basically because the Iris mesh functionality is still 'experimental'
11598
with PARSE_UGRID_ON_LOAD.context():
116-
lfric_cubes = iris.load(lfric_filepth)
117-
```
99+
lfric_rh = iris.load_cube(lfric_filepth, "relative_humidity_at_screen_level")
118100

119-
```python
120-
print("n(LFRic-cubes) = ", len(lfric_cubes))
121-
print("first 10 cubes ...")
122-
lfric_cubes[:10]
101+
lfric_rh
123102
```
103+
---
104+
105+
**NOTEs :**
106+
* putting just `cubes` at the end triggers notebook printing output
107+
* the effect of `print(cubes)` is different -- try it
108+
</details>
109+
<!-- #endregion -->
124110

125111
```python
126-
lfric_rh = lfric_cubes.extract_cube('relative_humidity_at_screen_level')
112+
with PARSE_UGRID_ON_LOAD.context():
113+
lfric_rh = iris.load_cube(lfric_filepth, "relative_humidity_at_screen_level")
127114

128115
lfric_rh
129116
```
130117

131-
---
132-
Or, just to show a faster selective loading ...
133-
134118
```python
135-
with PARSE_UGRID_ON_LOAD.context():
136-
lfric_rh = iris.load_cube(lfric_filepth, 'relative_humidity_at_screen_level')
137119

138-
lfric_rh
139120
```
140121

141122
## What you initially notice about "mesh cubes"
@@ -173,14 +154,14 @@ print("cube.mesh_dim() = ", lfric_rh.mesh_dim())
173154
<br>
174155

175156
```python
176-
#-------------------------------
177-
# Utility Function
157+
###-------------------------------
158+
### Utility Function
178159
#
179160
def is_meshcube(cube):
180161
return cube.mesh is not None
181162

182163
#-------------------------------
183-
# Testing ...
164+
### Testing ...
184165
#
185166
from iris.tests.stock import realistic_3d
186167
nonmesh_cube = realistic_3d()

0 commit comments

Comments
 (0)