Skip to content

Commit 79d5d36

Browse files
committed
Exercises added for the summer school
1 parent 4557ee8 commit 79d5d36

31 files changed

Lines changed: 3419 additions & 66 deletions

demo/Exercise_1.ipynb

Lines changed: 588 additions & 0 deletions
Large diffs are not rendered by default.

demo/Exercise_2.ipynb

Lines changed: 358 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "582137f7-99f1-476b-8f7d-c11c8ddfb3df",
6+
"metadata": {
7+
"editable": true,
8+
"slideshow": {
9+
"slide_type": ""
10+
},
11+
"tags": []
12+
},
13+
"source": [
14+
"# Practial exercises with PyGLDA toolbox\n",
15+
"---\n",
16+
"Edited by Fan Yang (fany@plan.aau.dk) and all other members from AAU geodesy group. This document is dedicated to the summer school held by Geodesy Group, Aalborg University, Denmark. This can be used as a quick start of the PyGLDA toolbox.\n",
17+
"\n",
18+
"**Notice**: please makre sure that this notebook is opened under the environment of **pyglda**, following these steps: navigate to the '../PyGLDA/demo/..', open a terminal and type\n",
19+
"> conda activate pyglda\n",
20+
"> \n",
21+
"> pip install jupyterlab\n",
22+
"> \n",
23+
"> jupiter lab\n",
24+
"---\n",
25+
"\n",
26+
"# Exercise-2\n",
27+
"The task is to test the impact of choosing differeng GRACE solutions: the options are GRACE-SH and GRACE-Mascon solution.\n",
28+
"\n",
29+
"---"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"id": "7bac2765-a127-4f93-b83e-b839cec16a2c",
35+
"metadata": {},
36+
"source": [
37+
"\n",
38+
"## 1. Load the default settings"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 1,
44+
"id": "797c93af-0638-4464-97ca-d60c6d421374",
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"data": {
49+
"text/plain": [
50+
"{'basin': 'Brahmaputra3subbasins',\n",
51+
" 'shp_path': '../data/basin/shp/Brahmaputra/Brahmaputra3subbasins_subbasins.shp',\n",
52+
" 'case': 'Exercise_2',\n",
53+
" 'setting_dir': '../settings/SummerSchool/Exercise_2',\n",
54+
" 'ens': 10,\n",
55+
" 'cold_begin_time': '2004-10-01',\n",
56+
" 'cold_end_time': '2004-12-31',\n",
57+
" 'warm_begin_time': '2005-01-01',\n",
58+
" 'warm_end_time': '2005-12-31',\n",
59+
" 'resume_begin_time': '2005-02-01',\n",
60+
" 'resume_end_time': '2005-12-31',\n",
61+
" 'external_data_path': '/media/user/My Book/Fan/SummerSchool/External Data',\n",
62+
" 'res_output': '/media/user/My Book/Fan/SummerSchool/External Data/w3ra/res',\n",
63+
" 'figure_output': '/media/user/My Book/Fan/SummerSchool/External Data/w3ra/figure'}"
64+
]
65+
},
66+
"execution_count": 1,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"from demo_summer_school import RDA, load_main_configuration_parameters,save_main_configuration_parameters\n",
73+
"load_main_configuration_parameters()"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"id": "d6ea2ac2-ed0d-432a-b74b-f9746c88ffcc",
79+
"metadata": {},
80+
"source": [
81+
"## 2. Preview of the setting file that controls the observation "
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": 2,
87+
"id": "7551a42b-7858-404d-a6a3-69e586502ec9",
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"data": {
92+
"text/plain": [
93+
"{'EWH_grid_dir': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/signal_Mascon',\n",
94+
" 'cov_dir': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/sample_DDK3',\n",
95+
" 'preprocess_res': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/output/',\n",
96+
" 'OL_mean': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/OLmean',\n",
97+
" 'aux_for_time_epochs': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/signal_Mascon',\n",
98+
" 'kind': 'Mascon_monthly'}"
99+
]
100+
},
101+
"execution_count": 2,
102+
"metadata": {},
103+
"output_type": "execute_result"
104+
}
105+
],
106+
"source": [
107+
"RDA.setting_dir = '../settings/SummerSchool/Exercise_2'\n",
108+
"import json\n",
109+
"from pathlib import Path\n",
110+
"\n",
111+
"## GRACE-MASCON\n",
112+
"config_mascon= json.load(open(Path(RDA.setting_dir)/'DA_setting_Mascon.json', 'r'))\n",
113+
"config_mascon['obs']['GRACE']"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 3,
119+
"id": "d897b8f7-37a9-4348-834a-350f5bacad32",
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"data": {
124+
"text/plain": [
125+
"{'EWH_grid_dir': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/signal_DDK3',\n",
126+
" 'cov_dir': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/sample_DDK3',\n",
127+
" 'preprocess_res': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/output/',\n",
128+
" 'OL_mean': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/OLmean',\n",
129+
" 'aux_for_time_epochs': '/media/user/My Book/Fan/SummerSchool/External Data/GRACE/SaGEA/signal_DDK3',\n",
130+
" 'kind': 'SH_monthly'}"
131+
]
132+
},
133+
"execution_count": 3,
134+
"metadata": {},
135+
"output_type": "execute_result"
136+
}
137+
],
138+
"source": [
139+
"## GRACE-SH\n",
140+
"config_SH= json.load(open(Path(RDA.setting_dir)/'DA_setting_SH.json', 'r'))\n",
141+
"config_SH['obs']['GRACE']"
142+
]
143+
},
144+
{
145+
"cell_type": "markdown",
146+
"id": "e9a30534-6f34-41b8-8787-d51088c60300",
147+
"metadata": {},
148+
"source": [
149+
"## 3. Make your choice of GRACE solution"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 4,
155+
"id": "126bc976-6970-49bf-8e99-84d9f432a7d8",
156+
"metadata": {},
157+
"outputs": [
158+
{
159+
"data": {
160+
"text/plain": [
161+
"{'basin': 'Brahmaputra3subbasins',\n",
162+
" 'shp_path': '../data/basin/shp/Brahmaputra/Brahmaputra3subbasins_subbasins.shp',\n",
163+
" 'case': 'Exercise_2',\n",
164+
" 'setting_dir': '../settings/SummerSchool/Exercise_2',\n",
165+
" 'ens': 10,\n",
166+
" 'cold_begin_time': '2004-10-01',\n",
167+
" 'cold_end_time': '2004-12-31',\n",
168+
" 'warm_begin_time': '2005-01-01',\n",
169+
" 'warm_end_time': '2005-12-31',\n",
170+
" 'resume_begin_time': '2005-02-01',\n",
171+
" 'resume_end_time': '2005-12-31',\n",
172+
" 'external_data_path': '/media/user/My Book/Fan/SummerSchool/External Data',\n",
173+
" 'res_output': '/media/user/My Book/Fan/SummerSchool/External Data/w3ra/res',\n",
174+
" 'figure_output': '/media/user/My Book/Fan/SummerSchool/External Data/w3ra/figure'}"
175+
]
176+
},
177+
"execution_count": 4,
178+
"metadata": {},
179+
"output_type": "execute_result"
180+
}
181+
],
182+
"source": [
183+
"### modify the settings and save to the json###\n",
184+
"config = config_mascon\n",
185+
"# config = config_SH\n",
186+
"with open(Path(RDA.setting_dir)/'DA_setting.json', 'w') as f:\n",
187+
" json.dump(config, f, indent=4)\n",
188+
"\n",
189+
"### start a new case study to avoid confusion ###\n",
190+
"RDA.case= 'Exercise_2'\n",
191+
"save_main_configuration_parameters()"
192+
]
193+
},
194+
{
195+
"cell_type": "markdown",
196+
"id": "be9586ef-8afd-4acc-814f-b90302601edd",
197+
"metadata": {},
198+
"source": [
199+
"## 4. Re-generate GRACE data"
200+
]
201+
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": 5,
205+
"id": "af9640ba-62ec-4a8a-bd41-a5135c8145dd",
206+
"metadata": {},
207+
"outputs": [
208+
{
209+
"name": "stdout",
210+
"output_type": "stream",
211+
"text": [
212+
"Start to pre-process GRACE to obtain basin-wise TWS over places of interest...\n",
213+
"2005-01\n",
214+
"2005-02\n",
215+
"2005-03\n",
216+
"2005-04\n",
217+
"2005-05\n",
218+
"2005-06\n",
219+
"2005-07\n",
220+
"2005-08\n",
221+
"2005-09\n",
222+
"2005-10\n",
223+
"2005-11\n",
224+
"2005-12\n",
225+
"Finished: 2025-08-18 15:31:33\n",
226+
"Start to pre-process GRACE to obtain grid-wise TWS over places of interest...\n",
227+
"2005-01\n",
228+
"2005-02\n",
229+
"2005-03\n",
230+
"2005-04\n",
231+
"2005-05\n",
232+
"2005-06\n",
233+
"2005-07\n",
234+
"2005-08\n",
235+
"2005-09\n",
236+
"2005-10\n",
237+
"2005-11\n",
238+
"2005-12\n",
239+
"Finished: 2025-08-18 15:31:34\n",
240+
"\n",
241+
"Start to pre-process GRACE to obtain COV over places of interest...\n",
242+
"2005-01_0.npy\n",
243+
"2005-02_0.npy\n",
244+
"2005-03_0.npy\n",
245+
"2005-04_0.npy\n",
246+
"2005-05_0.npy\n",
247+
"2005-06_0.npy\n",
248+
"2005-07_0.npy\n",
249+
"2005-08_0.npy\n",
250+
"2005-09_0.npy\n",
251+
"2005-10_0.npy\n",
252+
"2005-11_0.npy\n",
253+
"2005-12_0.npy\n",
254+
"Finished: 2025-08-18 15:31:46\n"
255+
]
256+
}
257+
],
258+
"source": [
259+
"from demo_summer_school import demo_prepare_GRACE_Mascon, demo_prepare_GRACE\n",
260+
"if config['obs']['GRACE']['kind'] == 'Mascon_monthly':\n",
261+
" demo_prepare_GRACE_Mascon(isDiagonal=False)\n",
262+
"elif config['obs']['GRACE']['kind'] == 'SH_monthly':\n",
263+
" demo_prepare_GRACE(isDiagonal=False)"
264+
]
265+
},
266+
{
267+
"cell_type": "markdown",
268+
"id": "50f6ebc1-b046-49cd-bae1-840ded558287",
269+
"metadata": {},
270+
"source": [
271+
"## 4. Perform the open loop and data assimilation"
272+
]
273+
},
274+
{
275+
"cell_type": "code",
276+
"execution_count": 6,
277+
"id": "1b0d2d71-a74f-437d-8a71-1bf4850416a5",
278+
"metadata": {},
279+
"outputs": [
280+
{
281+
"name": "stdout",
282+
"output_type": "stream",
283+
"text": [
284+
"\n",
285+
"Configuring W3v2 run\n",
286+
"Spatial resolution: 0.1\n",
287+
"Area: lat- [31.2, 21.8], lon- [87.8, 97.7]\n",
288+
"Forcing field: ERA5\n",
289+
"\n",
290+
"Initializing model states: cold\n",
291+
"Guess cold states.\n",
292+
"Spin up run for 2004-10-01 to 2004-12-31 (92 days)\n",
293+
"\n",
294+
"===== RUN from 2004-10-01 to 2004-12-31 =====\n",
295+
"\n",
296+
"Doing year/month 200410\n",
297+
"...............................\n",
298+
"Doing year/month 200411\n",
299+
"..............................\n",
300+
"Doing year/month 200412\n",
301+
"...............................\n",
302+
"Finished\n",
303+
"\n",
304+
"Configuring W3v2 run\n",
305+
"Spatial resolution: 0.1\n",
306+
"Area: lat- [31.2, 21.8], lon- [87.8, 97.7]\n",
307+
"Forcing field: ERA5\n",
308+
"/bin/bash: line 1: mpiexec: command not found\n",
309+
"/bin/bash: line 1: mpiexec: command not found\n"
310+
]
311+
}
312+
],
313+
"source": [
314+
"RDA.single_run()\n",
315+
"!mpiexec -n 11 python -u demo_summer_school.py OL\n",
316+
"!mpiexec -n 11 python -u demo_summer_school.py DA"
317+
]
318+
},
319+
{
320+
"cell_type": "markdown",
321+
"id": "824037c9-67d4-45ff-b0a0-9df8584adfa5",
322+
"metadata": {},
323+
"source": [
324+
"---\n",
325+
"### 5. Please go to another notebook for the visualization ==> **Visualization.ipynb**"
326+
]
327+
},
328+
{
329+
"cell_type": "code",
330+
"execution_count": null,
331+
"id": "776a052d-be0e-487d-b2d5-e0f83cbc4c3b",
332+
"metadata": {},
333+
"outputs": [],
334+
"source": []
335+
}
336+
],
337+
"metadata": {
338+
"kernelspec": {
339+
"display_name": "Python 3 (ipykernel)",
340+
"language": "python",
341+
"name": "python3"
342+
},
343+
"language_info": {
344+
"codemirror_mode": {
345+
"name": "ipython",
346+
"version": 3
347+
},
348+
"file_extension": ".py",
349+
"mimetype": "text/x-python",
350+
"name": "python",
351+
"nbconvert_exporter": "python",
352+
"pygments_lexer": "ipython3",
353+
"version": "3.10.12"
354+
}
355+
},
356+
"nbformat": 4,
357+
"nbformat_minor": 5
358+
}

0 commit comments

Comments
 (0)