|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "attachments": {}, |
| 5 | + "cell_type": "markdown", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Climate Projections Monthly: Global timeseries" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "attachments": {}, |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "## Import libraries\n", |
| 17 | + "\n", |
| 18 | + "Switch warnings off for better readability." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": null, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [], |
| 26 | + "source": [ |
| 27 | + "import warnings\n", |
| 28 | + "\n", |
| 29 | + "from c3s_eqc_automatic_quality_control import diagnostics, download, plot\n", |
| 30 | + "\n", |
| 31 | + "warnings.filterwarnings(\"ignore\")" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "attachments": {}, |
| 36 | + "cell_type": "markdown", |
| 37 | + "metadata": {}, |
| 38 | + "source": [ |
| 39 | + "## Define request" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "collection_id = \"projections-cmip6\"\n", |
| 49 | + "\n", |
| 50 | + "year_start = 2008\n", |
| 51 | + "year_stop = 2009\n", |
| 52 | + "\n", |
| 53 | + "request = {\n", |
| 54 | + " \"format\": \"zip\",\n", |
| 55 | + " \"temporal_resolution\": \"monthly\",\n", |
| 56 | + " \"experiment\": \"historical\",\n", |
| 57 | + " \"variable\": \"near_surface_air_temperature\",\n", |
| 58 | + " \"model\": \"cmcc_cm2_sr5\",\n", |
| 59 | + " \"year\": [str(year) for year in range(year_start, year_stop + 1)],\n", |
| 60 | + " \"month\": [f\"{month:02d}\" for month in range(1, 12 + 1)],\n", |
| 61 | + "}" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "attachments": {}, |
| 66 | + "cell_type": "markdown", |
| 67 | + "metadata": {}, |
| 68 | + "source": [ |
| 69 | + "## Define transform function\n", |
| 70 | + "\n", |
| 71 | + "Drop bounds as they are not used and create issues with dask" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": null, |
| 77 | + "metadata": {}, |
| 78 | + "outputs": [], |
| 79 | + "source": [ |
| 80 | + "def drop_bounds_and_spatial_weighted_mean(ds):\n", |
| 81 | + " return diagnostics.spatial_weighted_mean(ds.drop_dims(\"bnds\"))\n", |
| 82 | + "\n", |
| 83 | + "\n", |
| 84 | + "def drop_bounds_and_spatial_weighted_std(ds):\n", |
| 85 | + " return diagnostics.spatial_weighted_std(ds.drop_dims(\"bnds\"))" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "attachments": {}, |
| 90 | + "cell_type": "markdown", |
| 91 | + "metadata": {}, |
| 92 | + "source": [ |
| 93 | + "## Compute spatially-weighted global mean timeseries" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": null, |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [], |
| 101 | + "source": [ |
| 102 | + "ds_mean = download.download_and_transform(\n", |
| 103 | + " collection_id,\n", |
| 104 | + " request,\n", |
| 105 | + " transform_func=drop_bounds_and_spatial_weighted_mean,\n", |
| 106 | + " split_all=True,\n", |
| 107 | + ")" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "attachments": {}, |
| 112 | + "cell_type": "markdown", |
| 113 | + "metadata": {}, |
| 114 | + "source": [ |
| 115 | + "## Compute spatially-weighted global std timeseries" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "code", |
| 120 | + "execution_count": null, |
| 121 | + "metadata": {}, |
| 122 | + "outputs": [], |
| 123 | + "source": [ |
| 124 | + "ds_std = download.download_and_transform(\n", |
| 125 | + " collection_id,\n", |
| 126 | + " request,\n", |
| 127 | + " transform_func=drop_bounds_and_spatial_weighted_std,\n", |
| 128 | + " split_all=True,\n", |
| 129 | + ")" |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "attachments": {}, |
| 134 | + "cell_type": "markdown", |
| 135 | + "metadata": {}, |
| 136 | + "source": [ |
| 137 | + "## Plot and save figure" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "code", |
| 142 | + "execution_count": null, |
| 143 | + "metadata": {}, |
| 144 | + "outputs": [], |
| 145 | + "source": [ |
| 146 | + "filename = \"_\".join(\n", |
| 147 | + " [\"global-timeseries\", collection_id, request[\"temporal_resolution\"]]\n", |
| 148 | + ")\n", |
| 149 | + "title = filename.replace(\"-\", \" \").replace(\"_\", \" \").title()\n", |
| 150 | + "fig = plot.shaded_std(\"tas\", ds_mean, ds_std, title=title)\n", |
| 151 | + "fig.show()\n", |
| 152 | + "fig.write_image(filename + \".png\")" |
| 153 | + ] |
| 154 | + }, |
| 155 | + { |
| 156 | + "cell_type": "code", |
| 157 | + "execution_count": null, |
| 158 | + "metadata": {}, |
| 159 | + "outputs": [], |
| 160 | + "source": [] |
| 161 | + } |
| 162 | + ], |
| 163 | + "metadata": { |
| 164 | + "kernelspec": { |
| 165 | + "display_name": "eqc", |
| 166 | + "language": "python", |
| 167 | + "name": "python3" |
| 168 | + }, |
| 169 | + "language_info": { |
| 170 | + "codemirror_mode": { |
| 171 | + "name": "ipython", |
| 172 | + "version": 3 |
| 173 | + }, |
| 174 | + "file_extension": ".py", |
| 175 | + "mimetype": "text/x-python", |
| 176 | + "name": "python", |
| 177 | + "nbconvert_exporter": "python", |
| 178 | + "pygments_lexer": "ipython3", |
| 179 | + "version": "3.10.8" |
| 180 | + }, |
| 181 | + "vscode": { |
| 182 | + "interpreter": { |
| 183 | + "hash": "39a16a1176456aec0710d6d8dd097fdfd8eece03838aebbaaddfca0f16ac2477" |
| 184 | + } |
| 185 | + } |
| 186 | + }, |
| 187 | + "nbformat": 4, |
| 188 | + "nbformat_minor": 2 |
| 189 | +} |
0 commit comments