{ "cells": [ { "cell_type": "markdown", "id": "b2d05601", "metadata": {}, "source": [ "# with OGGM_v153 --> but apparently not available for all simulations???\n", "\n", "# Notebook to show the steady-state Glacier model differences " ] }, { "cell_type": "code", "execution_count": 1, "id": "f3310431-a48e-426f-9137-2e25bda4badc", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/users/lschuster/mambaforge/envs/oggm_gmip3/lib/python3.11/site-packages/pyproj/__init__.py:89: UserWarning: pyproj unable to set database path.\n", " _pyproj_global_context_initialize()\n" ] } ], "source": [ "# # these code lines above are equal to those at the beginning of 2_glacier_vs_climate_change\n", "\n", "# download it here https://cluster.klima.uni-bremen.de/~lschuster/glacierMIP3_analysis/glacierMIP3_{DATE}_models_all_rgi_regions_sum_scaled.nc\n", "# and change the path to your local path\n", "DATE = 'Feb12_2024' #'Jun29' #'apr04' (has OGGM runaway effect of glaciers inside)\n", "fill_option = 'repeat_last_101yrs'\n", "\n", "import xarray as xr\n", "import numpy as np\n", "import pandas as pd\n", "import scipy\n", "import os\n", "import glob\n", "import matplotlib.pyplot as plt\n", "from datetime import date\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "from matplotlib.lines import Line2D\n", "import matplotlib.patches as mpatches\n", "# for plots withinplots \n", "from mpl_toolkits.axes_grid1.inset_locator import inset_axes\n", "\n", "try:\n", " path_merged_runs_scaled_extend = f'/home/www/lschuster/glacierMIP3_analysis/glacierMIP3_{DATE}_models_all_rgi_regions_sum_scaled_extended_{fill_option}.nc'\n", " _ds_reg_models_extend = xr.open_dataset(path_merged_runs_scaled_extend)\n", "\n", "except:\n", " path_merged_runs_scaled_extend = f'/home/lilianschuster/Downloads/glacierMIP3_{DATE}_models_all_rgi_regions_sum_scaled_extended_{fill_option}.nc'\n", " _ds_reg_models_extend = xr.open_dataset(path_merged_runs_scaled_extend)\n", "from help_functions import pal_models, model_order, d_reg_num_name, model_order_anonymous, compute_steady_state_yr\n" ] }, { "cell_type": "code", "execution_count": 23, "id": "7be43c67-027f-4335-a13c-669407e78fee", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['PyGEM-OGGM_v13', 'GloGEMflow', 'GloGEMflow3D', 'OGGM_v16', 'GLIMB', 'Kraaijenbrink', 'GO', 'CISM2', 'OGGM_v153'] ['model 1', 'model 2', 'model 3', 'model 4', 'model 5', 'model 6', 'model 7', 'model 8', 'model 9']\n" ] } ], "source": [ "\n", "# --> comes from isimip3b_postprocessing_analysis/isimip3b_postprocess_to_monthly.ipynb\n", "pd_global_temp_exp = pd.read_csv('../data/temp_ch_ipcc_ar6_isimip3b.csv', index_col = 0)\n", "\n", "hue_order_anonymous = []\n", "\n", "pal_models_l = []\n", "hue_order = []\n", "for m, p in zip(model_order, pal_models):\n", " if (m!='OGGM-VAS') and (m!='Huss'): #m!='OGGM_v153'):\n", " hue_order.append(m)\n", " pal_models_l.append(p)\n", "for m in hue_order:\n", " hue_order_anonymous.append(model_order_anonymous[m])\n", "pal_models = pal_models_l\n", "\n", "print(hue_order, hue_order_anonymous)\n", "# select the right models:\n", "pal_models = sns.color_palette(pal_models)\n", "\n", "dict_model_col = {}\n", "for c,m in zip(pal_models, hue_order):\n", " dict_model_col[m] = c\n", " \n", "# select the right models\n", "\n", "glac_models = hue_order\n", "\n", "num_dict = {0:'(a)', 1:'(b)', 2:'(c)', 3:'(d)', 4: '(e)', 5:'(f)', 6:'(g)', 7:'(h)', 8:'(i)', 9:'(j)', 10:'(k)', 11:'(l)', 12:'(m)'} \n", "\n", "\n", "def get_glob_temp_exp(region='global'):\n", " pd_global_temp_exp_glac = pd.read_csv('../data/temp_ch_ipcc_ar6_isimip3b_glacier_regionally.csv', index_col = 0)\n", " _p = pd_global_temp_exp_glac.loc[pd_global_temp_exp_glac.region == region].drop(columns=['region'])\n", " _p = _p.groupby(['gcm','period_scenario']).mean()\n", " return _p\n", "\n", "np.testing.assert_allclose(get_glob_temp_exp(region='global')['temp_ch_ipcc'].values,\n", " pd_global_temp_exp.groupby(['gcm','period_scenario']).mean()['temp_ch_ipcc'].values, rtol=1e-5)\n", "import matplotlib\n", "matplotlib.__version__\n", "pd_global_temp_exp_m = get_glob_temp_exp(region='global')\n" ] }, { "cell_type": "code", "execution_count": 24, "id": "692a5921-20f3-4631-9503-77556a76c403", "metadata": {}, "outputs": [], "source": [ "\n", "glob_temp_ch = get_glob_temp_exp(region='global')['temp_ch_ipcc'].values\n", "from matplotlib.colors import LinearSegmentedColormap\n", "from sklearn.preprocessing import MinMaxScaler\n", "only_12_range = False\n", "if only_12_range:\n", " colors_icci_l3 = ['#70B8FF', '#FABB00', '#F25100', '#D42300', '#B3001E', '#800040', '#550066', '#2B084D']\n", " cmap_icci_3 = LinearSegmentedColormap.from_list('bins_100', colors_icci_l3, N=1000)\n", " # IDEA --> Let's scale from 1.2 onwards\n", " scaler = MinMaxScaler()\n", " temp_ch_sel = np.arange(1.2,glob_temp_ch.max(),0.25)\n", " scaler.fit(temp_ch_sel.reshape(-1,1))\n", " cmap = cmap_icci_3\n", "else:\n", " ## '#306BAF', '#1A488A', '#002966'\n", " ## '#4D8ED6',\n", " colors_full_temp_range = ['#002966', '#306BAF', '#70B8FF','#FABB00', '#F25100', '#D42300', '#B3001E', '#800040', '#550066', '#2B084D']\n", " cmap_full_temp_range = LinearSegmentedColormap.from_list('bins_100', colors_full_temp_range, N=1000)\n", " # IDEA --> Let's scale from the entire range onwards onwards\n", " scaler = MinMaxScaler()\n", " temp_ch_sel = np.arange(-0.36,glob_temp_ch.max(),0.25)# need to manually set the minimum to a lower value to have a light blue color at ~1.2°C\n", " scaler.fit(temp_ch_sel.reshape(-1,1))\n", " cmap = cmap_full_temp_range\n", "\n", "norm = plt.Normalize(vmin=-0.36, vmax=glob_temp_ch.max()) # we need the -0.4 for the correct norm \n", "sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)\n", "#sm.set_clim(glob_temp_ch.min(),glob_temp_ch.max())\n", "# ok, both approaches work the same \n", "assert sm.cmap == cmap\n", "\n", "t = 1.2\n", "import matplotlib.colors as mcolors\n", "# just want to make sure that 1.2°C is this color here: '#70B8FF'\n", "hex_color = '#70B8FF'\n", "rgba_color = mcolors.to_rgba(hex_color)\n", "c1=sm.cmap(scaler.transform(np.array(t).reshape(-1,1))).squeeze()\n", "c2=cmap(scaler.transform(np.array(t).reshape(-1,1))).squeeze()\n", "np.testing.assert_allclose(c1,c2)\n", "np.testing.assert_allclose(c1,rgba_color)" ] }, { "cell_type": "code", "execution_count": 25, "id": "e2df1fed-6dcc-4b69-8e61-62301f3fbc20", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | simulation_year | \n", "volume_m3 | \n", "area_m2 | \n", "extend_option | \n", "
|---|---|---|---|---|
| model_author | \n", "\n", " | \n", " | \n", " | \n", " |
| CISM2 | \n", "80 | \n", "80 | \n", "80 | \n", "80 | \n", "
| GLIMB | \n", "1520 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "
| GO | \n", "80 | \n", "80 | \n", "80 | \n", "80 | \n", "
| GloGEMflow | \n", "1520 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "
| GloGEMflow3D | \n", "880 | \n", "880 | \n", "880 | \n", "880 | \n", "
| Huss | \n", "764 | \n", "764 | \n", "764 | \n", "764 | \n", "
| Kraaijenbrink | \n", "240 | \n", "240 | \n", "240 | \n", "240 | \n", "
| OGGM-VAS | \n", "1440 | \n", "1440 | \n", "1440 | \n", "1440 | \n", "
| OGGM_v153 | \n", "304 | \n", "304 | \n", "304 | \n", "304 | \n", "
| OGGM_v16 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "
| PyGEM-OGGM_v13 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "1520 | \n", "
| \n", " | model_author | \n", "gcm | \n", "period_scenario | \n", "temp_ch_ipcc | \n", "volume_m3 | \n", "year_after_2020 | \n", "relative volume change (in %) | \n", "delta relative volume change (in %, to median model) | \n", "delta relative volume change (in %, to median model, relative to ref period ) | \n", "temp_ch_classes | \n", "rgi_reg | \n", "absolute delta relative volume change (in %, to median model) | \n", "absolute delta relative volume change (in %, to median model, relative to ref period ) | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "GLIMB | \n", "gfdl-esm4 | \n", "1851-1870_hist | \n", "0.231409 | \n", "1.253455e+14 | \n", "0.0 | \n", "80.812475 | \n", "-5.675031 | \n", "-5.984223 | \n", "-0.1°C-2.0°C | \n", "Global | \n", "5.675031 | \n", "5.984223 | \n", "
| 1 | \n", "GLIMB | \n", "gfdl-esm4 | \n", "1901-1920_hist | \n", "0.478289 | \n", "1.146157e+14 | \n", "0.0 | \n", "74.273069 | \n", "-1.113826 | \n", "-1.423018 | \n", "-0.1°C-2.0°C | \n", "Global | \n", "1.113826 | \n", "1.423018 | \n", "
| 2 | \n", "GLIMB | \n", "gfdl-esm4 | \n", "1951-1970_hist | \n", "0.392281 | \n", "1.179973e+14 | \n", "0.0 | \n", "76.486687 | \n", "-12.982556 | \n", "-13.291747 | \n", "-0.1°C-2.0°C | \n", "Global | \n", "12.982556 | \n", "13.291747 | \n", "
| 3 | \n", "GLIMB | \n", "gfdl-esm4 | \n", "1995-2014_hist | \n", "0.901467 | \n", "1.033774e+14 | \n", "0.0 | \n", "67.609008 | \n", "0.309192 | \n", "0.000000 | \n", "-0.1°C-2.0°C | \n", "Global | \n", "0.309192 | \n", "0.000000 | \n", "
| 4 | \n", "GLIMB | \n", "gfdl-esm4 | \n", "2021-2040_ssp126 | \n", "1.493792 | \n", "8.175907e+13 | \n", "0.0 | \n", "53.517849 | \n", "2.054803 | \n", "1.745611 | \n", "-0.1°C-2.0°C | \n", "Global | \n", "2.054803 | \n", "1.745611 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 1515 | \n", "PyGEM-OGGM_v13 | \n", "ukesm1-0-ll | \n", "2061-2080_ssp370 | \n", "4.439977 | \n", "6.337830e+12 | \n", "0.0 | \n", "13.770904 | \n", "-6.390154 | \n", "8.611169 | \n", "4.0°C-7.0°C | \n", "19 | \n", "6.390154 | \n", "8.611169 | \n", "
| 1516 | \n", "PyGEM-OGGM_v13 | \n", "ukesm1-0-ll | \n", "2061-2080_ssp585 | \n", "5.230543 | \n", "4.558544e+12 | \n", "0.0 | \n", "9.904876 | \n", "-8.343732 | \n", "6.657591 | \n", "4.0°C-7.0°C | \n", "19 | \n", "8.343732 | \n", "6.657591 | \n", "
| 1517 | \n", "PyGEM-OGGM_v13 | \n", "ukesm1-0-ll | \n", "2081-2100_ssp126 | \n", "3.038482 | \n", "1.314191e+13 | \n", "0.0 | \n", "28.597223 | \n", "-11.283813 | \n", "3.717510 | \n", "2.0°C-4.0°C | \n", "19 | \n", "11.283813 | \n", "3.717510 | \n", "
| 1518 | \n", "PyGEM-OGGM_v13 | \n", "ukesm1-0-ll | \n", "2081-2100_ssp370 | \n", "5.840495 | \n", "4.238342e+12 | \n", "0.0 | \n", "9.182292 | \n", "-3.481947 | \n", "11.519376 | \n", "4.0°C-7.0°C | \n", "19 | \n", "3.481947 | \n", "11.519376 | \n", "
| 1519 | \n", "PyGEM-OGGM_v13 | \n", "ukesm1-0-ll | \n", "2081-2100_ssp585 | \n", "6.884361 | \n", "4.286108e+12 | \n", "0.0 | \n", "9.359933 | \n", "-1.888705 | \n", "13.112618 | \n", "4.0°C-7.0°C | \n", "19 | \n", "1.888705 | \n", "13.112618 | \n", "
6400 rows × 13 columns
\n", "<xarray.DataArray 'volume_m3' (model_author: 11, rgi_reg: 19, experiments: 80)> Size: 67kB\n",
"array([[[ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" ...,\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan]],\n",
"\n",
" [[ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
"...\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan],\n",
" [8.7228482e+10, 6.7772969e+10, 8.2020876e+10, ...,\n",
" 3.2495129e+10, 4.9723812e+09, 2.5286986e+09],\n",
" [ nan, nan, nan, ...,\n",
" nan, nan, nan]],\n",
"\n",
" [[1.3886179e+13, 1.1903984e+13, 1.3050748e+13, ...,\n",
" nan, nan, nan],\n",
" [1.0717680e+11, 6.9207835e+10, 1.5074918e+11, ...,\n",
" nan, nan, nan],\n",
" [3.8212278e+13, 3.7969776e+13, 3.7253573e+13, ...,\n",
" nan, nan, nan],\n",
" ...,\n",
" [4.2145127e+12, 2.9537107e+12, 3.1543423e+12, ...,\n",
" nan, nan, nan],\n",
" [9.2111225e+10, 6.4005067e+10, 8.7077429e+10, ...,\n",
" nan, nan, nan],\n",
" [6.8539063e+13, 5.6107360e+13, 6.8148682e+13, ...,\n",
" nan, nan, nan]]], dtype=float32)\n",
"Coordinates:\n",
" * model_author (model_author) <U14 616B 'CISM2' 'GO' ... 'Huss'\n",
" * rgi_reg (rgi_reg) <U2 152B '01' '02' '03' '04' ... '17' '18' '19'\n",
" extend_option <U18 72B ...\n",
" * experiments (experiments) object 640B MultiIndex\n",
" * gcm (experiments) <U13 4kB 'gfdl-esm4' ... 'ukesm1-0-ll'\n",
" * period_scenario (experiments) <U16 5kB '1851-1870_hist' ... '2081-2100_s...\n",
" temp_ch_ipcc (experiments) float64 640B 0.2314 0.4783 ... 5.84 6.884