Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More templates #10

Merged
merged 7 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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