From 83bf925bacd3160bbb23a95e96be824f72513c43 Mon Sep 17 00:00:00 2001 From: barghini Date: Mon, 24 Oct 2022 15:20:27 +0200 Subject: [PATCH] update Application_Template_ERA5.ipynb --- notebooks/Application_Template_ERA5.ipynb | 96 ++++++++++++++--------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/notebooks/Application_Template_ERA5.ipynb b/notebooks/Application_Template_ERA5.ipynb index b2f5015..0918a64 100644 --- a/notebooks/Application_Template_ERA5.ipynb +++ b/notebooks/Application_Template_ERA5.ipynb @@ -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)" ] }, { @@ -15,12 +17,10 @@ "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", @@ -28,19 +28,9 @@ "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 " @@ -48,14 +38,22 @@ }, { "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" ] }, { @@ -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", @@ -83,7 +81,7 @@ { "cell_type": "code", "execution_count": null, - "id": "28634d95", + "id": "b85e649b", "metadata": {}, "outputs": [], "source": [ @@ -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 }, @@ -116,7 +114,7 @@ }, { "cell_type": "markdown", - "id": "d0c15202", + "id": "a168702f", "metadata": {}, "source": [ "#### DOWNLOAD and PROCESSING" @@ -124,11 +122,13 @@ }, { "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", @@ -148,7 +148,7 @@ "id": "72a0d2f2", "metadata": {}, "source": [ - "#### Define operation to be applied to each single chunk" + "#### Define `f`" ] }, { @@ -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", @@ -174,7 +192,7 @@ { "cell_type": "code", "execution_count": null, - "id": "32dc0d53", + "id": "d5a60b98", "metadata": {}, "outputs": [], "source": [ @@ -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" @@ -239,15 +257,17 @@ }, { "cell_type": "markdown", - "id": "652e11de", + "id": "1c22a70e", "metadata": {}, "source": [ - "### PROCESSING with pandas: DAILY MEAN TEMPERATURE ON ROME 2021-2022 " + "
\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" @@ -256,7 +276,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d08a3332", + "id": "f0563c75", "metadata": {}, "outputs": [], "source": [ @@ -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 }, @@ -292,7 +312,7 @@ }, { "cell_type": "markdown", - "id": "1999cb3b", + "id": "f0e983fb", "metadata": {}, "source": [ "#### Plot result " @@ -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", @@ -320,7 +340,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cf3f4f32", + "id": "ffb0075a", "metadata": {}, "outputs": [], "source": [