Skip to content

Commit 55b10a0

Browse files
authored
Merge pull request #62 from pletzer/periodicity_bug
Periodicity bug
2 parents d1f531b + 1de3c11 commit 55b10a0

File tree

10 files changed

+3262
-3061
lines changed

10 files changed

+3262
-3061
lines changed

mint/notebooks/interpVectorField.ipynb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
"cell_type": "code",
1414
"execution_count": 1,
15-
"id": "a449116e",
15+
"id": "ee28b47e",
1616
"metadata": {},
1717
"outputs": [],
1818
"source": [
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"cell_type": "markdown",
36-
"id": "467d2519",
36+
"id": "91467c81",
3737
"metadata": {},
3838
"source": [
3939
"A critical aspect of mimetic interpolation is that the interpolating functions are vectors. However, they are different for W1 and W2 fields."
@@ -46,8 +46,9 @@
4646
"metadata": {},
4747
"outputs": [],
4848
"source": [
49+
"import numpy\n",
4950
"import mint\n",
50-
"import numpy"
51+
"print(f'mint version = {mint.__version__}')"
5152
]
5253
},
5354
{
@@ -158,7 +159,7 @@
158159
},
159160
{
160161
"cell_type": "markdown",
161-
"id": "d16395c1",
162+
"id": "40554671",
162163
"metadata": {},
163164
"source": [
164165
"## Create the set of target points"
@@ -180,7 +181,7 @@
180181
},
181182
{
182183
"cell_type": "markdown",
183-
"id": "1ddf77c0",
184+
"id": "04b698aa",
184185
"metadata": {},
185186
"source": [
186187
"## Interpolate the W1 and W2 fields onto the target points"
@@ -207,7 +208,7 @@
207208
},
208209
{
209210
"cell_type": "markdown",
210-
"id": "a0375512",
211+
"id": "c38ab2e0",
211212
"metadata": {},
212213
"source": [
213214
"Below are the interpolated vector fields for W1 (top) and (W2). On the left (right), a lat-lon (Cartesian) coordinate system was used to compute the field integral along horizontal edges. Most of the differences are near the poles.\n",
@@ -264,7 +265,7 @@
264265
{
265266
"cell_type": "code",
266267
"execution_count": null,
267-
"id": "194aeebe",
268+
"id": "e699c218",
268269
"metadata": {},
269270
"outputs": [],
270271
"source": []

mint/notebooks/regridUni2LFRic.ipynb

Lines changed: 121 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "8a103633",
6+
"metadata": {},
7+
"source": [
8+
"# Mimetic regridding from lon-lat to cubed-sphere\n",
9+
"This notebook shows how to regrid/remap edge or face centred data on a lon-lat grid to cubed-sphere in a flux conservative way."
10+
]
11+
},
312
{
413
"cell_type": "code",
514
"execution_count": 1,
615
"id": "aed8b1f0",
716
"metadata": {},
8-
"outputs": [],
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"mint version = 1.19.1\n"
23+
]
24+
}
25+
],
926
"source": [
27+
"import numpy\n",
1028
"import mint\n",
11-
"import numpy"
29+
"print(f'mint version = {mint.__version__}')"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"id": "9d8ea35c",
35+
"metadata": {},
36+
"source": [
37+
"## Create a regridding instance"
1238
]
1339
},
1440
{
@@ -18,41 +44,114 @@
1844
"metadata": {},
1945
"outputs": [],
2046
"source": [
21-
"regridder = mint.RegridEdges()\n",
22-
"\n",
23-
"# grid settings\n",
24-
"regridder.setSrcGridFlags(fixLonAcrossDateline=0, averageLonAtPole=0)\n",
25-
"regridder.setDstGridFlags(fixLonAcrossDateline=1, averageLonAtPole=1)\n",
26-
"\n",
27-
"# load the grids\n",
28-
"regridder.loadSrcGrid('../../data/latlon100x50.nc$latlon')\n",
29-
"regridder.loadDstGrid('../../data/lfric_diag_wind.nc$Mesh2d')\n",
30-
"\n",
31-
"# compute the regridding weights\n",
32-
"regridder.build(numCellsPerBucket=10, periodX=360., debug=1)\n",
33-
"\n",
34-
"mint.printLogMessages()\n",
35-
"mint.writeLogMessages('log.txt')"
47+
"regridder = mint.RegridEdges()"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"id": "f0a32721",
53+
"metadata": {},
54+
"source": [
55+
"## Set the flags for the source and destination grids\n",
56+
"For the lon-lat grid we recommend $fixLonAcrossDateline=0$ and $averageLonAtPole=0$. For the cibed-sphere grid we recommend $fixLonAcrossDateline=1$ and $averageLonAtPole=1$. The first option will add and subtract 360 degrees, \n",
57+
"to reduce the length of cell edges when this cross the dateline. The second option will adjust the longitudes at the poles to make the grid compact."
3658
]
3759
},
3860
{
3961
"cell_type": "code",
40-
"execution_count": null,
41-
"id": "f3e2b8ea",
62+
"execution_count": 3,
63+
"id": "aa31f866",
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"regridder.setSrcGridFlags(fixLonAcrossDateline=0, averageLonAtPole=0) # for lon-lat\n",
68+
"regridder.setDstGridFlags(fixLonAcrossDateline=1, averageLonAtPole=1) # for cubed-sphere"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"id": "bceb9177",
74+
"metadata": {},
75+
"source": [
76+
"## Load the source and destination grids\n",
77+
"The grid are assumed to be stored in the Ugrid 2D netCDF format. Note that we need to specify the name of the grid in the file as well, as several grids ccan live inside the file. This is achieved by passing the name of the file folowwed by '$' and the name of the grid (or mesh)."
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": 4,
83+
"id": "5aacb9a7",
4284
"metadata": {},
4385
"outputs": [],
4486
"source": [
87+
"regridder.loadSrcGrid('../../data/latlon100x50.nc$latlon') # mesh name is latlon\n",
88+
"regridder.loadDstGrid('../../data/lfric_diag_wind.nc$Mesh2d') # mesh name is Mesh2d"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "4f34e4ce",
94+
"metadata": {},
95+
"source": [
96+
"## Compute the regridding weights\n",
97+
"Next we compute the weights by building the regridder. Option $debug=1$ will print all the destination edges that partially fall outside the source domain. Option $periodX$ is useful for global domains. Option $numCellsPerBucket$ sets the number of cell in each cell locator bucket. The latter affects performance only, except in the edge cases. We recommend anywhere 10-500 cells per bucket."
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 5,
103+
"id": "3e5167a3",
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"regridder.build(numCellsPerBucket=128, periodX=360., debug=1)"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"id": "503b1212",
113+
"metadata": {},
114+
"source": [
115+
"## View the log messages\n",
116+
"It's good practice to view the log messages to chak that all destination edges were found inside the source grid."
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": 6,
122+
"id": "f3e2b8ea",
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"[Thu Nov 11 16:25:19 2021 info ] src/mntRegridEdges.cpp in function mnt_regridedges_loadSrcGrid (line 468): loading src grid from file \"../../data/latlon100x50.nc$latlon\"\r\n",
130+
"[Thu Nov 11 16:25:19 2021 info ] src/mntRegridEdges.cpp in function mnt_regridedges_loadDstGrid (line 481): loading dst grid from file \"../../data/lfric_diag_wind.nc$Mesh2d\"\r\n"
131+
]
132+
}
133+
],
134+
"source": [
135+
"mint.writeLogMessages('log.txt')\n",
45136
"! cat log.txt"
46137
]
47138
},
139+
{
140+
"cell_type": "markdown",
141+
"id": "cd350ebc",
142+
"metadata": {},
143+
"source": [
144+
"## Saving the weights to file"
145+
]
146+
},
48147
{
49148
"cell_type": "code",
50-
"execution_count": null,
51-
"id": "40a78e17",
149+
"execution_count": 7,
150+
"id": "4c9bb26d",
52151
"metadata": {},
53152
"outputs": [],
54153
"source": [
55-
" "
154+
"regridder.dumpWeights('lonlat_cs_weights.nc')"
56155
]
57156
}
58157
],

0 commit comments

Comments
 (0)