From 653ad5356bc123c6c499a971b4644071fc0755b3 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Thu, 22 Jun 2023 15:57:52 +0200 Subject: [PATCH] remove deprecated nb --- notebooks/wp4/clima_t2m.ipynb | 288 ---------------------------------- 1 file changed, 288 deletions(-) delete mode 100644 notebooks/wp4/clima_t2m.ipynb diff --git a/notebooks/wp4/clima_t2m.ipynb b/notebooks/wp4/clima_t2m.ipynb deleted file mode 100644 index bf742b7..0000000 --- a/notebooks/wp4/clima_t2m.ipynb +++ /dev/null @@ -1,288 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# WP4: Climatology and Bias - Near Surface Air Temperature" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Import libraries\n", - "\n", - "Switch warnings off for better readability.\\\n", - "Set matplotlib default settings." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import warnings\n", - "\n", - "import cartopy.crs as ccrs\n", - "import matplotlib.pyplot as plt\n", - "import xarray as xr\n", - "from c3s_eqc_automatic_quality_control import diagnostics, download, plot\n", - "\n", - "plt.style.use(\"seaborn-v0_8-talk\")\n", - "\n", - "warnings.filterwarnings(\"ignore\")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Define time period" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "year_start = 1985\n", - "year_stop = 1987\n", - "\n", - "common_request = {\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 requests" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "request_era = (\n", - " \"reanalysis-era5-single-levels-monthly-means\",\n", - " {\n", - " \"product_type\": \"monthly_averaged_reanalysis\",\n", - " \"format\": \"netcdf\",\n", - " \"time\": \"00:00\",\n", - " \"variable\": \"2m_temperature\",\n", - " **common_request,\n", - " },\n", - ")\n", - "\n", - "request_sim = (\n", - " \"projections-cmip6\",\n", - " {\n", - " \"format\": \"zip\",\n", - " \"temporal_resolution\": \"monthly\",\n", - " \"experiment\": \"historical\",\n", - " \"variable\": \"near_surface_air_temperature\",\n", - " \"model\": \"cmcc_cm2_sr5\",\n", - " **common_request,\n", - " },\n", - ")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Define functions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def resample_and_regrid_sim(ds, grid_out):\n", - " ds_seasonal = diagnostics.seasonal_weighted_mean(ds)\n", - " return diagnostics.regrid(ds_seasonal, grid_out, method=\"bilinear\", periodic=True)\n", - "\n", - "\n", - "def kelvin_to_celsius(da):\n", - " \"\"\"Convert from kelvin to celsius.\"\"\"\n", - " with xr.set_options(keep_attrs=True):\n", - " da -= 273.15\n", - " da.attrs[\"units\"] = \"°C\"\n", - " return da" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Download data and interpolate" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "chunks = {\"year\": 1}\n", - "\n", - "ds_era_seasonal = download.download_and_transform(\n", - " *request_era,\n", - " chunks=chunks,\n", - " transform_func=diagnostics.seasonal_weighted_mean,\n", - " transform_chunks=False,\n", - ")\n", - "\n", - "ds_sim_mean = download.download_and_transform(\n", - " *request_sim,\n", - " chunks=chunks,\n", - " transform_func=diagnostics.time_weighted_mean,\n", - " transform_chunks=False,\n", - ")\n", - "\n", - "ds_reg_seasonal = download.download_and_transform(\n", - " *request_sim,\n", - " chunks=chunks,\n", - " transform_func=resample_and_regrid_sim,\n", - " transform_func_kwargs={\n", - " \"grid_out\": ds_era_seasonal[[\"longitude\", \"latitude\"]],\n", - " },\n", - " transform_chunks=False,\n", - ")" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute mean and seasonal bias" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Convert to celsius\n", - "da_sim_mean = kelvin_to_celsius(ds_sim_mean[\"tas\"])\n", - "\n", - "# Compute bias\n", - "with xr.set_options(keep_attrs=True):\n", - " da_bias = ds_reg_seasonal[\"tas\"] - ds_era_seasonal[\"t2m\"]\n", - "da_bias.attrs[\"long_name\"] += \" Bias\"" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Define labels and settings" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# labels\n", - "info = {key: request_sim[1][key] for key in (\"model\", \"experiment\", \"variable\")}\n", - "info[\"period\"] = f\"{request_sim[1]['year'][0]}-{request_sim[1]['year'][-1]}\"\n", - "fig_prefix = \"_\".join(info.values())\n", - "suptitle = \"; \".join([f\"{k.title()}: {v}\" for k, v in info.items()])\n", - "\n", - "# matplotlib settings\n", - "suptitle_kwargs = {\"x\": 0.5, \"y\": 1, \"ha\": \"center\", \"va\": \"bottom\"}" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plot mean" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p1 = plot.projected_map(\n", - " da_sim_mean, projection=ccrs.Robinson(), levels=range(-30, 31, 5), cmap=\"YlOrRd\"\n", - ")\n", - "p1.figure.suptitle(suptitle, **suptitle_kwargs)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plot seasonal bias" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "p2 = plot.projected_map(\n", - " da_bias,\n", - " projection=ccrs.Robinson(),\n", - " levels=range(-6, 7),\n", - " cmap=\"RdBu_r\",\n", - " col=\"season\",\n", - " col_wrap=2,\n", - ")\n", - "p2.fig.suptitle(suptitle, **suptitle_kwargs)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.10" - }, - "vscode": { - "interpreter": { - "hash": "39a16a1176456aec0710d6d8dd097fdfd8eece03838aebbaaddfca0f16ac2477" - } - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}