{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CESM2-WACCM_ssp126CESM2-WACCM_ssp370CESM2-WACCM_ssp585CESM2-WACCM_ssp245CESM2-WACCM_ssp534-overMPI-ESM1-2-HR_ssp585MPI-ESM1-2-HR_ssp370MPI-ESM1-2-HR_ssp245MPI-ESM1-2-HR_ssp126GFDL-ESM4_ssp370...gfdl-esm4_r1i1p1f1_ssp585mpi-esm1-2-hr_r1i1p1f1_ssp126mpi-esm1-2-hr_r1i1p1f1_ssp370mpi-esm1-2-hr_r1i1p1f1_ssp585mri-esm2-0_r1i1p1f1_ssp126mri-esm2-0_r1i1p1f1_ssp370mri-esm2-0_r1i1p1f1_ssp585ipsl-cm6a-lr_r1i1p1f1_ssp126ipsl-cm6a-lr_r1i1p1f1_ssp370ipsl-cm6a-lr_r1i1p1f1_ssp585
rgiid
RGI60-01.00001TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-01.00002TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-01.00003TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-01.00004TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-01.00005TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
..................................................................
RGI60-19.02748TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-19.02749TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-19.02750TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-19.02751TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
RGI60-19.02752TrueTrueTrueTrueTrueTrueTrueTrueTrueTrue...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "

215547 rows × 78 columns

\n", "
" ], "text/plain": [ " CESM2-WACCM_ssp126 CESM2-WACCM_ssp370 CESM2-WACCM_ssp585 \\\n", "rgiid \n", "RGI60-01.00001 True True True \n", "RGI60-01.00002 True True True \n", "RGI60-01.00003 True True True \n", "RGI60-01.00004 True True True \n", "RGI60-01.00005 True True True \n", "... ... ... ... \n", "RGI60-19.02748 True True True \n", "RGI60-19.02749 True True True \n", "RGI60-19.02750 True True True \n", "RGI60-19.02751 True True True \n", "RGI60-19.02752 True True True \n", "\n", " CESM2-WACCM_ssp245 CESM2-WACCM_ssp534-over \\\n", "rgiid \n", "RGI60-01.00001 True True \n", "RGI60-01.00002 True True \n", "RGI60-01.00003 True True \n", "RGI60-01.00004 True True \n", "RGI60-01.00005 True True \n", "... ... ... \n", "RGI60-19.02748 True True \n", "RGI60-19.02749 True True \n", "RGI60-19.02750 True True \n", "RGI60-19.02751 True True \n", "RGI60-19.02752 True True \n", "\n", " MPI-ESM1-2-HR_ssp585 MPI-ESM1-2-HR_ssp370 MPI-ESM1-2-HR_ssp245 \\\n", "rgiid \n", "RGI60-01.00001 True True True \n", "RGI60-01.00002 True True True \n", "RGI60-01.00003 True True True \n", "RGI60-01.00004 True True True \n", "RGI60-01.00005 True True True \n", "... ... ... ... \n", "RGI60-19.02748 True True True \n", "RGI60-19.02749 True True True \n", "RGI60-19.02750 True True True \n", "RGI60-19.02751 True True True \n", "RGI60-19.02752 True True True \n", "\n", " MPI-ESM1-2-HR_ssp126 GFDL-ESM4_ssp370 ... \\\n", "rgiid ... \n", "RGI60-01.00001 True True ... \n", "RGI60-01.00002 True True ... \n", "RGI60-01.00003 True True ... \n", "RGI60-01.00004 True True ... \n", "RGI60-01.00005 True True ... \n", "... ... ... ... \n", "RGI60-19.02748 True True ... \n", "RGI60-19.02749 True True ... \n", "RGI60-19.02750 True True ... \n", "RGI60-19.02751 True True ... \n", "RGI60-19.02752 True True ... \n", "\n", " gfdl-esm4_r1i1p1f1_ssp585 mpi-esm1-2-hr_r1i1p1f1_ssp126 \\\n", "rgiid \n", "RGI60-01.00001 NaN NaN \n", "RGI60-01.00002 NaN NaN \n", "RGI60-01.00003 NaN NaN \n", "RGI60-01.00004 NaN NaN \n", "RGI60-01.00005 NaN NaN \n", "... ... ... \n", "RGI60-19.02748 NaN NaN \n", "RGI60-19.02749 NaN NaN \n", "RGI60-19.02750 NaN NaN \n", "RGI60-19.02751 NaN NaN \n", "RGI60-19.02752 NaN NaN \n", "\n", " mpi-esm1-2-hr_r1i1p1f1_ssp370 mpi-esm1-2-hr_r1i1p1f1_ssp585 \\\n", "rgiid \n", "RGI60-01.00001 NaN NaN \n", "RGI60-01.00002 NaN NaN \n", "RGI60-01.00003 NaN NaN \n", "RGI60-01.00004 NaN NaN \n", "RGI60-01.00005 NaN NaN \n", "... ... ... \n", "RGI60-19.02748 NaN NaN \n", "RGI60-19.02749 NaN NaN \n", "RGI60-19.02750 NaN NaN \n", "RGI60-19.02751 NaN NaN \n", "RGI60-19.02752 NaN NaN \n", "\n", " mri-esm2-0_r1i1p1f1_ssp126 mri-esm2-0_r1i1p1f1_ssp370 \\\n", "rgiid \n", "RGI60-01.00001 NaN NaN \n", "RGI60-01.00002 NaN NaN \n", "RGI60-01.00003 NaN NaN \n", "RGI60-01.00004 NaN NaN \n", "RGI60-01.00005 NaN NaN \n", "... ... ... \n", "RGI60-19.02748 NaN NaN \n", "RGI60-19.02749 NaN NaN \n", "RGI60-19.02750 NaN NaN \n", "RGI60-19.02751 NaN NaN \n", "RGI60-19.02752 NaN NaN \n", "\n", " mri-esm2-0_r1i1p1f1_ssp585 ipsl-cm6a-lr_r1i1p1f1_ssp126 \\\n", "rgiid \n", "RGI60-01.00001 NaN NaN \n", "RGI60-01.00002 NaN NaN \n", "RGI60-01.00003 NaN NaN \n", "RGI60-01.00004 NaN NaN \n", "RGI60-01.00005 NaN NaN \n", "... ... ... \n", "RGI60-19.02748 NaN NaN \n", "RGI60-19.02749 NaN NaN \n", "RGI60-19.02750 NaN NaN \n", "RGI60-19.02751 NaN NaN \n", "RGI60-19.02752 NaN NaN \n", "\n", " ipsl-cm6a-lr_r1i1p1f1_ssp370 ipsl-cm6a-lr_r1i1p1f1_ssp585 \n", "rgiid \n", "RGI60-01.00001 NaN NaN \n", "RGI60-01.00002 NaN NaN \n", "RGI60-01.00003 NaN NaN \n", "RGI60-01.00004 NaN NaN \n", "RGI60-01.00005 NaN NaN \n", "... ... ... \n", "RGI60-19.02748 NaN NaN \n", "RGI60-19.02749 NaN NaN \n", "RGI60-19.02750 NaN NaN \n", "RGI60-19.02751 NaN NaN \n", "RGI60-19.02752 NaN NaN \n", "\n", "[215547 rows x 78 columns]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd_working#.dropna()" ] }, { "cell_type": "code", "execution_count": 18, "id": "299490e7-7928-4389-9e79-431107a72b93", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['gfdl-esm4_r1i1p1f1_ssp126',\n", " 'gfdl-esm4_r1i1p1f1_ssp370',\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", " 'ukesm1-0-ll_r1i1p1f2_ssp126',\n", " 'ukesm1-0-ll_r1i1p1f2_ssp370',\n", " 'ukesm1-0-ll_r1i1p1f2_ssp585']" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gcms_ssps_isimip3b" ] }, { "cell_type": "code", "execution_count": 19, "id": "7a02bf67-3fba-43d8-989a-84ea25ee8987", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "23\n", "22\n", "21\n", "26\n", "24\n", "22\n", "22\n", "22\n", "22\n", "23\n", "22\n", "21\n", "21\n", "21\n", "21\n", "2\n", "33\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "3\n", "27\n", "33\n", "36\n", "30\n", "37\n", "38\n", "36\n", "44\n", "52\n", "32\n", "34\n", "27\n", "21\n", "21\n", "21\n", "4\n", "23\n", "18\n", "18\n", "22\n", "18\n", "18\n", "14\n", "13\n", "17\n", "13\n", "15\n", "12\n", "12\n", "12\n", "13\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "7\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "9\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "10\n", "141\n", "138\n", "144\n", "140\n", "144\n", "138\n", "138\n", "138\n", "137\n", "139\n", "138\n", "137\n", "138\n", "138\n", "138\n", "11\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "12\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "13\n", "218\n", "217\n", "213\n", "221\n", "216\n", "211\n", "216\n", "211\n", "210\n", "217\n", "212\n", "214\n", "209\n", "209\n", "209\n", "14\n", "45\n", "47\n", "30\n", "53\n", "46\n", "31\n", "31\n", "31\n", "30\n", "36\n", "35\n", "33\n", "26\n", "27\n", "28\n", "15\n", "17\n", "16\n", "16\n", "19\n", "18\n", "17\n", "16\n", "16\n", "15\n", "16\n", "16\n", "16\n", "16\n", "14\n", "15\n", "16\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "17\n", "49\n", "45\n", "44\n", "50\n", "46\n", "47\n", "47\n", "44\n", "43\n", "46\n", "44\n", "44\n", "44\n", "42\n", "42\n", "18\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "19\n", "473\n", "467\n", "466\n", "469\n", "466\n", "465\n", "466\n", "464\n", "464\n", "472\n", "466\n", "467\n", "472\n", "467\n", "465\n", "5\n", "30\n", "24\n", "25\n", "36\n", "31\n", "35\n", "30\n", "24\n", "25\n", "31\n", "32\n", "31\n", "21\n", "20\n", "21\n", "_w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 215547\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", "1\n", "21\n", "21\n", "21\n", "22\n", "21\n", "21\n", "23\n", "22\n", "21\n", "21\n", "22\n", "21\n", "21\n", "21\n", "21\n", "2\n", "33\n", "34\n", "34\n", "33\n", "32\n", "33\n", "32\n", "32\n", "33\n", "32\n", "32\n", "32\n", "32\n", "32\n", "32\n", "3\n", "27\n", "28\n", "30\n", "28\n", "27\n", "32\n", "28\n", "33\n", "33\n", "25\n", "34\n", "29\n", "23\n", "22\n", "23\n", "4\n", "17\n", "15\n", "13\n", "12\n", "12\n", "14\n", "17\n", "14\n", "16\n", "12\n", "13\n", "12\n", "12\n", "12\n", "13\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "7\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "9\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "10\n", "140\n", "140\n", "140\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "137\n", "11\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "12\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "13\n", "229\n", "222\n", "217\n", "229\n", "222\n", "215\n", "218\n", "214\n", "213\n", "224\n", "215\n", "218\n", "215\n", "211\n", "211\n", "14\n", "41\n", "38\n", "34\n", "48\n", "33\n", "31\n", "31\n", "30\n", "29\n", "35\n", "33\n", "35\n", "28\n", "32\n", "29\n", "15\n", "18\n", "16\n", "16\n", "17\n", "19\n", "17\n", "16\n", "16\n", "15\n", "18\n", "18\n", "18\n", "16\n", "15\n", "16\n", "16\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "17\n", "51\n", "48\n", "45\n", "50\n", "48\n", "51\n", "49\n", "48\n", "48\n", "47\n", "47\n", "44\n", "49\n", "44\n", "44\n", "18\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "19\n", "468\n", "465\n", "465\n", "467\n", "466\n", "466\n", "468\n", "473\n", "465\n", "473\n", "469\n", "469\n", "481\n", "467\n", "464\n", "5\n", "52\n", "46\n", "45\n", "51\n", "34\n", "39\n", "36\n", "28\n", "27\n", "38\n", "38\n", "54\n", "26\n", "29\n", "29\n", "_bc_2000_2019_w5e5_gcm_merged\n", "Amount of glaciers that run over the entire time period: 215547\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", "1\n", "27\n", "27\n", "24\n", "29\n", "28\n", "28\n", "23\n", "20\n", "21\n", "29\n", "24\n", "24\n", "21\n", "21\n", "21\n", "2\n", "37\n", "37\n", "37\n", "32\n", "32\n", "32\n", "37\n", "37\n", "37\n", "33\n", "33\n", "33\n", "33\n", "33\n", "33\n", "3\n", "30\n", "33\n", "36\n", "32\n", "37\n", "38\n", "38\n", "44\n", "53\n", "33\n", "35\n", "30\n", "20\n", "21\n", "21\n", "4\n", "23\n", "18\n", "19\n", "25\n", "22\n", "22\n", "14\n", "15\n", "19\n", "14\n", "17\n", "16\n", "13\n", "11\n", "13\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "7\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "7\n", "7\n", "7\n", "10\n", "10\n", "10\n", "7\n", "7\n", "7\n", "8\n", "8\n", "7\n", "8\n", "8\n", "8\n", "9\n", "2\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "10\n", "144\n", "145\n", "145\n", "142\n", "145\n", "145\n", "143\n", "144\n", "143\n", "140\n", "142\n", "139\n", "138\n", "138\n", "137\n", "11\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "12\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "13\n", "215\n", "222\n", "208\n", "219\n", "209\n", "209\n", "211\n", "208\n", "207\n", "210\n", "209\n", "209\n", "205\n", "205\n", "205\n", "14\n", "45\n", "57\n", "40\n", "57\n", "51\n", "45\n", "37\n", "38\n", "34\n", "36\n", "32\n", "34\n", "38\n", "38\n", "39\n", "15\n", "16\n", "18\n", "15\n", "22\n", "19\n", "19\n", "17\n", "18\n", "18\n", "14\n", "14\n", "14\n", "15\n", "13\n", "13\n", "16\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "17\n", "47\n", "45\n", "43\n", "50\n", "46\n", "45\n", "48\n", "46\n", "46\n", "45\n", "43\n", "43\n", "43\n", "42\n", "41\n", "18\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "19\n", "477\n", "473\n", "475\n", "471\n", "471\n", "469\n", "469\n", "469\n", "470\n", "475\n", "469\n", "469\n", "474\n", "468\n", "468\n", "5\n", "36\n", "31\n", "34\n", "40\n", "37\n", "40\n", "36\n", "30\n", "31\n", "28\n", "37\n", "33\n", "20\n", "20\n", "20\n", "_gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 215547\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", "1\n", "21\n", "21\n", "21\n", "22\n", "21\n", "21\n", "23\n", "22\n", "21\n", "21\n", "22\n", "21\n", "21\n", "21\n", "22\n", "2\n", "38\n", "34\n", "34\n", "33\n", "32\n", "33\n", "39\n", "37\n", "39\n", "36\n", "35\n", "34\n", "40\n", "37\n", "34\n", "3\n", "26\n", "28\n", "30\n", "28\n", "27\n", "32\n", "28\n", "33\n", "33\n", "25\n", "35\n", "29\n", "23\n", "22\n", "23\n", "4\n", "17\n", "15\n", "13\n", "12\n", "12\n", "14\n", "18\n", "14\n", "16\n", "12\n", "13\n", "13\n", "12\n", "12\n", "13\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "7\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "7\n", "7\n", "7\n", "8\n", "8\n", "8\n", "8\n", "8\n", "8\n", "7\n", "7\n", "7\n", "9\n", "9\n", "9\n", "9\n", "2\n", "2\n", "3\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "10\n", "140\n", "140\n", "139\n", "138\n", "138\n", "138\n", "138\n", "138\n", "138\n", "139\n", "139\n", "139\n", "137\n", "138\n", "137\n", "11\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "5\n", "12\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "342\n", "13\n", "229\n", "222\n", "218\n", "230\n", "224\n", "216\n", "217\n", "212\n", "212\n", "222\n", "214\n", "218\n", "216\n", "214\n", "213\n", "14\n", "46\n", "41\n", "40\n", "48\n", "37\n", "35\n", "33\n", "33\n", "31\n", "40\n", "36\n", "39\n", "36\n", "38\n", "33\n", "15\n", "19\n", "16\n", "18\n", "19\n", "19\n", "17\n", "15\n", "15\n", "14\n", "19\n", "18\n", "18\n", "16\n", "15\n", "16\n", "16\n", "3\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "4\n", "3\n", "3\n", "3\n", "4\n", "4\n", "4\n", "4\n", "17\n", "54\n", "48\n", "48\n", "50\n", "48\n", "50\n", "52\n", "51\n", "51\n", "48\n", "49\n", "45\n", "52\n", "49\n", "48\n", "18\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "19\n", "469\n", "467\n", "467\n", "467\n", "467\n", "468\n", "471\n", "474\n", "466\n", "473\n", "471\n", "469\n", "482\n", "467\n", "467\n", "5\n", "53\n", "47\n", "45\n", "50\n", "35\n", "39\n", "35\n", "27\n", "26\n", "34\n", "36\n", "52\n", "28\n", "28\n", "30\n", "_bc_2000_2019_gcm_from_2000\n", "Amount of glaciers that run over the entire time period: 215547\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" ] } ], "source": [ "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['','_bc_2000_2019']:\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_isimip3b:\n", " gcm = gcm_ssp.split('_')[0]\n", " ssp = gcm_ssp.split('_')[-1]\n", "\n", " with xr.open_mfdataset(f'{dpath}/run_hydro_{hist}_endyr2100_ISIMIP3b_{gcm_ssp}{bc}_rgi{rgi_reg_s}*.nc') as ds:\n", " ds = ds.volume.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", " print(len(rgis_error))\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_ISIMIP3b{bc}_{hist}.csv')\n" ] }, { "cell_type": "markdown", "id": "696f0485-3485-4ef0-b9e9-f1421f8a2af8", "metadata": {}, "source": [ "### Common running glaciers working for all global experiments" ] }, { "cell_type": "code", "execution_count": 24, "id": "256c74ac-8082-4337-a940-c9fafc989663", "metadata": {}, "outputs": [], "source": [ "all_running_rgis_l = []\n", "for hist in ['w5e5_gcm_merged', 'gcm_from_2000']:\n", " for bc in ['_bc_2000_2019','_bc_1979_2014']:\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", "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_ISIMIP3b{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.csv')" ] }, { "cell_type": "code", "execution_count": null, "id": "cc6fcdae-03f0-4095-873a-a46d837e3d91", "metadata": {}, "outputs": [], "source": [ "print(len(pd_working_all)/len(pd_working))" ] }, { "cell_type": "code", "execution_count": null, "id": "6f54c6cf-ce6c-449b-b649-d1d16a03d10a", "metadata": {}, "outputs": [], "source": [ "print(pd_working_all.area.sum()/pd_working.area.sum())" ] }, { "cell_type": "code", "execution_count": null, "id": "e0147aaf-50fd-4268-b350-3a2840991247", "metadata": {}, "outputs": [], "source": [] } ], "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.12" } }, "nbformat": 4, "nbformat_minor": 5 }