-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add satellite * monthly notebook * satellite done * add climate projection template monthly * all templates and use stringify dates * template update * cleanup
- Loading branch information
Showing
7 changed files
with
814 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
notebooks/climate_projections/01-Application_Template_Global_Timeseries_Monthly.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Climate Projections Monthly: Global timeseries" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Import libraries\n", | ||
"\n", | ||
"Switch warnings off for better readability." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import warnings\n", | ||
"\n", | ||
"from c3s_eqc_automatic_quality_control import diagnostics, download, plot\n", | ||
"\n", | ||
"warnings.filterwarnings(\"ignore\")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define request" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"collection_id = \"projections-cmip6\"\n", | ||
"\n", | ||
"year_start = 2008\n", | ||
"year_stop = 2009\n", | ||
"\n", | ||
"request = {\n", | ||
" \"format\": \"zip\",\n", | ||
" \"temporal_resolution\": \"monthly\",\n", | ||
" \"experiment\": \"historical\",\n", | ||
" \"variable\": \"near_surface_air_temperature\",\n", | ||
" \"model\": \"cmcc_cm2_sr5\",\n", | ||
" \"year\": [str(year) for year in range(year_start, year_stop + 1)],\n", | ||
" \"month\": [f\"{month:02d}\" for month in range(1, 12 + 1)],\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define transform function\n", | ||
"\n", | ||
"Drop bounds as they are not used and create issues with dask" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def drop_bounds_and_spatial_weighted_mean(ds):\n", | ||
" return diagnostics.spatial_weighted_mean(ds.drop_dims(\"bnds\"))\n", | ||
"\n", | ||
"\n", | ||
"def drop_bounds_and_spatial_weighted_std(ds):\n", | ||
" return diagnostics.spatial_weighted_std(ds.drop_dims(\"bnds\"))" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Compute spatially-weighted global mean timeseries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds_mean = download.download_and_transform(\n", | ||
" collection_id,\n", | ||
" request,\n", | ||
" transform_func=drop_bounds_and_spatial_weighted_mean,\n", | ||
" split_all=True,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Compute spatially-weighted global std timeseries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds_std = download.download_and_transform(\n", | ||
" collection_id,\n", | ||
" request,\n", | ||
" transform_func=drop_bounds_and_spatial_weighted_std,\n", | ||
" split_all=True,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot and save figure" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"filename = \"_\".join(\n", | ||
" [\"global-timeseries\", collection_id, request[\"temporal_resolution\"]]\n", | ||
")\n", | ||
"title = filename.replace(\"-\", \" \").replace(\"_\", \" \").title()\n", | ||
"fig = plot.shaded_std(\"tas\", ds_mean, ds_std, title=title)\n", | ||
"fig.show()\n", | ||
"fig.write_image(filename + \".png\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "eqc", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.8" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "39a16a1176456aec0710d6d8dd097fdfd8eece03838aebbaaddfca0f16ac2477" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.