update notebooks

This commit is contained in:
Alfredo Oliviero 2024-12-02 14:46:04 +01:00
parent 67d00b2e62
commit 39978a1c97
5 changed files with 142 additions and 1389 deletions

View File

@ -193,7 +193,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install cdsapi" "# !pip install cdsapi"
] ]
}, },
{ {

View File

@ -3,15 +3,13 @@
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": []
"# Analysis of Projected versus Historical Climatology with CORDEX Data"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### About" "# Analysis of Projected versus Historical Climatology with CORDEX Data"
] ]
}, },
{ {
@ -23,6 +21,13 @@
"CDS_PROJECT = \"03x02_projections-cordex\"" "CDS_PROJECT = \"03x02_projections-cordex\""
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### About"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -116,47 +121,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git\n",
" Cloning https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git to /private/var/folders/hc/hl1vgl493cqdfj_g7d8pggv40000gn/T/pip-req-build-fxhc4mqq\n",
" Running command git clone --filter=blob:none --quiet https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git /private/var/folders/hc/hl1vgl493cqdfj_g7d8pggv40000gn/T/pip-req-build-fxhc4mqq\n",
" warning: filtering not recognized by server, ignoring\n",
" warning: filtering not recognized by server, ignoring\n",
" Resolved https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git to commit 22ec9dd7e72830d0057adc7454aa7e864a86a23c\n",
" Preparing metadata (setup.py) ... \u001b[?25ldone\n",
"\u001b[?25hRequirement already satisfied: cdsapi>=0.7.2 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from d4science-copernicus-cds==1.0.0) (0.7.4)\n",
"Requirement already satisfied: attrs in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from d4science-copernicus-cds==1.0.0) (24.2.0)\n",
"Requirement already satisfied: typing_extensions in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from d4science-copernicus-cds==1.0.0) (4.12.2)\n",
"Requirement already satisfied: cads-api-client>=1.4.7 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (1.5.2)\n",
"Requirement already satisfied: requests>=2.5.0 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (2.32.3)\n",
"Requirement already satisfied: tqdm in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (4.67.0)\n",
"Requirement already satisfied: multiurl>=0.3.2 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cads-api-client>=1.4.7->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (0.3.2)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (2.2.3)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (3.4.0)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (3.10)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (2024.8.30)\n",
"Requirement already satisfied: python-dateutil in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (2.9.0.post0)\n",
"Requirement already satisfied: pytz in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (2024.2)\n",
"Requirement already satisfied: six>=1.5 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from python-dateutil->multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi>=0.7.2->d4science-copernicus-cds==1.0.0) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [ "source": [
"!pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git" "# !pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -165,18 +139,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"URL https://cds.climate.copernicus.eu/api\n",
"KEY db1f2085-6b8b-42e6-b832-625dfaf831a4\n"
]
}
],
"source": [ "source": [
"URL, KEY = cds_get_credentials()\n", "URL, KEY = cds_get_credentials()\n",
"print(\"URL\", URL)\n", "print(\"URL\", URL)\n",
@ -194,16 +159,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"datadir: %s /Users/Alfredo/cds_dataDir/out_2024_11_08_16_32_34_projections-cordex/\n",
"/Users/Alfredo/cds_dataDir/out_2024_11_08_16_32_34_projections-cordex/\n"
]
}
],
"source": [ "source": [
"import os\n", "import os\n",
"\n", "\n",
@ -220,7 +176,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -251,35 +207,11 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: cdsapi in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (0.7.4)\n",
"Requirement already satisfied: tqdm in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi) (4.67.0)\n",
"Requirement already satisfied: cads-api-client>=1.4.7 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi) (1.5.2)\n",
"Requirement already satisfied: requests>=2.5.0 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cdsapi) (2.32.3)\n",
"Requirement already satisfied: typing-extensions in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cads-api-client>=1.4.7->cdsapi) (4.12.2)\n",
"Requirement already satisfied: attrs in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cads-api-client>=1.4.7->cdsapi) (24.2.0)\n",
"Requirement already satisfied: multiurl>=0.3.2 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from cads-api-client>=1.4.7->cdsapi) (0.3.2)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi) (3.4.0)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi) (2.2.3)\n",
"Requirement already satisfied: idna<4,>=2.5 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi) (3.10)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from requests>=2.5.0->cdsapi) (2024.8.30)\n",
"Requirement already satisfied: python-dateutil in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi) (2.9.0.post0)\n",
"Requirement already satisfied: pytz in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi) (2024.2)\n",
"Requirement already satisfied: six>=1.5 in /Users/Alfredo/.pyenv/versions/3.10.12/lib/python3.10/site-packages (from python-dateutil->multiurl>=0.3.2->cads-api-client>=1.4.7->cdsapi) (1.16.0)\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [ "source": [
"!pip install cdsapi" "# !pip install cdsapi"
] ]
}, },
{ {
@ -291,7 +223,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -370,63 +302,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-11-08 16:32:35,536 INFO [2024-09-28T00:00:00] **Welcome to the New Climate Data Store (CDS)!** This new system is in its early days of full operations and still undergoing enhancements and fine tuning. Some disruptions are to be expected. Your \n",
"[feedback](https://jira.ecmwf.int/plugins/servlet/desk/portal/1/create/202) is key to improve the user experience on the new CDS for the benefit of everyone. Thank you.\n",
"2024-11-08 16:32:35,537 WARNING [2024-09-26T00:00:00] Should you have not yet migrated from the old CDS system to the new CDS, please check our [informative page](https://confluence.ecmwf.int/x/uINmFw) for guidance.\n",
"2024-11-08 16:32:35,537 INFO [2024-09-26T00:00:00] Watch our [Forum](https://forum.ecmwf.int/) for Announcements, news and other discussed topics.\n",
"2024-11-08 16:32:35,537 INFO [2024-09-16T00:00:00] Remember that you need to have an ECMWF account to use the new CDS. **Your old CDS credentials will not work in new CDS!**\n",
"2024-11-08 16:32:35,538 WARNING [2024-06-16T00:00:00] CDS API syntax is changed and some keys or parameter names may have also changed. To avoid requests failing, please use the \"Show API request code\" tool on the dataset Download Form to check you are using the correct syntax for your API request.\n"
]
}
],
"source": [ "source": [
"c = cdsapi.Client()" "c = cdsapi.Client()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading ../data/projections-cordex/1971-2000_cordex_historical_africa.zip\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-11-08 16:32:40,312 INFO Request ID is 3636de2e-8ccb-4f8a-a09c-b331eb536911\n",
"2024-11-08 16:32:40,958 INFO status has been updated to accepted\n",
"2024-11-08 16:32:44,906 INFO status has been updated to running\n",
"2024-11-08 16:32:47,222 INFO status has been updated to successful\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09118f68c4864e688a354f1913744d26",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"4370e553fb6d0700264d5dc2075c0fbd.zip: 0%| | 0.00/908M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"\n", "\n",
"filename_historical = os.path.join(CDS_DATA, '1971-2000_cordex_historical_africa.zip')\n", "filename_historical = os.path.join(CDS_DATA, '1971-2000_cordex_historical_africa.zip')\n",
@ -458,40 +345,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"downloading ../data/projections-cordex/2071-2100_cordex_rcp_4_5_africa.zip\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-11-08 16:35:40,398 INFO Request ID is ddb4760c-10bb-4883-ae82-1b41c053338a\n",
"2024-11-08 16:35:40,442 INFO status has been updated to accepted\n",
"2024-11-08 16:35:45,465 INFO status has been updated to running\n",
"2024-11-08 16:35:48,901 INFO status has been updated to accepted\n",
"2024-11-08 16:36:01,647 INFO status has been updated to successful\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cf3014202d04447e903c93b1e7de934e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"16922db45b157736efd0e3528b6f0922.zip: 0%| | 0.00/908M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"filename_future = os.path.join(CDS_DATA, '2071-2100_cordex_rcp_4_5_africa.zip')\n", "filename_future = os.path.join(CDS_DATA, '2071-2100_cordex_rcp_4_5_africa.zip')\n",
"\n", "\n",

View File

@ -4,7 +4,22 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Wind Chill Index with Reanalysis Data\n", "# Wind Chill Index with Reanalysis Data\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"CDS_PROJECT = \"05x01_ci-windchill\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n", "\n",
"#### About\n", "#### About\n",
"\n", "\n",
@ -58,7 +73,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git" "# !pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git"
] ]
}, },
{ {
@ -95,16 +110,6 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"import os\n", "import os\n",
"\n",
"CDS_PROJECT = \"ci-windchill \""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"DATADIR = cds_datadir(CDS_PROJECT)\n", "DATADIR = cds_datadir(CDS_PROJECT)\n",
"print(DATADIR)" "print(DATADIR)"
] ]
@ -159,7 +164,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install cdsapi" "# !pip install cdsapi"
] ]
}, },
{ {
@ -279,6 +284,14 @@
"source": [ "source": [
"\n", "\n",
"fw = os.path.join(CDS_DATA, \"UERRA_ws10m.nc\")\n", "fw = os.path.join(CDS_DATA, \"UERRA_ws10m.nc\")\n",
"\n",
"#restore execution\n",
"if not os.path.exists(fw):\n",
" pending_id = \"0a24c457-eb7c-47ae-87a3-d6973fb38adb\"\n",
" print (\"trying to resume\", pending_id)\n",
" \n",
" c.client.download_results(pending_id, fw)\n",
"\n",
"if not os.path.exists(fw):\n", "if not os.path.exists(fw):\n",
" print(\"Downloading data\", fw)\n", " print(\"Downloading data\", fw)\n",
" c.retrieve(\n", " c.retrieve(\n",
@ -305,7 +318,7 @@
" },\n", " },\n",
" fw)\n", " fw)\n",
"else:\n", "else:\n",
" print(\"File exists\", filename_ws10m)" " print(\"File exists\", fw)"
] ]
}, },
{ {
@ -341,9 +354,9 @@
" 'time': '06:00',\n", " 'time': '06:00',\n",
" 'data_format': 'netcdf_legacy',\n", " 'data_format': 'netcdf_legacy',\n",
" },\n", " },\n",
" filename_t2m)\n", " ft)\n",
"else:\n", "else:\n",
" print(\"File exists\", filename_t2m)" " print(\"File exists\", ft)"
] ]
}, },
{ {
@ -619,7 +632,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.5" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -8,6 +8,17 @@
"# Sorting pre-requisits for ibicus: downloading and preprocessing data" "# Sorting pre-requisits for ibicus: downloading and preprocessing data"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "4d227eed",
"metadata": {},
"outputs": [],
"source": [
"\n",
"CDS_PROJECT = \"06x00_data_download_and_preprocessing\""
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "46c1c6de", "id": "46c1c6de",
@ -57,7 +68,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"!pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git" "# !pip install git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git"
] ]
}, },
{ {
@ -90,6 +101,16 @@
"---" "---"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "fa0848be",
"metadata": {},
"outputs": [],
"source": [
"# !pip install scitools-iris"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -127,22 +148,12 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "4d227eed", "id": "0701fcf7",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import os\n", "import os\n",
"\n", "\n",
"CDS_PROJECT = \"data_download_and_preprocessing\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0701fcf7",
"metadata": {},
"outputs": [],
"source": [
"DATADIR = cds_datadir(CDS_PROJECT)\n", "DATADIR = cds_datadir(CDS_PROJECT)\n",
"print(DATADIR)" "print(DATADIR)"
] ]
@ -250,9 +261,18 @@
"\n", "\n",
"# choose a historical period to extract\n", "# choose a historical period to extract\n",
"period_hist = '1979-01-01/2005-12-31' \n", "period_hist = '1979-01-01/2005-12-31' \n",
"start_year_hist = 1979\n",
"end_year_hist = 2005\n",
"years_hist = [str(year) for year in range(start_year_hist, end_year_hist+1)]\n",
"\n", "\n",
"# choose a future period to extract:\n", "# choose a future period to extract:\n",
"period_fut = '2050-01-01/2070-12-31'\n", "period_fut = '2050-01-01/2070-12-31'\n",
"start_year_fut = 2050\n",
"end_year_fut = 2070\n",
"years_fut = [str(year) for year in range(start_year_fut, end_year_fut+1)]\n",
"\n",
"months = [str(month).zfill(2) for month in range(1, 13)]\n",
"\n",
"\n", "\n",
"# choose a filename for the historical cm data\n", "# choose a filename for the historical cm data\n",
"fname_cm_hist = f\"cmip6_daily_1979-2015_ipsl_historical_{variable}.zip\"\n", "fname_cm_hist = f\"cmip6_daily_1979-2015_ipsl_historical_{variable}.zip\"\n",
@ -295,8 +315,20 @@
"source": [ "source": [
"# download historical climate model data\n", "# download historical climate model data\n",
"\n", "\n",
"c = cdsapi.Client(url=URL, key=KEY)\n", "c = cdsapi.Client()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d673417",
"metadata": {},
"outputs": [],
"source": [
"zipfile_fname_cm_hist = os.path.join(CDS_DATA, fname_cm_hist)\n",
"\n", "\n",
"if not os.exists(zipfile_fname_cm_hist):\n",
" print(f\"Downloading {zipfile_fname_cm_hist}\")\n",
" c.retrieve(\n", " c.retrieve(\n",
" 'projections-cmip6',\n", " 'projections-cmip6',\n",
" {\n", " {\n",
@ -305,11 +337,15 @@
" 'level': 'single_levels',\n", " 'level': 'single_levels',\n",
" 'variable': variable,\n", " 'variable': variable,\n",
" 'model': model,\n", " 'model': model,\n",
" 'date': period_hist,\n", " # 'date': period_hist,\n",
" 'year': years_hist,\n",
" 'month': months,\n",
" 'area': area,\n", " 'area': area,\n",
" 'format': 'zip',\n", " 'format': 'zip',\n",
" },\n", " },\n",
" f'{DATADIR}/{fname_cm_hist}')" " zipfile_fname_cm_hist)\n",
"else:\n",
" print(f\"File {zipfile_fname_cm_hist} already exists\")"
] ]
}, },
{ {
@ -329,7 +365,7 @@
"source": [ "source": [
"import zipfile\n", "import zipfile\n",
"\n", "\n",
"with zipfile.ZipFile(f'{DATADIR}/{fname_cm_hist}', 'r') as zip_ref:\n", "with zipfile.ZipFile(zipfile_fname_cm_hist, 'r') as zip_ref:\n",
" zip_ref.extractall(DATADIR)" " zip_ref.extractall(DATADIR)"
] ]
}, },
@ -366,8 +402,10 @@
"source": [ "source": [
"# download future climate model data\n", "# download future climate model data\n",
"\n", "\n",
"c = cdsapi.Client(url=URL, key=KEY)\n", "zipfile_cm_future = os.path.join(CDS_DATA, fname_cm_future) \n",
"\n", "\n",
"if not os.path.exists(zipfile_cm_future):\n",
" print(f\"Downloading {zipfile_cm_future}\")\n",
" c.retrieve(\n", " c.retrieve(\n",
" 'projections-cmip6',\n", " 'projections-cmip6',\n",
" {\n", " {\n",
@ -376,11 +414,15 @@
" 'level': 'single_levels',\n", " 'level': 'single_levels',\n",
" 'variable': variable,\n", " 'variable': variable,\n",
" 'model': model,\n", " 'model': model,\n",
" 'date': period_fut,\n", " # 'date': period_fut,\n",
" 'year': years_fut,\n",
" 'month': months,\n",
" 'area': area,\n", " 'area': area,\n",
" 'format': 'zip',\n", " 'format': 'zip',\n",
" },\n", " },\n",
" f'{DATADIR}/{fname_cm_future}')" " zipfile_cm_future)\n",
"else:\n",
" print(f\"File {zipfile_cm_future} already exists\")"
] ]
}, },
{ {
@ -400,7 +442,7 @@
"source": [ "source": [
"import zipfile\n", "import zipfile\n",
"\n", "\n",
"with zipfile.ZipFile(f'{DATADIR}/{fname_cm_future}', 'r') as zip_ref:\n", "with zipfile.ZipFile(zipfile_cm_future, 'r') as zip_ref:\n",
" zip_ref.extractall(DATADIR)" " zip_ref.extractall(DATADIR)"
] ]
}, },
@ -902,7 +944,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.8.5" "version": "3.10.12"
} }
}, },
"nbformat": 4, "nbformat": 4,