Skip to content

Commit

Permalink
More templates (#10)
Browse files Browse the repository at this point in the history
* add satellite

* monthly notebook

* satellite done

* add climate projection template monthly

* all templates and use stringify dates

* template update

* cleanup
  • Loading branch information
malmans2 authored Jan 9, 2023
1 parent 4487033 commit 02cbf06
Show file tree
Hide file tree
Showing 7 changed files with 814 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/ecmwf-projects/cookiecutter-conda-package",
"commit": "c7cd369f71b4cfc647fc7c1972cc3c45860256d5",
"commit": "c4101cc46ee7312553f246d8806aebc7160edcc4",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ repos:
args: [--autofix]
additional_dependencies: [toml-sort<0.22.0]
- repo: https://github.com/PyCQA/pydocstyle.git
rev: 6.1.1
rev: 6.2.2
hooks:
- id: pydocstyle
additional_dependencies: [toml]
additional_dependencies: [tomli]
exclude: tests|docs
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.3
Expand Down
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
}
Loading

0 comments on commit 02cbf06

Please sign in to comment.