{ "cells": [ { "cell_type": "markdown", "id": "77967766-5722-4bbd-ac99-d14f79ec3441", "metadata": {}, "source": [ "# MESMER-m analysis (simple provide-region plots)\n", "- always using common running glaciers" ] }, { "cell_type": "code", "execution_count": 4, "id": "e649fe0c-73bc-459d-a4b7-4740d27095bd", "metadata": {}, "outputs": [], "source": [ "import os\n", "import xarray as xr\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import seaborn as sns\n", "from func_add_mesmer_m import gcms_mesmer, quantiles, scenarios\n", "import json\n", "import geopandas as gpd\n", "from oggm import utils\n", "# get the dataset where coordinates of glaciers are stored\n", "frgi = utils.file_downloader('https://cluster.klima.uni-bremen.de/~oggm/rgi/rgi62_stats.h5')\n", "#frgi = '/home/users/lschuster/glacierMIP/rgi62_stats.h5'\n", "odf = pd.read_hdf(frgi, index_col=0)" ] }, { "cell_type": "markdown", "id": "16e06423-b48c-46c8-ad59-d61feafc14c0", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 5, "id": "da28a01f-10ec-40b0-bf19-df1a3d15dff1", "metadata": {}, "outputs": [], "source": [ "# to get the climate files\n", "#for g in gcms_mesmer:\n", "# print(f'wget -r --user=climatechange --password=globalwarming 88.198.17.222:/mesmer-m-processed/mesmer-m-processed/{g}/glacier_modellers/')" ] }, { "cell_type": "code", "execution_count": 6, "id": "9d1d0e34-cc55-4a09-8556-77473a73dcb1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sbatch --array=1-92 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 1 2100\n", "sbatch --array=1-24 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 2 2100\n", "sbatch --array=1-39 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 3 2100\n", "sbatch --array=1-9 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 4 2100\n", "sbatch --array=1-6 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 5 2100\n", "sbatch --array=1-5 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 6 2100\n", "sbatch --array=1-8 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 7 2100\n", "sbatch --array=1-4 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 8 2100\n", "sbatch --array=1-197 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 9 2100\n", "sbatch --array=1-6 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 10 2100\n", "sbatch --array=1-32 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 11 2100\n", "sbatch --array=1-8 run_slurm_with_hydro_per_provide_reg_mesmer.slurm 12 2100\n" ] } ], "source": [ "### stuff to run onf cluster ... www_lschuster/provide/MESMER-M_projections/runs/run_slurm_with_hydro_per_provide_reg_mesmer.slurm\n", "n_glac_per_batch = 500\n", "#for preg in ['P04', 'P07']:\n", "for p in np.arange(1,12.1,1): # No P13 (i.e., antarctic periphery ...)\n", " p = int(p)\n", " preg = f'P{p:02d}'\n", " f = open('/home/www/lschuster/provide/provide_glacier_regions/rgi_ids_per_provide_region.json')\n", " rgis_preg = json.load(f)[preg]\n", " rgis_preg = list(set(rgis_preg)) # the IDs are not unique ... \n", " rgis_preg = np.sort(rgis_preg) # make sure that the RGIs are sorted ...\n", " if preg == 'P03': # omit connectiity level 2 from P03 (i.e., Greenland)\n", " odf_preg = odf.loc[rgis_preg]\n", " odf_preg_sel = odf_preg.loc[odf_preg['Connect'] != 2]\n", " rgis_preg = odf_preg_sel.index\n", "\n", " #print(provide_reg_full_name_dict_correct[preg], len(rgis_preg), p, preg)\n", " n_batches = int(np.ceil(len(rgis_preg)/n_glac_per_batch))\n", " print(f'sbatch --array=1-{n_batches} run_slurm_with_hydro_per_provide_reg_mesmer.slurm {p} 2100')\n", " #print('\\n')" ] }, { "cell_type": "code", "execution_count": 7, "id": "a2fbd082-fa6c-4ef8-9ce1-1eb1d99ba81f", "metadata": {}, "outputs": [], "source": [ "gcms_mesmer = [ # 'ACCESS-CM2', #NO precipitation data, # 'MCM-UA-1-0', no precipitation data\n", " 'ACCESS-ESM1-5', 'CESM2-WACCM', 'CESM2',\n", " 'CMCC-CM2-SR5', 'CNRM-CM6-1-HR', 'CNRM-CM6-1', 'CNRM-ESM2-1', 'CanESM5', 'E3SM-1-1',\n", " 'FGOALS-f3-L', 'FGOALS-g3', 'HadGEM3-GC31-LL', 'HadGEM3-GC31-MM', 'IPSL-CM6A-LR', \n", " 'MPI-ESM1-2-HR', 'MPI-ESM1-2-LR' , 'MRI-ESM2-0', 'NorESM2-LM', 'NorESM2-MM', 'UKESM1-0-LL']\n", "\n" ] }, { "cell_type": "code", "execution_count": 8, "id": "fedbbbca-c616-4409-9924-e9908a4b706b", "metadata": {}, "outputs": [], "source": [ "pd_provide_reg_full_name = gpd.read_file('/home/www/lschuster/provide/provide_glacier_regions/provide_glacier_regions.shp')\n", "pd_provide_reg_full_name.index = pd_provide_reg_full_name.provide_id\n", "provide_reg_full_name_dict = dict(pd_provide_reg_full_name['full_name'])\n", "provide_reg_full_name_dict['P06'] = 'East Asia'\n", "provide_reg_full_name_dict_correct = provide_reg_full_name_dict.copy()\n", "#provide_reg_full_name_dict_correct['P05'] = 'Svalbard, Jan Mayen\\nand Russian Arctic'\n", "#provide_reg_full_name_dict_correct['P13'] = 'Subantarctic and\\nAntarctic Islands'\n", "provide_reg_full_name_dict_correct['P09'] = 'High Mountain Asia' # need to rename that probably, but this is better than \"Central Asia\" as that is already the name for only RGI region 13\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "ea1aa65d-e6ab-4ccf-8746-6cddcd3b4764", "metadata": {}, "outputs": [], "source": [ "colors = {'0.05':'blue', '0.25':'cyan', '0.5':'black', '0.75':'orange', '0.95':'red'}" ] }, { "cell_type": "code", "execution_count": 10, "id": "e100a545-1b43-4ddb-8269-a53b1ba347ec", "metadata": {}, "outputs": [], "source": [ "path = '/home/www/lschuster/provide/MESMER-M_projections/runs/output/oggm_v16/2023.3/2100'" ] }, { "cell_type": "code", "execution_count": 14, "id": "8af4fcce-bbff-47b3-b29e-c29ead3765f1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1000\n" ] } ], "source": [ "# test if all files are there \n", "missing_f_reg = {}\n", "n_exps = len(gcms_mesmer) * len(scenarios)*len(quantiles)\n", "print(n_exps)\n", "for p in np.arange(1,12.1,1): # No P13 (i.e., antarctic periphery ...)\n", " p = int(p)\n", " preg = f'P{p:02d}'\n", " f = open('/home/www/lschuster/provide/provide_glacier_regions/rgi_ids_per_provide_region.json')\n", " rgis_preg = json.load(f)[preg]\n", " rgis_preg = list(set(rgis_preg)) # the IDs are not unique ... \n", " rgis_preg = np.sort(rgis_preg) # make sure that the RGIs are sorted ...\n", " if preg == 'P03': # omit connectiity level 2 from P03 (i.e., Greenland)\n", " odf_preg = odf.loc[rgis_preg]\n", " odf_preg_sel = odf_preg.loc[odf_preg['Connect'] != 2]\n", " rgis_preg = odf_preg_sel.index\n", " #print(provide_reg_full_name_dict_correct[preg], len(rgis_preg), p, preg)\n", " n_batches = int(np.ceil(len(rgis_preg)/n_glac_per_batch))\n", " try:\n", " assert n_exps == int(len(os.listdir(path+'/'+preg))/n_batches)\n", " except:\n", " print(preg, int(len(os.listdir(path+'/'+preg))/n_batches))\n", " \n", " missing_f_reg_l = []\n", "\n", " for j in np.arange(0,int(np.ceil(len(rgis_preg)/500)),1):\n", " ji= j*500\n", " je = (j+1)*500\n", " scenario = scenarios[-1]\n", " model = gcms_mesmer[-1]\n", " q = quantiles[-1]\n", " try:\n", " xr.open_dataset(f'{path}/{preg}/run_hydro_w5e5_gcm_merged_{scenario}_{model}_q{q}_bc_2000_2019_Batch_{ji}_{je}.nc')\n", " except:\n", " missing_f_reg_l.append(j+1) # array that has to be rerun\n", " #print(j+1)\n", " # test that should work at the end:\n", " assert len(missing_f_reg_l) == 0\n", " missing_f_reg[preg] = missing_f_reg_l\n", " " ] }, { "cell_type": "code", "execution_count": 15, "id": "176b1ec4-5ef3-456b-b641-264734c035a2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'P01': [],\n", " 'P02': [],\n", " 'P03': [],\n", " 'P04': [],\n", " 'P05': [],\n", " 'P06': [],\n", " 'P07': [],\n", " 'P08': [],\n", " 'P09': [],\n", " 'P10': [],\n", " 'P11': [],\n", " 'P12': []}" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "missing_f_reg" ] }, { "cell_type": "code", "execution_count": 12, "id": "c40be62d-9b60-413c-8e7d-deea0ea7ffdb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (time: 102, rgi_id: 500, month_2d: 12)\n",
"Coordinates:\n",
" * time (time) float64 2e+03 2.001e+03 ... 2.101e+03\n",
" * rgi_id (rgi_id) object 'RGI60-01.00001' ... 'RGI60...\n",
" hydro_year (time) int64 2000 2001 2002 ... 2099 2100 2101\n",
" hydro_month (time) int64 4 4 4 4 4 4 4 4 ... 4 4 4 4 4 4 4\n",
" calendar_year (time) int64 2000 2001 2002 ... 2099 2100 2101\n",
" calendar_month (time) int64 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1\n",
" * month_2d (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n",
" calendar_month_2d (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n",
"Data variables: (12/22)\n",
" volume (time, rgi_id) float32 7.034e+06 ... 0.0\n",
" volume_bsl (time, rgi_id) float32 0.0 0.0 0.0 ... 0.0 0.0\n",
" volume_bwl (time, rgi_id) float32 0.0 0.0 0.0 ... 0.0 0.0\n",
" area (time, rgi_id) float32 3.443e+05 ... 0.0\n",
" length (time, rgi_id) float32 792.0 1.4e+03 ... 0.0\n",
" off_area (time, rgi_id) float32 3.097e-09 ... nan\n",
" ... ...\n",
" liq_prcp_on_glacier_monthly (time, month_2d, rgi_id) float32 ...\n",
" snowfall_off_glacier_monthly (time, month_2d, rgi_id) float32 ...\n",
" snowfall_on_glacier_monthly (time, month_2d, rgi_id) float32 ...\n",
" water_level (rgi_id) float32 0.0 0.0 0.0 ... 0.0 0.0 0.0\n",
" glen_a (rgi_id) float32 7.607e-24 ... 7.727e-24\n",
" fs (rgi_id) float32 0.0 0.0 0.0 ... 0.0 0.0 0.0\n",
"Attributes:\n",
" description: OGGM model output\n",
" oggm_version: 1.6.1\n",
" calendar: 365-day no leap\n",
" creation_date: 2024-01-19 21:30:45<xarray.DataArray 'volume' (scenario: 10, quantile: 5, gcm: 20, time: 102)>\n",
"[102000 values with dtype=float32]\n",
"Coordinates:\n",
" * time (time) float64 2e+03 2.001e+03 ... 2.1e+03 2.101e+03\n",
" hydro_year (time) int64 2000 2001 2002 2003 ... 2098 2099 2100 2101\n",
" hydro_month (time) int64 4 4 4 4 4 4 4 4 4 4 4 ... 4 4 4 4 4 4 4 4 4 4 4\n",
" calendar_year (time) int64 2000 2001 2002 2003 ... 2098 2099 2100 2101\n",
" calendar_month (time) int64 1 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 1\n",
" * gcm (gcm) object 'ACCESS-ESM1-5' 'CESM2-WACCM' ... 'UKESM1-0-LL'\n",
" * quantile (quantile) object '0.05' '0.25' '0.5' '0.75' '0.95'\n",
" * scenario (scenario) object 'CurPol' 'GS' ... 'ssp119' 'ssp534-over'\n",
"Attributes:\n",
" n_rgi_ids: 3927\n",
" n_rgi_ids_working: 3896\n",
" area_at_rgi_rgi_ids: 2092.1459999999997\n",
" area_at_rgi_rgi_ids_working: 2091.072