Skip to content

Commit 83bf925

Browse files
committed
update Application_Template_ERA5.ipynb
1 parent 7e6827c commit 83bf925

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

notebooks/Application_Template_ERA5.ipynb

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"id": "ae8bf7b2",
66
"metadata": {},
77
"source": [
8-
"## APPLICATION TEMPLATE ERA5 - DAILY MEAN TEMPERATURE"
8+
"## APPLICATION TEMPLATE ERA5 - GLOBAL DAILY MEAN TEMPERATURE\n",
9+
"\n",
10+
"package c3s-eqc-toolbox-template (https://github.com/bopen/c3s-eqc-toolbox-template)"
911
]
1012
},
1113
{
@@ -15,47 +17,43 @@
1517
"metadata": {},
1618
"outputs": [],
1719
"source": [
18-
"import numpy as np\n",
1920
"import plotly.express as px\n",
2021
"import pandas as pd\n",
2122
"import xarray as xr\n",
2223
"\n",
23-
"import cacholote\n",
2424
"import cads_toolbox \n",
2525
"import c3s_eqc_toolbox_template\n",
2626
"\n",
2727
"import warnings\n",
2828
"warnings.filterwarnings('ignore')"
2929
]
3030
},
31-
{
32-
"cell_type": "code",
33-
"execution_count": null,
34-
"id": "367e0267",
35-
"metadata": {},
36-
"outputs": [],
37-
"source": [
38-
"cacholote.config.SETTINGS"
39-
]
40-
},
4131
{
4232
"cell_type": "markdown",
43-
"id": "fa7aecc6",
33+
"id": "e5413ab8",
4434
"metadata": {},
4535
"source": [
4636
"### PROCESSING with Xarray: GLOBAL DAILY MEAN TEMPERATURE 2021-2022 "
4737
]
4838
},
4939
{
5040
"cell_type": "markdown",
51-
"id": "13fbe2c7",
41+
"id": "e4c6c63a",
5242
"metadata": {},
5343
"source": [
5444
"APPLICATION SUMMARY:\n",
5545
"\n",
56-
" - DATA REQUESTS DEFINITION\n",
57-
" - CHUNKED DOWNLOAD and PROCESSING\n",
58-
" - RESULT PLOT"
46+
" - Data requests definition\n",
47+
" \n",
48+
" \n",
49+
" - Processing: \n",
50+
" - chunked download\n",
51+
" - apply tranformation to each chunk\n",
52+
" - chache the result on each chunk\n",
53+
" - merge all the chunks\n",
54+
"\n",
55+
"\n",
56+
" - Plot the result"
5957
]
6058
},
6159
{
@@ -68,7 +66,7 @@
6866
},
6967
{
7068
"cell_type": "markdown",
71-
"id": "45f70dac",
69+
"id": "29a64fdc",
7270
"metadata": {},
7371
"source": [
7472
"For request definition we use **`c3s_eqc_toolbox_template.update_request_date`**.\n",
@@ -83,7 +81,7 @@
8381
{
8482
"cell_type": "code",
8583
"execution_count": null,
86-
"id": "28634d95",
84+
"id": "b85e649b",
8785
"metadata": {},
8886
"outputs": [],
8987
"source": [
@@ -98,13 +96,13 @@
9896
" 'variable': '2m_temperature',\n",
9997
"}\n",
10098
"start = \"2021-06\"\n",
101-
"stop = \"2022-06\""
99+
"stop = None # \"2022-06\""
102100
]
103101
},
104102
{
105103
"cell_type": "code",
106104
"execution_count": null,
107-
"id": "eddef45a",
105+
"id": "9bac51ad",
108106
"metadata": {
109107
"scrolled": false
110108
},
@@ -116,19 +114,21 @@
116114
},
117115
{
118116
"cell_type": "markdown",
119-
"id": "d0c15202",
117+
"id": "a168702f",
120118
"metadata": {},
121119
"source": [
122120
"#### DOWNLOAD and PROCESSING"
123121
]
124122
},
125123
{
126124
"cell_type": "markdown",
127-
"id": "cf0ef08d",
125+
"id": "df75d54b",
128126
"metadata": {},
129127
"source": [
130128
"The processing will be perform as follows:\n",
131129
"\n",
130+
"**Definition of the transformation `f`** to be applied to each single chunk\n",
131+
"\n",
132132
"**Chunk definition**: define how to chunk the request along time dimension (year, month, day): \n",
133133
"e.g. `chunks={\"year\": 1,\"month\": 1}`\n",
134134
"\n",
@@ -148,7 +148,7 @@
148148
"id": "72a0d2f2",
149149
"metadata": {},
150150
"source": [
151-
"#### Define operation to be applied to each single chunk"
151+
"#### Define `f`"
152152
]
153153
},
154154
{
@@ -163,6 +163,24 @@
163163
" return ds.resample(time=\"1D\").mean(\"time\")"
164164
]
165165
},
166+
{
167+
"cell_type": "markdown",
168+
"id": "72330a8c",
169+
"metadata": {},
170+
"source": [
171+
"#### Define `chunks`"
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": null,
177+
"id": "df6b9ee6",
178+
"metadata": {},
179+
"outputs": [],
180+
"source": [
181+
"chunks={\"year\": 1,\"month\": 1}"
182+
]
183+
},
166184
{
167185
"cell_type": "markdown",
168186
"id": "dcf105d9",
@@ -174,7 +192,7 @@
174192
{
175193
"cell_type": "code",
176194
"execution_count": null,
177-
"id": "32dc0d53",
195+
"id": "d5a60b98",
178196
"metadata": {},
179197
"outputs": [],
180198
"source": [
@@ -191,7 +209,7 @@
191209
"outputs": [],
192210
"source": [
193211
"daily_global_t2m = c3s_eqc_toolbox_template.download_and_transform(\n",
194-
" collection_id, requests, chunks={\"year\": 1,\"month\": 1}, f=spatial_daily_mean, open_with=\"xarray\",\n",
212+
" collection_id, requests, chunks=chunks, f=spatial_daily_mean, open_with=\"xarray\",\n",
195213
")\n",
196214
"\n",
197215
"daily_global_t2m"
@@ -239,15 +257,17 @@
239257
},
240258
{
241259
"cell_type": "markdown",
242-
"id": "652e11de",
260+
"id": "1c22a70e",
243261
"metadata": {},
244262
"source": [
245-
"### PROCESSING with pandas: DAILY MEAN TEMPERATURE ON ROME 2021-2022 "
263+
"<hr style=\"border:2px solid gray\">\n",
264+
"\n",
265+
"## Example using pandas: DAILY MEAN TEMPERATURE ON ROME 2021-2022"
246266
]
247267
},
248268
{
249269
"cell_type": "markdown",
250-
"id": "840a7ed0",
270+
"id": "8e6a83c9",
251271
"metadata": {},
252272
"source": [
253273
"#### Define operation to be applied to each single chunk"
@@ -256,7 +276,7 @@
256276
{
257277
"cell_type": "code",
258278
"execution_count": null,
259-
"id": "d08a3332",
279+
"id": "f0563c75",
260280
"metadata": {},
261281
"outputs": [],
262282
"source": [
@@ -269,16 +289,16 @@
269289
},
270290
{
271291
"cell_type": "markdown",
272-
"id": "c0919822",
292+
"id": "2843642d",
273293
"metadata": {},
274294
"source": [
275-
"#### Perform the processing"
295+
"#### Downaload and perform the processing"
276296
]
277297
},
278298
{
279299
"cell_type": "code",
280300
"execution_count": null,
281-
"id": "5b8fe772",
301+
"id": "5b29b730",
282302
"metadata": {
283303
"scrolled": false
284304
},
@@ -292,7 +312,7 @@
292312
},
293313
{
294314
"cell_type": "markdown",
295-
"id": "1999cb3b",
315+
"id": "f0e983fb",
296316
"metadata": {},
297317
"source": [
298318
"#### Plot result "
@@ -301,11 +321,11 @@
301321
{
302322
"cell_type": "code",
303323
"execution_count": null,
304-
"id": "9e0b6572",
324+
"id": "ee442826",
305325
"metadata": {},
306326
"outputs": [],
307327
"source": [
308-
"daily_global_t2m = daily_global_t2m.squeeze()\n",
328+
"daily_global_t2m = daily_rome_t2m.squeeze()\n",
309329
"fig = px.line(daily_rome_t2m - 273.15, y=\"t2m\")\n",
310330
"\n",
311331
"fig.update_layout(\n",
@@ -320,7 +340,7 @@
320340
{
321341
"cell_type": "code",
322342
"execution_count": null,
323-
"id": "cf3f4f32",
343+
"id": "ffb0075a",
324344
"metadata": {},
325345
"outputs": [],
326346
"source": [

0 commit comments

Comments
 (0)