Skip to content

Commit

Permalink
fix requests cordex
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Apr 2, 2024
1 parent c43c209 commit 9c3b4c4
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions notebooks/wp4/extreme_indices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"# Time period\n",
"year_start = 1971\n",
"year_stop = 2000\n",
"assert year_start >= 1971\n",
"\n",
"# Choose annual or seasonal timeseries\n",
"timeseries = \"JJA\"\n",
Expand Down Expand Up @@ -285,29 +286,39 @@
" return start_year, end_year\n",
"\n",
"\n",
"model_requests = {}\n",
"if collection_id == \"CORDEX\":\n",
" models = models_cordex\n",
" model_key = \"rcm_model\"\n",
" request_sim = (\n",
" \"projections-cordex-domains-single-levels\",\n",
" [\n",
" {\n",
" **request_cordex,\n",
" \"start_year\": start_year,\n",
" \"end_year\": end_year,\n",
" }\n",
" for start_year, end_year in zip(\n",
" *get_cordex_years(year_start, year_stop, timeseries)\n",
" )\n",
" ],\n",
" )\n",
" for model in models_cordex:\n",
" start_years = [1970 if model in (\"smhi_rca4\", \"uhoh_wrf361h\") else 1966] + list(\n",
" range(1971, 2097, 5)\n",
" )\n",
" end_years = [1970] + list(range(1975, 2101, 5))\n",
" model_requests[model] = (\n",
" \"projections-cordex-domains-single-levels\",\n",
" [\n",
" {\n",
" \"rcm_model\": model,\n",
" **request_cordex,\n",
" \"start_year\": start_year,\n",
" \"end_year\": end_year,\n",
" }\n",
" for start_year, end_year in zip(\n",
" *get_cordex_years(\n",
" year_start,\n",
" year_stop,\n",
" timeseries,\n",
" start_years=start_years,\n",
" end_years=end_years,\n",
" )\n",
" )\n",
" ],\n",
" )\n",
"elif collection_id == \"CMIP6\":\n",
" models = models_cmip6\n",
" model_key = \"model\"\n",
" request_sim = (\n",
" \"projections-cmip6\",\n",
" download.split_request(request_cmip6, chunks=chunks),\n",
" )\n",
" for model in models_cmip6:\n",
" model_requests[model] = (\n",
" \"projections-cmip6\",\n",
" download.split_request(request_cmip6 | {\"model\": model}, chunks=chunks),\n",
" )\n",
"else:\n",
" raise ValueError(f\"{collection_id=}\")"
]
Expand Down Expand Up @@ -508,23 +519,23 @@
"source": [
"interpolated_datasets = []\n",
"model_datasets = {}\n",
"for model in models:\n",
"for model, requests in model_requests.items():\n",
" print(f\"{model=}\")\n",
" model_kwargs = {\n",
" \"collection_id\": request_sim[0],\n",
" \"requests\": [request | {model_key: model} for request in request_sim[1]],\n",
" \"chunks\": chunks if collection_id == \"CMIP6\" else None,\n",
" \"transform_chunks\": False,\n",
" \"transform_func\": compute_indices_and_trends,\n",
" }\n",
" # Original model\n",
" model_datasets[model] = download.download_and_transform(\n",
" *requests,\n",
" **model_kwargs,\n",
" transform_func_kwargs=transform_func_kwargs,\n",
" )\n",
"\n",
" # Interpolated model\n",
" ds = download.download_and_transform(\n",
" *requests,\n",
" **model_kwargs,\n",
" transform_func_kwargs=transform_func_kwargs\n",
" | {\n",
Expand Down

0 comments on commit 9c3b4c4

Please sign in to comment.