|
24 | 24 | "import iris\n", |
25 | 25 | "from iris import load, load_cube\n", |
26 | 26 | "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" |
29 | 28 | ] |
30 | 29 | }, |
31 | 30 | { |
|
375 | 374 | }, |
376 | 375 | { |
377 | 376 | "cell_type": "code", |
378 | | - "execution_count": 6, |
| 377 | + "execution_count": 29, |
379 | 378 | "id": "fb72ce6d-0724-45da-a4d1-b004b6ce6bb5", |
380 | 379 | "metadata": {}, |
381 | 380 | "outputs": [], |
|
396 | 395 | }, |
397 | 396 | { |
398 | 397 | "cell_type": "code", |
399 | | - "execution_count": 7, |
| 398 | + "execution_count": 28, |
400 | 399 | "id": "c6d9036e-6c44-4926-a85f-bacd18fe37e1", |
401 | 400 | "metadata": {}, |
402 | 401 | "outputs": [ |
403 | 402 | { |
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\">'CF-1.7'</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\">'Created by xios'</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\">'6 h'</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\">'6 h'</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\">'instant'</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\">'Created by xios'</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" |
425 | 544 | } |
426 | 545 | ], |
427 | 546 | "source": [ |
428 | 547 | "# Regrid the mesh cube.\n", |
429 | 548 | "result = regridder(mesh_cube)\n", |
430 | | - "print(result)" |
| 549 | + "result" |
431 | 550 | ] |
432 | 551 | }, |
433 | 552 | { |
|
1266 | 1385 | "source": [ |
1267 | 1386 | "## Exercise 2: Zonal means\n", |
1268 | 1387 | "\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", |
1272 | 1392 | "\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\"`" |
1274 | 1394 | ] |
1275 | 1395 | }, |
1276 | 1396 | { |
1277 | 1397 | "cell_type": "code", |
1278 | | - "execution_count": 20, |
| 1398 | + "execution_count": 30, |
1279 | 1399 | "id": "4671d53e-d4ae-42b4-9608-7bd416a8d1eb", |
1280 | 1400 | "metadata": {}, |
1281 | 1401 | "outputs": [], |
1282 | 1402 | "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 | + ")" |
1284 | 1409 | ] |
1285 | 1410 | }, |
1286 | 1411 | { |
|
1293 | 1418 | }, |
1294 | 1419 | { |
1295 | 1420 | "cell_type": "code", |
1296 | | - "execution_count": 21, |
| 1421 | + "execution_count": 31, |
1297 | 1422 | "id": "e0eb804f-737a-4b6c-a469-6917e2b27087", |
1298 | 1423 | "metadata": {}, |
1299 | 1424 | "outputs": [], |
|
1311 | 1436 | }, |
1312 | 1437 | { |
1313 | 1438 | "cell_type": "code", |
1314 | | - "execution_count": 22, |
| 1439 | + "execution_count": 33, |
1315 | 1440 | "id": "6a358122-28c7-4276-90b6-9427f38cbf3c", |
1316 | 1441 | "metadata": {}, |
1317 | 1442 | "outputs": [ |
1318 | 1443 | { |
1319 | 1444 | "name": "stdout", |
1320 | 1445 | "output_type": "stream", |
1321 | 1446 | "text": [ |
1322 | | - "unknown / (unknown) (latitude: 1; longitude: 1)\n", |
| 1447 | + "unknown / (unknown) (longitude: 1; latitude: 6)\n", |
1323 | 1448 | " Dimension coordinates:\n", |
1324 | | - " latitude x -\n", |
1325 | | - " longitude - x\n" |
| 1449 | + " longitude x -\n", |
| 1450 | + " latitude - x\n" |
1326 | 1451 | ] |
1327 | 1452 | } |
1328 | 1453 | ], |
1329 | 1454 | "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", |
1333 | 1458 | "print(lat_band_cube)" |
1334 | 1459 | ] |
1335 | 1460 | }, |
|
1349 | 1474 | }, |
1350 | 1475 | { |
1351 | 1476 | "cell_type": "code", |
1352 | | - "execution_count": 23, |
| 1477 | + "execution_count": 34, |
1353 | 1478 | "id": "3c629318-c076-44ee-86b2-10188d5d5067", |
1354 | 1479 | "metadata": {}, |
1355 | 1480 | "outputs": [], |
|
1367 | 1492 | }, |
1368 | 1493 | { |
1369 | 1494 | "cell_type": "code", |
1370 | | - "execution_count": 24, |
| 1495 | + "execution_count": 35, |
1371 | 1496 | "id": "8a7a5d23-0ce6-4673-a227-25f30e96e357", |
1372 | 1497 | "metadata": {}, |
1373 | 1498 | "outputs": [ |
1374 | 1499 | { |
1375 | 1500 | "name": "stdout", |
1376 | 1501 | "output_type": "stream", |
1377 | 1502 | "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" |
1379 | 1509 | ] |
1380 | 1510 | } |
1381 | 1511 | ], |
|
1396 | 1526 | }, |
1397 | 1527 | { |
1398 | 1528 | "cell_type": "code", |
1399 | | - "execution_count": 25, |
| 1529 | + "execution_count": 36, |
1400 | 1530 | "id": "77220820-6d30-430f-bf91-e563e5311a85", |
1401 | 1531 | "metadata": {}, |
1402 | 1532 | "outputs": [ |
1403 | 1533 | { |
1404 | 1534 | "name": "stdout", |
1405 | 1535 | "output_type": "stream", |
1406 | 1536 | "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" |
1408 | 1543 | ] |
1409 | 1544 | } |
1410 | 1545 | ], |
|
1426 | 1561 | }, |
1427 | 1562 | { |
1428 | 1563 | "cell_type": "code", |
1429 | | - "execution_count": 26, |
| 1564 | + "execution_count": 37, |
1430 | 1565 | "id": "fae1a8d7-7e23-4dc6-80e8-f7e864866b10", |
1431 | 1566 | "metadata": {}, |
1432 | 1567 | "outputs": [ |
|
0 commit comments