{ "cells": [ { "cell_type": "markdown", "id": "bdc6291f-a4af-4ec4-bf21-c1e8cf7bc11d", "metadata": {}, "source": [ "# Error analysis\n", "- similar to [error_analysis_v1.ipynb](https://nbviewer.org/urls/cluster.klima.uni-bremen.de/~lschuster/error_analysis/error_analysis_v1.ipynb?flush_cache=true#Analysis-for-Level-5-pre-processing-directories!)" ] }, { "cell_type": "code", "execution_count": 1, "id": "010a4dde-97d6-421f-abff-3de9c477dcc1", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-06-05 07:42:38: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.\n", "2023-06-05 07:42:38: oggm.cfg: Multiprocessing switched OFF according to the parameter file.\n", "2023-06-05 07:42:38: oggm.cfg: Multiprocessing: using all available processors (N=32)\n" ] } ], "source": [ "from oggm import cfg, workflow, utils, shop\n", "import pandas as pd\n", "import os, glob\n", "import numpy as np\n", "import xarray as xr\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "sns.set_style(\"whitegrid\")\n", "\n", "cfg.initialize()\n", "\n", "import matplotlib\n", "matplotlib.rcParams['figure.figsize'] = (14, 8)\n", "import geopandas as gpd\n", "\n", "gcms_cmip6 = pd.read_csv('/home/www/oggm/cmip6/all_gcm_list.csv', index_col=0) \n", "\n", "gcms = []\n", "ssps = []\n", "gcms_ssps = []\n", "for ind in gcms_cmip6.loc[gcms_cmip6['var']=='pr'].index:\n", " gcms.append(gcms_cmip6.loc[ind].gcm)\n", " ssps.append(gcms_cmip6.loc[ind].ssp)\n", " gcms_ssps.append(f'{gcms_cmip6.loc[ind].gcm}_{gcms_cmip6.loc[ind].ssp}')" ] }, { "cell_type": "code", "execution_count": 2, "id": "95c11c7e-c2ea-416b-ba22-5592120b183f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 3, "id": "1bf1f01d-0408-4386-9d47-30c007ff996f", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "8515f2a2-e230-4b24-b55e-9795e7d6dae6", "metadata": {}, "source": [ "## Get a list with the amount of failing glaciers and area for the different Scenarios and GCMs" ] }, { "cell_type": "code", "execution_count": 4, "id": "8b48b998-1bdc-4145-a2d4-93ce7f19d99e", "metadata": {}, "outputs": [], "source": [ "pd_geodetic = utils.get_geodetic_mb_dataframe()[utils.get_geodetic_mb_dataframe().period=='2000-01-01_2020-01-01']\n", "# ok, connectivity level 2 glaciers are not inside ...\n", "rgis_05 = gpd.read_file(utils.get_rgi_region_file('05', version='62'))\n", "rgis_05_remove = rgis_05.loc[(rgis_05['Connect'] ==2)].RGIId.values\n", "assert len(np.intersect1d(pd_geodetic.index.values,rgis_05_remove)) == 0\n", "total_area = pd_geodetic.area.sum()\n", "total_counts = len(pd_geodetic)" ] }, { "cell_type": "code", "execution_count": null, "id": "6ac45a3a-0115-4ad0-96bb-2296b8d6c843", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "5\n", "_bc_2000_2019_w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 213655\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.12%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.90%\n", "1\n" ] } ], "source": [ "# NEW version 2023.3:\n", "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_2000_2019']: #,'_bc_1979_2014'\n", " pd_working = pd.DataFrame(index = pd_geodetic.index,\n", " columns=gcms_ssps)\n", " # we will set those that are not running afterwards to np.NaN value\n", " pd_working.loc[pd_geodetic.index] = True\n", " pd_working['area'] = pd_geodetic.area\n", " pd_working['all_running_rgis'] = np.NaN\n", " pd_working['rgi_reg'] = pd_geodetic.reg\n", " for rgi_reg in np.array([ 1, 2, 3, 4, 6, 7, 8, 9,\n", " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5]):\n", " print(rgi_reg)\n", " if rgi_reg < 10:\n", " rgi_reg_s = f'0{rgi_reg}'\n", " else:\n", " rgi_reg_s = rgi_reg\n", " \n", "\n", " dpath = f'/home/www/lschuster/runs_oggm_v16/runs_2023.3/output/RGI{rgi_reg_s}'\n", " # amount of glaciers in that rgi region\n", " rgi_reg_glaciers = pd_working.loc[pd_working.rgi_reg==int(rgi_reg)].index\n", " for gcm_ssp in gcms_ssps: \n", " with xr.open_mfdataset(f'{dpath}/run_hydro_{hist}_endyr2100_CMIP6_{gcm_ssp}{bc}_rgi{rgi_reg_s}*.nc') as ds:\n", " ds = ds.volume.sel(time=2000).load()\n", " # make sure that all glaciers have been running\n", " assert len(ds.rgi_id.values) == len(rgi_reg_glaciers)\n", " rgis_error = list(set(rgi_reg_glaciers) - set(ds.dropna(dim='rgi_id').rgi_id.values))\n", " pd_working.loc[rgis_error, gcm_ssp] = np.NaN\n", " ds.close()\n", " \n", " all_running_rgis = pd_working[gcms_ssps].dropna().index\n", " pd_working.loc[all_running_rgis, 'all_running_rgis'] = True\n", " all_running_rel = len(all_running_rgis)*100/len(pd_geodetic)\n", " all_running_rel_area = pd_working.loc[all_running_rgis].area.sum()*100/pd_working.area.sum()\n", " print(f'{bc}_{hist}')\n", " print(f'Amount of glaciers that run over the entire time period: {len(all_running_rgis)}')\n", " print(f'Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: {all_running_rel:0.2f}%')\n", " print(f'Relative percentage of glacier area where all gcms and ssp could run over the entire time period: {all_running_rel_area:0.2f}%')\n", " #pd_rel_error_area_L5.to_csv('rel_error_area_statistics_for_oversh_stab_scenarios.csv')\n", " pd_working.to_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}_2023.3.csv')\n" ] }, { "cell_type": "code", "execution_count": null, "id": "e38c77f9-0eec-4900-b5a6-8614b6ba5ffe", "metadata": {}, "outputs": [], "source": [ "run = False\n", "if run:\n", " for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_2000_2019']: #,'_bc_1979_2014'\n", " pd_working = pd.DataFrame(index = pd_geodetic.index,\n", " columns=gcms_ssps)\n", " # we will set those that are not running afterwards to np.NaN value\n", " pd_working.loc[pd_geodetic.index] = True\n", " pd_working['area'] = pd_geodetic.area\n", " pd_working['all_running_rgis'] = np.NaN\n", " pd_working['rgi_reg'] = pd_geodetic.reg\n", " for rgi_reg in np.array([ 1, 2, 3, 4, 6, 7, 8, 9,\n", " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5]):\n", " print(rgi_reg)\n", " if rgi_reg < 10:\n", " rgi_reg_s = f'0{rgi_reg}'\n", " else:\n", " rgi_reg_s = rgi_reg\n", "\n", "\n", " dpath = f'/home/www/lschuster/runs_oggm_v16/output/RGI{rgi_reg_s}'\n", " # amount of glaciers in that rgi region\n", " rgi_reg_glaciers = pd_working.loc[pd_working.rgi_reg==int(rgi_reg)].index\n", " for gcm_ssp in gcms_ssps: \n", " with xr.open_mfdataset(f'{dpath}/run_hydro_{hist}_endyr2100_CMIP6_{gcm_ssp}{bc}_rgi{rgi_reg_s}*.nc') as ds:\n", " ds = ds.volume.sel(time=2000).load()\n", " # make sure that all glaciers have been running\n", " assert len(ds.rgi_id.values) == len(rgi_reg_glaciers)\n", " rgis_error = list(set(rgi_reg_glaciers) - set(ds.dropna(dim='rgi_id').rgi_id.values))\n", " pd_working.loc[rgis_error, gcm_ssp] = np.NaN\n", " ds.close()\n", "\n", " all_running_rgis = pd_working[gcms_ssps].dropna().index\n", " pd_working.loc[all_running_rgis, 'all_running_rgis'] = True\n", " all_running_rel = len(all_running_rgis)*100/len(pd_geodetic)\n", " all_running_rel_area = pd_working.loc[all_running_rgis].area.sum()*100/pd_working.area.sum()\n", " print(f'{bc}_{hist}')\n", " print(f'Amount of glaciers that run over the entire time period: {len(all_running_rgis)}')\n", " print(f'Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: {all_running_rel:0.2f}%')\n", " print(f'Relative percentage of glacier area where all gcms and ssp could run over the entire time period: {all_running_rel_area:0.2f}%')\n", " #pd_rel_error_area_L5.to_csv('rel_error_area_statistics_for_oversh_stab_scenarios.csv')\n", " pd_working.to_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}.csv')\n" ] }, { "cell_type": "code", "execution_count": null, "id": "1587c5ef-adbe-4a4d-9b51-52389eb5a938", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "9dd560ea-822e-4687-a0f3-049c608a1ad2", "metadata": {}, "source": [ "##### Do the same for every RGI region:" ] }, { "cell_type": "code", "execution_count": null, "id": "a098fe9d-fc80-4767-8226-f4ce83053b5c", "metadata": {}, "outputs": [], "source": [ "# NEW version 2023.3:\n", "for rgi_reg in pd_working.rgi_reg.unique():\n", " if rgi_reg < 10:\n", " rgi_reg_s = f'0{rgi_reg}'\n", " else:\n", " rgi_reg_s = rgi_reg\n", " print(f'RGI{rgi_reg_s}')\n", " for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " pd_working = pd.read_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}_2023.3.csv', low_memory=False)\n", " pd_working_sel = pd_working.loc[pd_working.rgi_reg==int(rgi_reg)]\n", " all_running_rgis_reg = pd_working_sel[gcms_ssps].dropna().index\n", " all_running_rel_reg = len(all_running_rgis_reg)*100/len(pd_working_sel)\n", " all_running_rel_area_reg = pd_working.loc[all_running_rgis_reg].area.sum()*100/pd_working_sel.area.sum()\n", " print(f'{hist}')\n", " print(f'Amount of glaciers that run over the entire time period: {len(all_running_rgis_reg)}')\n", " print(f'Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: {all_running_rel_reg:0.2f}%')\n", " print(f'Relative percentage of glacier area where all gcms and ssp could run over the entire time period: {all_running_rel_area_reg:0.2f}%')" ] }, { "cell_type": "code", "execution_count": null, "id": "82a0cce1-9465-4961-b464-5a9c8da3ab09", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 11, "id": "33a75b06-c4e2-4bfe-8db5-961c4950008b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RGI01\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 27086\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.92%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 27085\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.92%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "RGI02\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 18805\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.73%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 18797\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.69%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "RGI03\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 4525\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.32%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 4526\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.34%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "RGI04\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 7396\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.74%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 7396\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.74%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "RGI05\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 19190\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.40%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 19183\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.36%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "RGI06\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 566\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.65%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 566\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.65%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "RGI07\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 1615\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 100.00%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 1613\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.88%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "RGI08\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 3410\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.80%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 3408\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.74%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "RGI09\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 1065\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.63%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.95%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 1065\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.63%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.95%\n", "RGI10\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 5000\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 97.07%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 96.34%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 4999\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 97.05%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 96.33%\n", "RGI11\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 3921\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.85%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 3921\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.85%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "RGI12\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 1518\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 80.40%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 90.73%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 1518\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 80.40%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 90.73%\n", "RGI13\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 54174\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.53%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.84%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 54165\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.51%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.83%\n", "RGI14\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 27938\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.82%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.98%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 27934\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.81%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.97%\n", "RGI15\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 13097\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.83%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.94%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 13094\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.81%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.94%\n", "RGI16\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 2936\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.90%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 2934\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.83%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.99%\n", "RGI17\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 15850\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.64%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.86%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 15849\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.63%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.86%\n", "RGI18\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 3536\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.97%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 3536\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.97%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 100.00%\n", "RGI19\n", "w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 2228\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 80.96%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.81%\n", "gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 2228\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 80.96%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.80%\n" ] } ], "source": [ "for rgi_reg in pd_working.rgi_reg.unique():\n", " if rgi_reg < 10:\n", " rgi_reg_s = f'0{rgi_reg}'\n", " else:\n", " rgi_reg_s = rgi_reg\n", " print(f'RGI{rgi_reg_s}')\n", " for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " pd_working = pd.read_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}.csv', low_memory=False)\n", " pd_working_sel = pd_working.loc[pd_working.rgi_reg==int(rgi_reg)]\n", " all_running_rgis_reg = pd_working_sel[gcms_ssps].dropna().index\n", " all_running_rel_reg = len(all_running_rgis_reg)*100/len(pd_working_sel)\n", " all_running_rel_area_reg = pd_working.loc[all_running_rgis_reg].area.sum()*100/pd_working_sel.area.sum()\n", " print(f'{hist}')\n", " print(f'Amount of glaciers that run over the entire time period: {len(all_running_rgis_reg)}')\n", " print(f'Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: {all_running_rel_reg:0.2f}%')\n", " print(f'Relative percentage of glacier area where all gcms and ssp could run over the entire time period: {all_running_rel_area_reg:0.2f}%')" ] }, { "cell_type": "code", "execution_count": null, "id": "7f7b1ecc-5ea3-48dd-a9f7-203f0dc04356", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "ff6a3c72-03fb-4038-ac66-40842a11bf97", "metadata": {}, "source": [ "***Save it in a common running file with just _bc_2000_2019****" ] }, { "cell_type": "code", "execution_count": null, "id": "7c56c10b-4dfe-4e28-a320-ee8015cf8fea", "metadata": {}, "outputs": [], "source": [ "all_running_rgis_l = []\n", "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_2000_2019']:\n", " pd_working = pd.read_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}_2023.3.csv', low_memory=False, index_col='rgiid')\n", " all_running_rgis_l.append(pd_working['all_running_rgis'].dropna().index)\n", " \n", "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_2000_2019']:\n", " pd_working = pd.read_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}.csv', low_memory=False, index_col='rgiid')\n", " all_running_rgis_l.append(pd_working['all_running_rgis'].dropna().index)\n", "\n", "all_running_rgis = all_running_rgis_l[0]\n", "for i in all_running_rgis_l[1:]:\n", " all_running_rgis = list(set(all_running_rgis).intersection(i))\n", "pd_working_all = pd_working.loc[all_running_rgis][['area','all_running_rgis', 'rgi_reg']]\n", "pd_working_all.to_csv('all_common_working_rgi_ids_bc_2000_2019_w_2023.2_vs_2023.3.csv')" ] }, { "cell_type": "markdown", "id": "3c55a156-d7ae-4e7d-958f-d6c794f4b7bb", "metadata": {}, "source": [ "### Now repeat it with the CMIP6 run with '_bc_1979_2014'" ] }, { "cell_type": "code", "execution_count": 12, "id": "8e071faf-817b-41bc-affa-d683d7b313b5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "5\n", "_bc_1979_2014_w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 214055\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.31%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.91%\n", "1\n", "2\n", "3\n", "4\n", "6\n", "7\n", "8\n", "9\n", "10\n", "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "5\n", "_bc_1979_2014_gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 213997\n", "Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: 99.28%\n", "Relative percentage of glacier area where all gcms and ssp could run over the entire time period: 99.90%\n" ] } ], "source": [ "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_1979_2014']:\n", " pd_working = pd.DataFrame(index = pd_geodetic.index,\n", " columns=gcms_ssps)\n", " # we will set those that are not running afterwards to np.NaN value\n", " pd_working.loc[pd_geodetic.index] = True\n", " pd_working['area'] = pd_geodetic.area\n", " pd_working['all_running_rgis'] = np.NaN\n", " pd_working['rgi_reg'] = pd_geodetic.reg\n", " for rgi_reg in np.array([ 1, 2, 3, 4, 6, 7, 8, 9,\n", " 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5]):\n", " print(rgi_reg)\n", " if rgi_reg < 10:\n", " rgi_reg_s = f'0{rgi_reg}'\n", " else:\n", " rgi_reg_s = rgi_reg\n", " \n", "\n", " dpath = f'/home/www/lschuster/runs_oggm_v16/output/RGI{rgi_reg_s}'\n", " # amount of glaciers in that rgi region\n", " rgi_reg_glaciers = pd_working.loc[pd_working.rgi_reg==int(rgi_reg)].index\n", " for gcm_ssp in gcms_ssps:\n", " gcm = gcm_ssp.split('_')[0]\n", " ssp = gcm_ssp.split('_')[1]\n", " if gcm.lower() in ['gfdl-esm4', 'mpi-esm1-2-hr', 'mri-esm2-0']: \n", " if ssp in ['ssp126', 'ssp370', 'ssp585']:\n", " with xr.open_mfdataset(f'{dpath}/run_hydro_{hist}_endyr2100_CMIP6_{gcm_ssp}{bc}_rgi{rgi_reg_s}*.nc') as ds:\n", " ds = ds.volume.sel(time=2000).load()\n", " # make sure that all glaciers have been running\n", " assert len(ds.rgi_id.values) == len(rgi_reg_glaciers)\n", " rgis_error = list(set(rgi_reg_glaciers) - set(ds.dropna(dim='rgi_id').rgi_id.values))\n", " pd_working.loc[rgis_error, gcm_ssp] = np.NaN\n", " ds.close()\n", " \n", " all_running_rgis = pd_working[gcms_ssps].dropna().index\n", " pd_working.loc[all_running_rgis, 'all_running_rgis'] = True\n", " all_running_rel = len(all_running_rgis)*100/len(pd_geodetic)\n", " all_running_rel_area = pd_working.loc[all_running_rgis].area.sum()*100/pd_working.area.sum()\n", " print(f'{bc}_{hist}')\n", " print(f'Amount of glaciers that run over the entire time period: {len(all_running_rgis)}')\n", " print(f'Relative percentage of glacier amount where all gcms and ssp could run over the entire time period: {all_running_rel:0.2f}%')\n", " print(f'Relative percentage of glacier area where all gcms and ssp could run over the entire time period: {all_running_rel_area:0.2f}%')\n", " #pd_rel_error_area_L5.to_csv('rel_error_area_statistics_for_oversh_stab_scenarios.csv')\n", " pd_working.to_csv(f'working_rgis_for_oggm_v16_CMIP6{bc}_{hist}.csv')\n" ] }, { "cell_type": "markdown", "id": "a5346e70-38e7-4af3-acf0-98709aa9f8b6", "metadata": {}, "source": [ "### Now repeat it with the ISIMIP3b runs" ] }, { "cell_type": "code", "execution_count": 13, "id": "c02bc555-cff2-45f3-9822-c0a63d72ac7e", "metadata": {}, "outputs": [], "source": [ "isimip3b_members = ['gfdl-esm4_r1i1p1f1', 'mpi-esm1-2-hr_r1i1p1f1',\n", " 'mri-esm2-0_r1i1p1f1',\n", " 'ipsl-cm6a-lr_r1i1p1f1', 'ukesm1-0-ll_r1i1p1f2' ]\n", "gcms_ssps_isimip3b = []\n", "for member in isimip3b_members:\n", " # Download the three main SSPs\n", " for ssp in ['ssp126', 'ssp370','ssp585']:\n", " gcms_ssps_isimip3b.append(f'{member}_{ssp}')" ] }, { "cell_type": "code", "execution_count": 17, "id": "4cf0dc12-8b50-4838-a33b-69e8a554217f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | CESM2-WACCM_ssp126 | \n", "CESM2-WACCM_ssp370 | \n", "CESM2-WACCM_ssp585 | \n", "CESM2-WACCM_ssp245 | \n", "CESM2-WACCM_ssp534-over | \n", "MPI-ESM1-2-HR_ssp585 | \n", "MPI-ESM1-2-HR_ssp370 | \n", "MPI-ESM1-2-HR_ssp245 | \n", "MPI-ESM1-2-HR_ssp126 | \n", "GFDL-ESM4_ssp370 | \n", "... | \n", "gfdl-esm4_r1i1p1f1_ssp585 | \n", "mpi-esm1-2-hr_r1i1p1f1_ssp126 | \n", "mpi-esm1-2-hr_r1i1p1f1_ssp370 | \n", "mpi-esm1-2-hr_r1i1p1f1_ssp585 | \n", "mri-esm2-0_r1i1p1f1_ssp126 | \n", "mri-esm2-0_r1i1p1f1_ssp370 | \n", "mri-esm2-0_r1i1p1f1_ssp585 | \n", "ipsl-cm6a-lr_r1i1p1f1_ssp126 | \n", "ipsl-cm6a-lr_r1i1p1f1_ssp370 | \n", "ipsl-cm6a-lr_r1i1p1f1_ssp585 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| rgiid | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| RGI60-01.00001 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-01.00002 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-01.00003 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-01.00004 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-01.00005 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| RGI60-19.02748 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-19.02749 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-19.02750 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-19.02751 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| RGI60-19.02752 | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "True | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
215547 rows × 78 columns
\n", "