Skip to content

Commit

Permalink
update Application_Template_ERA5.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
aurghs committed Oct 24, 2022
1 parent 7e6827c commit 83bf925
Showing 1 changed file with 58 additions and 38 deletions.
96 changes: 58 additions & 38 deletions notebooks/Application_Template_ERA5.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"id": "ae8bf7b2",
"metadata": {},
"source": [
"## APPLICATION TEMPLATE ERA5 - DAILY MEAN TEMPERATURE"
"## APPLICATION TEMPLATE ERA5 - GLOBAL DAILY MEAN TEMPERATURE\n",
"\n",
"package c3s-eqc-toolbox-template (https://github.com/bopen/c3s-eqc-toolbox-template)"
]
},
{
Expand All @@ -15,47 +17,43 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import plotly.express as px\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"import cacholote\n",
"import cads_toolbox \n",
"import c3s_eqc_toolbox_template\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "367e0267",
"metadata": {},
"outputs": [],
"source": [
"cacholote.config.SETTINGS"
]
},
{
"cell_type": "markdown",
"id": "fa7aecc6",
"id": "e5413ab8",
"metadata": {},
"source": [
"### PROCESSING with Xarray: GLOBAL DAILY MEAN TEMPERATURE 2021-2022 "
]
},
{
"cell_type": "markdown",
"id": "13fbe2c7",
"id": "e4c6c63a",
"metadata": {},
"source": [
"APPLICATION SUMMARY:\n",
"\n",
" - DATA REQUESTS DEFINITION\n",
" - CHUNKED DOWNLOAD and PROCESSING\n",
" - RESULT PLOT"
" - Data requests definition\n",
" \n",
" \n",
" - Processing: \n",
" - chunked download\n",
" - apply tranformation to each chunk\n",
" - chache the result on each chunk\n",
" - merge all the chunks\n",
"\n",
"\n",
" - Plot the result"
]
},
{
Expand All @@ -68,7 +66,7 @@
},
{
"cell_type": "markdown",
"id": "45f70dac",
"id": "29a64fdc",
"metadata": {},
"source": [
"For request definition we use **`c3s_eqc_toolbox_template.update_request_date`**.\n",
Expand All @@ -83,7 +81,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "28634d95",
"id": "b85e649b",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -98,13 +96,13 @@
" 'variable': '2m_temperature',\n",
"}\n",
"start = \"2021-06\"\n",
"stop = \"2022-06\""
"stop = None # \"2022-06\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eddef45a",
"id": "9bac51ad",
"metadata": {
"scrolled": false
},
Expand All @@ -116,19 +114,21 @@
},
{
"cell_type": "markdown",
"id": "d0c15202",
"id": "a168702f",
"metadata": {},
"source": [
"#### DOWNLOAD and PROCESSING"
]
},
{
"cell_type": "markdown",
"id": "cf0ef08d",
"id": "df75d54b",
"metadata": {},
"source": [
"The processing will be perform as follows:\n",
"\n",
"**Definition of the transformation `f`** to be applied to each single chunk\n",
"\n",
"**Chunk definition**: define how to chunk the request along time dimension (year, month, day): \n",
"e.g. `chunks={\"year\": 1,\"month\": 1}`\n",
"\n",
Expand All @@ -148,7 +148,7 @@
"id": "72a0d2f2",
"metadata": {},
"source": [
"#### Define operation to be applied to each single chunk"
"#### Define `f`"
]
},
{
Expand All @@ -163,6 +163,24 @@
" return ds.resample(time=\"1D\").mean(\"time\")"
]
},
{
"cell_type": "markdown",
"id": "72330a8c",
"metadata": {},
"source": [
"#### Define `chunks`"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "df6b9ee6",
"metadata": {},
"outputs": [],
"source": [
"chunks={\"year\": 1,\"month\": 1}"
]
},
{
"cell_type": "markdown",
"id": "dcf105d9",
Expand All @@ -174,7 +192,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "32dc0d53",
"id": "d5a60b98",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -191,7 +209,7 @@
"outputs": [],
"source": [
"daily_global_t2m = c3s_eqc_toolbox_template.download_and_transform(\n",
" collection_id, requests, chunks={\"year\": 1,\"month\": 1}, f=spatial_daily_mean, open_with=\"xarray\",\n",
" collection_id, requests, chunks=chunks, f=spatial_daily_mean, open_with=\"xarray\",\n",
")\n",
"\n",
"daily_global_t2m"
Expand Down Expand Up @@ -239,15 +257,17 @@
},
{
"cell_type": "markdown",
"id": "652e11de",
"id": "1c22a70e",
"metadata": {},
"source": [
"### PROCESSING with pandas: DAILY MEAN TEMPERATURE ON ROME 2021-2022 "
"<hr style=\"border:2px solid gray\">\n",
"\n",
"## Example using pandas: DAILY MEAN TEMPERATURE ON ROME 2021-2022"
]
},
{
"cell_type": "markdown",
"id": "840a7ed0",
"id": "8e6a83c9",
"metadata": {},
"source": [
"#### Define operation to be applied to each single chunk"
Expand All @@ -256,7 +276,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d08a3332",
"id": "f0563c75",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -269,16 +289,16 @@
},
{
"cell_type": "markdown",
"id": "c0919822",
"id": "2843642d",
"metadata": {},
"source": [
"#### Perform the processing"
"#### Downaload and perform the processing"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5b8fe772",
"id": "5b29b730",
"metadata": {
"scrolled": false
},
Expand All @@ -292,7 +312,7 @@
},
{
"cell_type": "markdown",
"id": "1999cb3b",
"id": "f0e983fb",
"metadata": {},
"source": [
"#### Plot result "
Expand All @@ -301,11 +321,11 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9e0b6572",
"id": "ee442826",
"metadata": {},
"outputs": [],
"source": [
"daily_global_t2m = daily_global_t2m.squeeze()\n",
"daily_global_t2m = daily_rome_t2m.squeeze()\n",
"fig = px.line(daily_rome_t2m - 273.15, y=\"t2m\")\n",
"\n",
"fig.update_layout(\n",
Expand All @@ -320,7 +340,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "cf3f4f32",
"id": "ffb0075a",
"metadata": {},
"outputs": [],
"source": [
Expand Down

0 comments on commit 83bf925

Please sign in to comment.