You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notebooks/.notebook_shadow_copies/Sec_05_Regridding.md
+43-46Lines changed: 43 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,7 @@ jupyter:
17
17
## Set up
18
18
19
19
```python
20
-
from pathlib import Path
21
-
import numpy as np
22
-
23
20
from esmf_regrid.experimental.unstructured_scheme import MeshToGridESMFRegridder, GridToMeshESMFRegridder
24
-
import iris
25
-
from iris import load, load_cube
26
21
from iris.coords import DimCoord
27
22
from iris.cube import Cube
28
23
```
@@ -104,6 +99,7 @@ import matplotlib.pyplot as plt
104
99
from testdata_fetching import um_temp
105
100
grid_temp = um_temp()
106
101
102
+
# We slice the cube to make sure it is 2D for plotting.
107
103
iqplt.pcolormesh(grid_temp[0, 0])
108
104
plt.gca().coastlines()
109
105
plt.show()
@@ -113,11 +109,12 @@ plt.gca().coastlines()
113
109
plt.show()
114
110
```
115
111
116
-
We can then plot the difference between the UM data and the data regridded from LFRic. Since our data is now on a latlon grid we can do this with matplotlib as normal.
112
+
We can then plot the difference between the UM data and the data regridded from LFRic. Since all our data is now on a latlon grid we can subtract to find the difference between the regridded LFRic data and equivalent UM data and plot this with matplotlib as normal.
117
113
118
114
```python
119
115
temp_diff = result_2 - grid_temp
120
116
117
+
# We choose a colormap that makes it clear where the differences are.
**Step 6:** Repeat step 4 and 5 for `resolution=100`.
241
238
242
-
Note the difference in value. Also note that it takes more time to initialise a regridder with higher resolution.
239
+
Note the difference in value. Also note that it takes more time to initialise a regridder with higher resolution. Higher resolutions ought to be more accurate but there is a tradeoff between performance and accuracy.
If we have data on aditional dimensions, we can use the same approach as exercise 2 to produce a Hovmoller diagram. That is, if we have data that varies along time we can take the area weighted mean over latitude bands and plot the data aginst longitude and time (or similarly, we can plot against latitude and time).
278
-
279
-
**Step 1:** Load a temperature cube using the `testdata_fetching` function `lfric_temp`. Extract a single pressure slice using the `cube.extract` method with a constraint `iris.Constraint(pressure=850)` as the argument (we choose this level because it has noticable details).
274
+
If we have data on aditional dimensions, we can use the same approach as exercise 2 to produce a Hovmoller diagram. That is, if we have data that varies along time we can take the area weighted mean over latitude bands and plot the data aginst latitude and time (or similarly, we can plot against longitude and time).
280
275
276
+
**Step 1:** Load a cube with humidity data using the `testdata_fetching` function `lfric_rh_alltimes_3d`.
from testdata_fetching import lfric_rh_alltimes_3d
287
280
281
+
humidity_cube = lfric_rh_alltimes_3d()
282
+
humidity_cube
283
+
```
288
284
289
-
**Step 2:** Create a target cube whose longitude coordinate is derived from the UM cube loaded from `um_orography` and whose latitude coordinate has bounds `[[-180, 180]]`. This can be done by slicing a cube derived from `um_orography` (using the slice `[:1]` so that this dimension isnt collapsed), removing the latitude coordinate and adding a latitude coordinate with bounds `[[-180, 180]]` (you can reuse the coordinate from exercise 2).
285
+
**Step 2:** Create a target cube whose latitude coordinate is derived from the UM cube loaded from `um_orography` and whose longitude coordinate has bounds `[[-180, 180]]`. This can be done by slicing a cube derived from `um_orography` (using the slice `[:, :1]` so that this dimension isnt collapsed), removing the longitude coordinate and adding a longitude coordinate with bounds `[[-180, 180]]` (you can reuse the coordinate from exercise 2).
290
286
291
287
```python
292
-
target_cube_lons= grid_cube[:1]
293
-
target_cube_lons.remove_coord("latitude")
294
-
target_cube_lons.add_dim_coord(lat_full, 0)
295
-
target_cube_lons
288
+
target_cube_lats= grid_cube[:,:1]
289
+
target_cube_lats.remove_coord("longitude")
290
+
target_cube_lats.add_dim_coord(lon_full, 1)
291
+
target_cube_lats
296
292
```
297
293
298
294
```python
299
-
# We also can do the same thing for bands of constant latitude.
295
+
# We also can do the same thing for bands of constant longitude.
300
296
301
-
#target_cube_lats = grid_cube[:,:1]
302
-
#target_cube_lats.remove_coord("longitude")
303
-
#target_cube_lats.add_dim_coord(lon_full, 1)
304
-
#target_cube_lats
297
+
#target_cube_lons = grid_cube[:1]
298
+
#target_cube_lons.remove_coord("latitude")
299
+
#target_cube_lons.add_dim_coord(lat_full, 0)
300
+
#target_cube_lons
305
301
```
306
302
307
-
**Step 3:** Create a `MeshToGridESMFRegridder` regridder from the slice of the temperature cube onto the target cube. Set the resolution keyword to 2 (this should be sufficient since these are bands of constant longitude). Use this regridder to create a resulting cube.
303
+
**Step 3:** Create a `MeshToGridESMFRegridder` regridder from the slice of the humidity cube onto the target cube. Set the resolution keyword to 500 (this should be good balance of accuracy and performance). Use this regridder to create a resulting cube.
**Step 4:** Plot the data in the resulting cube. This can be done with `iqplt.pcolormesh`. Note that the resulting cube will have an unnecessary dimension which will have to be sliced (using `[:, 0]`). Note that extra steps can be taken to format the dates for this plot.
321
+
**Step 4:** Plot the data in the resulting cube. This can be done with `iqplt.pcolormesh`. Note that the resulting cube will have an unnecessary dimension which will have to be sliced (using `[:, :, 0]`). Note that extra steps can be taken to format the dates for this plot.
0 commit comments