Skip to content

Commit 8cb845b

Browse files
address additional comments
1 parent d899b51 commit 8cb845b

File tree

2 files changed

+196
-57
lines changed

2 files changed

+196
-57
lines changed

notebooks/.notebook_shadow_copies/Sec_05_Regridding.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import iris
2525
from iris import load, load_cube
2626
from iris.coords import DimCoord
2727
from iris.cube import Cube
28-
from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD
2928
```
3029

3130
## Example: Regridding LFRic data
@@ -60,7 +59,7 @@ regridder = MeshToGridESMFRegridder(mesh_cube, grid_cube)
6059
```python
6160
# Regrid the mesh cube.
6261
result = regridder(mesh_cube)
63-
print(result)
62+
result
6463
```
6564

6665
The reason this is done in two steps is because initialising a regridder is potentially quite expensive if the grids or meshes involved are large. Once initialised, a regridder can regrid many source cubes (defined on the same source grid/mesh) onto the same target. We can demonstrate this by regridding a different cube using the same regridder.
@@ -185,15 +184,20 @@ plt.show()
185184

186185
## Exercise 2: Zonal means
187186

188-
A zonal mean is the area weighted average over a defined region. e.g. a band of latitude/longitude.
189-
Calculating zonal means can be done as a regridding operation where the zone is defined by the target cube.
190-
In this example, the target cube will contain a single cell.
187+
For a latlon cube, a common operation is to collapse over longitude by taking an average. This is not possible for an LFRic style mesh cube since there is no independent longitude dimension to collapse. While it is possible to regrid to a latlon cube and then collapse, this introduces an additional step to the process. Instead, it is possible to simplify this into a single step by considering this as a regridding operation where the target cube contains multiple latitude bands.
191188

192-
**Step 1:** Define a latitude coordinate whose bounds are `[[-20, 20]]`. Remember to set the standard name to be `"latitude"` and the units to be `"degrees"`
189+
A zonal mean is the area weighted average over a defined region or sequence of regions. e.g. a band of latitude/longitude.
190+
Calculating zonal means can be done as a regridding operation where the zone is defined by the target cube. This can involve a target cube with a single cell or, as in this example, a number of cells along the latitude dimension.
193191

194-
```python
195-
lat_band = DimCoord(0, bounds=[[-20, 20]], standard_name="latitude", units="degrees")
192+
**Step 1:** Define a latitude coordinate whose bounds are `[[-90, -60], [-60, -30], [-30, 0], [0, 30], [30, 60], [60, 90]]`. Remember to set the standard name to be `"latitude"` and the units to be `"degrees"`
196193

194+
```python
195+
lat_bands = DimCoord(
196+
[-75, -45, -15, 15, 45, 75],
197+
bounds=[[-90, -60], [-60, -30], [-30, 0], [0, 30], [30, 60], [60, 90]],
198+
standard_name="latitude",
199+
units="degrees"
200+
)
197201
```
198202

199203
**Step 2:** Define a longitude coordinate whose bounds are `[[-180, 180]]`. Remember to set the standard name to be `"longitude"` and the units to be `"degrees"`
@@ -205,9 +209,9 @@ lon_full = DimCoord(0, bounds=[[-180, 180]], standard_name="longitude", units="d
205209
**Step 3:** Create a single celled cube (i.e. `Cube([[0]])`) and attach the latitude and longitude coordinates to it.
206210

207211
```python
208-
lat_band_cube = Cube([[0]])
209-
lat_band_cube.add_dim_coord(lat_band, 0)
210-
lat_band_cube.add_dim_coord(lon_full, 1)
212+
lat_band_cube = Cube([[0, 0, 0, 0, 0, 0]])
213+
lat_band_cube.add_dim_coord(lat_bands, 1)
214+
lat_band_cube.add_dim_coord(lon_full, 0)
211215
print(lat_band_cube)
212216
```
213217

notebooks/Sec_05_Regridding.ipynb

Lines changed: 181 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"import iris\n",
2525
"from iris import load, load_cube\n",
2626
"from iris.coords import DimCoord\n",
27-
"from iris.cube import Cube\n",
28-
"from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD"
27+
"from iris.cube import Cube"
2928
]
3029
},
3130
{
@@ -375,7 +374,7 @@
375374
},
376375
{
377376
"cell_type": "code",
378-
"execution_count": 6,
377+
"execution_count": 29,
379378
"id": "fb72ce6d-0724-45da-a4d1-b004b6ce6bb5",
380379
"metadata": {},
381380
"outputs": [],
@@ -396,38 +395,158 @@
396395
},
397396
{
398397
"cell_type": "code",
399-
"execution_count": 7,
398+
"execution_count": 28,
400399
"id": "c6d9036e-6c44-4926-a85f-bacd18fe37e1",
401400
"metadata": {},
402401
"outputs": [
403402
{
404-
"name": "stdout",
405-
"output_type": "stream",
406-
"text": [
407-
"surface_altitude / (m) (latitude: 480; longitude: 640)\n",
408-
" Dimension coordinates:\n",
409-
" latitude x -\n",
410-
" longitude - x\n",
411-
" Scalar coordinates:\n",
412-
" forecast_period 21600 seconds\n",
413-
" forecast_reference_time 2021-03-24 00:00:00\n",
414-
" time 2021-03-24 06:00:00\n",
415-
" Cell methods:\n",
416-
" point time\n",
417-
" Attributes:\n",
418-
" Conventions 'CF-1.7'\n",
419-
" description 'Created by xios'\n",
420-
" interval_operation '6 h'\n",
421-
" interval_write '6 h'\n",
422-
" online_operation 'instant'\n",
423-
" title 'Created by xios'\n"
424-
]
403+
"data": {
404+
"text/html": [
405+
"\n",
406+
"<style>\n",
407+
" a.iris {\n",
408+
" text-decoration: none !important;\n",
409+
" }\n",
410+
" table.iris {\n",
411+
" white-space: pre;\n",
412+
" border: 1px solid;\n",
413+
" border-color: #9c9c9c;\n",
414+
" font-family: monaco, monospace;\n",
415+
" }\n",
416+
" th.iris {\n",
417+
" background: #303f3f;\n",
418+
" color: #e0e0e0;\n",
419+
" border-left: 1px solid;\n",
420+
" border-color: #9c9c9c;\n",
421+
" font-size: 1.05em;\n",
422+
" min-width: 50px;\n",
423+
" max-width: 125px;\n",
424+
" }\n",
425+
" tr.iris :first-child {\n",
426+
" border-right: 1px solid #9c9c9c !important;\n",
427+
" }\n",
428+
" td.iris-title {\n",
429+
" background: #d5dcdf;\n",
430+
" border-top: 1px solid #9c9c9c;\n",
431+
" font-weight: bold;\n",
432+
" }\n",
433+
" .iris-word-cell {\n",
434+
" text-align: left !important;\n",
435+
" white-space: pre;\n",
436+
" }\n",
437+
" .iris-subheading-cell {\n",
438+
" padding-left: 2em !important;\n",
439+
" }\n",
440+
" .iris-inclusion-cell {\n",
441+
" padding-right: 1em !important;\n",
442+
" }\n",
443+
" .iris-panel-body {\n",
444+
" padding-top: 0px;\n",
445+
" }\n",
446+
" .iris-panel-title {\n",
447+
" padding-left: 3em;\n",
448+
" }\n",
449+
" .iris-panel-title {\n",
450+
" margin-top: 7px;\n",
451+
" }\n",
452+
"</style>\n",
453+
"<table class=\"iris\" id=\"139748445253056\">\n",
454+
" <tr class=\"iris\">\n",
455+
"<th class=\"iris iris-word-cell\">Surface Altitude (m)</th>\n",
456+
"<th class=\"iris iris-word-cell\">latitude</th>\n",
457+
"<th class=\"iris iris-word-cell\">longitude</th>\n",
458+
"</tr>\n",
459+
" <tr class=\"iris\">\n",
460+
"<td class=\"iris-word-cell iris-subheading-cell\">Shape</td>\n",
461+
"<td class=\"iris iris-inclusion-cell\">480</td>\n",
462+
"<td class=\"iris iris-inclusion-cell\">640</td>\n",
463+
"</tr>\n",
464+
" <tr class=\"iris\">\n",
465+
" <td class=\"iris-title iris-word-cell\">Dimension coordinates</td>\n",
466+
" <td class=\"iris-title\"></td>\n",
467+
" <td class=\"iris-title\"></td>\n",
468+
"</tr>\n",
469+
"<tr class=\"iris\">\n",
470+
" <td class=\"iris-word-cell iris-subheading-cell\">\tlatitude</td>\n",
471+
" <td class=\"iris-inclusion-cell\">x</td>\n",
472+
" <td class=\"iris-inclusion-cell\">-</td>\n",
473+
"</tr>\n",
474+
"<tr class=\"iris\">\n",
475+
" <td class=\"iris-word-cell iris-subheading-cell\">\tlongitude</td>\n",
476+
" <td class=\"iris-inclusion-cell\">-</td>\n",
477+
" <td class=\"iris-inclusion-cell\">x</td>\n",
478+
"</tr>\n",
479+
"<tr class=\"iris\">\n",
480+
" <td class=\"iris-title iris-word-cell\">Scalar coordinates</td>\n",
481+
" <td class=\"iris-title\"></td>\n",
482+
" <td class=\"iris-title\"></td>\n",
483+
"</tr>\n",
484+
"<tr class=\"iris\">\n",
485+
" <td class=\"iris-word-cell iris-subheading-cell\">\tforecast_period</td>\n",
486+
" <td class=\"iris-word-cell\" colspan=\"2\">21600 seconds</td>\n",
487+
"</tr>\n",
488+
"<tr class=\"iris\">\n",
489+
" <td class=\"iris-word-cell iris-subheading-cell\">\tforecast_reference_time</td>\n",
490+
" <td class=\"iris-word-cell\" colspan=\"2\">2021-03-24 00:00:00</td>\n",
491+
"</tr>\n",
492+
"<tr class=\"iris\">\n",
493+
" <td class=\"iris-word-cell iris-subheading-cell\">\ttime</td>\n",
494+
" <td class=\"iris-word-cell\" colspan=\"2\">2021-03-24 06:00:00</td>\n",
495+
"</tr>\n",
496+
"<tr class=\"iris\">\n",
497+
" <td class=\"iris-title iris-word-cell\">Cell methods</td>\n",
498+
" <td class=\"iris-title\"></td>\n",
499+
" <td class=\"iris-title\"></td>\n",
500+
"</tr>\n",
501+
"<tr class=\"iris\">\n",
502+
" <td class=\"iris-word-cell iris-subheading-cell\">\tpoint</td>\n",
503+
" <td class=\"iris-word-cell\" colspan=\"2\">time</td>\n",
504+
"</tr>\n",
505+
"<tr class=\"iris\">\n",
506+
" <td class=\"iris-title iris-word-cell\">Attributes</td>\n",
507+
" <td class=\"iris-title\"></td>\n",
508+
" <td class=\"iris-title\"></td>\n",
509+
"</tr>\n",
510+
"<tr class=\"iris\">\n",
511+
" <td class=\"iris-word-cell iris-subheading-cell\">\tConventions</td>\n",
512+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;CF-1.7&#x27;</td>\n",
513+
"</tr>\n",
514+
"<tr class=\"iris\">\n",
515+
" <td class=\"iris-word-cell iris-subheading-cell\">\tdescription</td>\n",
516+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;Created by xios&#x27;</td>\n",
517+
"</tr>\n",
518+
"<tr class=\"iris\">\n",
519+
" <td class=\"iris-word-cell iris-subheading-cell\">\tinterval_operation</td>\n",
520+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;6 h&#x27;</td>\n",
521+
"</tr>\n",
522+
"<tr class=\"iris\">\n",
523+
" <td class=\"iris-word-cell iris-subheading-cell\">\tinterval_write</td>\n",
524+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;6 h&#x27;</td>\n",
525+
"</tr>\n",
526+
"<tr class=\"iris\">\n",
527+
" <td class=\"iris-word-cell iris-subheading-cell\">\tonline_operation</td>\n",
528+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;instant&#x27;</td>\n",
529+
"</tr>\n",
530+
"<tr class=\"iris\">\n",
531+
" <td class=\"iris-word-cell iris-subheading-cell\">\ttitle</td>\n",
532+
" <td class=\"iris-word-cell\" colspan=\"2\">&#x27;Created by xios&#x27;</td>\n",
533+
"</tr>\n",
534+
"</table>\n",
535+
" "
536+
],
537+
"text/plain": [
538+
"<iris 'Cube' of surface_altitude / (m) (latitude: 480; longitude: 640)>"
539+
]
540+
},
541+
"execution_count": 28,
542+
"metadata": {},
543+
"output_type": "execute_result"
425544
}
426545
],
427546
"source": [
428547
"# Regrid the mesh cube.\n",
429548
"result = regridder(mesh_cube)\n",
430-
"print(result)"
549+
"result"
431550
]
432551
},
433552
{
@@ -1266,21 +1385,27 @@
12661385
"source": [
12671386
"## Exercise 2: Zonal means\n",
12681387
"\n",
1269-
"A zonal mean is the area weighted average over a defined region. e.g. a band of latitude/longitude.\n",
1270-
"Calculating zonal means can be done as a regridding operation where the zone is defined by the target cube.\n",
1271-
"In this example, the target cube will contain a single cell.\n",
1388+
"For a latlon cube, a common operation is to collapse over longitude by taking an average. This is not possible for an LFRic style mesh cube since there is no independent longitude dimension to collapse. While it is possible to regrid to a latlon cube and then collapse, this introduces an additional step to the process. Instead, it is possible to simplify this into a single step by considering this as a regridding operation where the target cube contains multiple latitude bands.\n",
1389+
"\n",
1390+
"A zonal mean is the area weighted average over a defined region or sequence of regions. e.g. a band of latitude/longitude.\n",
1391+
"Calculating zonal means can be done as a regridding operation where the zone is defined by the target cube. This can involve a target cube with a single cell or, as in this example, a number of cells along the latitude dimension.\n",
12721392
"\n",
1273-
"**Step 1:** Define a latitude coordinate whose bounds are `[[-20, 20]]`. Remember to set the standard name to be `\"latitude\"` and the units to be `\"degrees\"`"
1393+
"**Step 1:** Define a latitude coordinate whose bounds are `[[-90, -60], [-60, -30], [-30, 0], [0, 30], [30, 60], [60, 90]]`. Remember to set the standard name to be `\"latitude\"` and the units to be `\"degrees\"`"
12741394
]
12751395
},
12761396
{
12771397
"cell_type": "code",
1278-
"execution_count": 20,
1398+
"execution_count": 30,
12791399
"id": "4671d53e-d4ae-42b4-9608-7bd416a8d1eb",
12801400
"metadata": {},
12811401
"outputs": [],
12821402
"source": [
1283-
"lat_band = DimCoord(0, bounds=[[-20, 20]], standard_name=\"latitude\", units=\"degrees\")\n"
1403+
"lat_bands = DimCoord(\n",
1404+
" [-75, -45, -15, 15, 45, 75],\n",
1405+
" bounds=[[-90, -60], [-60, -30], [-30, 0], [0, 30], [30, 60], [60, 90]],\n",
1406+
" standard_name=\"latitude\",\n",
1407+
" units=\"degrees\"\n",
1408+
")"
12841409
]
12851410
},
12861411
{
@@ -1293,7 +1418,7 @@
12931418
},
12941419
{
12951420
"cell_type": "code",
1296-
"execution_count": 21,
1421+
"execution_count": 31,
12971422
"id": "e0eb804f-737a-4b6c-a469-6917e2b27087",
12981423
"metadata": {},
12991424
"outputs": [],
@@ -1311,25 +1436,25 @@
13111436
},
13121437
{
13131438
"cell_type": "code",
1314-
"execution_count": 22,
1439+
"execution_count": 33,
13151440
"id": "6a358122-28c7-4276-90b6-9427f38cbf3c",
13161441
"metadata": {},
13171442
"outputs": [
13181443
{
13191444
"name": "stdout",
13201445
"output_type": "stream",
13211446
"text": [
1322-
"unknown / (unknown) (latitude: 1; longitude: 1)\n",
1447+
"unknown / (unknown) (longitude: 1; latitude: 6)\n",
13231448
" Dimension coordinates:\n",
1324-
" latitude x -\n",
1325-
" longitude - x\n"
1449+
" longitude x -\n",
1450+
" latitude - x\n"
13261451
]
13271452
}
13281453
],
13291454
"source": [
1330-
"lat_band_cube = Cube([[0]])\n",
1331-
"lat_band_cube.add_dim_coord(lat_band, 0)\n",
1332-
"lat_band_cube.add_dim_coord(lon_full, 1)\n",
1455+
"lat_band_cube = Cube([[0, 0, 0, 0, 0, 0]])\n",
1456+
"lat_band_cube.add_dim_coord(lat_bands, 1)\n",
1457+
"lat_band_cube.add_dim_coord(lon_full, 0)\n",
13331458
"print(lat_band_cube)"
13341459
]
13351460
},
@@ -1349,7 +1474,7 @@
13491474
},
13501475
{
13511476
"cell_type": "code",
1352-
"execution_count": 23,
1477+
"execution_count": 34,
13531478
"id": "3c629318-c076-44ee-86b2-10188d5d5067",
13541479
"metadata": {},
13551480
"outputs": [],
@@ -1367,15 +1492,20 @@
13671492
},
13681493
{
13691494
"cell_type": "code",
1370-
"execution_count": 24,
1495+
"execution_count": 35,
13711496
"id": "8a7a5d23-0ce6-4673-a227-25f30e96e357",
13721497
"metadata": {},
13731498
"outputs": [
13741499
{
13751500
"name": "stdout",
13761501
"output_type": "stream",
13771502
"text": [
1378-
"[[132.29930129838036]]\n"
1503+
"[[834.3404501938949]\n",
1504+
" [22.911713801134844]\n",
1505+
" [144.84938200705713]\n",
1506+
" [173.82307542995312]\n",
1507+
" [419.66049216165635]\n",
1508+
" [267.17610202883344]]\n"
13791509
]
13801510
}
13811511
],
@@ -1396,15 +1526,20 @@
13961526
},
13971527
{
13981528
"cell_type": "code",
1399-
"execution_count": 25,
1529+
"execution_count": 36,
14001530
"id": "77220820-6d30-430f-bf91-e563e5311a85",
14011531
"metadata": {},
14021532
"outputs": [
14031533
{
14041534
"name": "stdout",
14051535
"output_type": "stream",
14061536
"text": [
1407-
"[[131.4283200362707]]\n"
1537+
"[[790.6355533520023]\n",
1538+
" [25.988278381067268]\n",
1539+
" [145.97213673743698]\n",
1540+
" [163.82279492506785]\n",
1541+
" [428.4158694964161]\n",
1542+
" [265.59292488249076]]\n"
14081543
]
14091544
}
14101545
],
@@ -1426,7 +1561,7 @@
14261561
},
14271562
{
14281563
"cell_type": "code",
1429-
"execution_count": 26,
1564+
"execution_count": 37,
14301565
"id": "fae1a8d7-7e23-4dc6-80e8-f7e864866b10",
14311566
"metadata": {},
14321567
"outputs": [

0 commit comments

Comments
 (0)