{ "cells": [ { "cell_type": "markdown", "id": "a3f276bc-95d8-4fac-b896-3034680cb192", "metadata": {}, "source": [ "# Global glacier change in 2100 as a function of global GCM temperature\n", "- 1. vs GMT in 2100 (from Dave)\n", " - then recompute it (to know if I get the same estimates out)\n", " - use data from here: https://cluster.klima.uni-bremen.de/~oggm/cmip6/\n", "- 2. vs GMT in 2050 " ] }, { "cell_type": "code", "execution_count": 205, "id": "3812f98e-1caf-47e5-a7c4-4735015b9c62", "metadata": {}, "outputs": [], "source": [ "import os, numpy as np, pandas as pd\n", "import seaborn as sns\n", "import xarray as xr\n", "import matplotlib.pyplot as plt\n", "import scipy" ] }, { "cell_type": "markdown", "id": "b677918f-1a1a-4f0f-8bca-e96702f6f634", "metadata": {}, "source": [ "## Get temperature changes from CMIP6 data" ] }, { "cell_type": "code", "execution_count": 206, "id": "48985440-d302-4be2-b9f8-75f8922e925e", "metadata": {}, "outputs": [], "source": [ "### FROM DAVE:\n", "\n", "fpath = '/home/www/lschuster/rounce_2023_data/0_exploratory_data_analysis/'\n", "#also read in the global temperature change in 2100 relative to 1850-1900 data:\n", "pd_temp_ch_dr = pd.read_csv(fpath+'Global_mean_temp_deviation_2081_2100_rel_1850_1900.csv')\n", "pd_temp_ch_dr['gcm'] = [a.lower() for a in pd_temp_ch_dr['GCM']]\n", "pd_temp_ch_dr['gcm_ssp'] = pd_temp_ch_dr['gcm'] +'_'+pd_temp_ch_dr['Scenario']\n", "pd_temp_ch_dr =pd_temp_ch_dr.set_index('gcm_ssp')\n", "pd_temp_ch_dr = pd_temp_ch_dr[['global_mean_deviation_degC']]" ] }, { "cell_type": "code", "execution_count": 207, "id": "064b74bb-a81a-4bca-86d8-1b19f3ad9af4", "metadata": {}, "outputs": [], "source": [ "fpath_cmip6 = '/home/www/oggm/cmip6/'\n", "pd_gcm_list = pd.read_csv(fpath_cmip6+'all_gcm_list.csv', index_col='index')" ] }, { "cell_type": "code", "execution_count": 208, "id": "6bf5678c-1f7e-44cf-8ceb-380e8f364d95", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_2424679/1252063683.py:2: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " pd_gcm_tas['gcm'] = [a.lower() for a in pd_gcm_tas['gcm']]\n", "/tmp/ipykernel_2424679/1252063683.py:3: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", " pd_gcm_tas['gcm_ssp'] = pd_gcm_tas['gcm'] +'_'+pd_gcm_tas['ssp']\n" ] } ], "source": [ "pd_gcm_tas = pd_gcm_list.loc[pd_gcm_list['var'] == 'tas']\n", "pd_gcm_tas['gcm'] = [a.lower() for a in pd_gcm_tas['gcm']]\n", "pd_gcm_tas['gcm_ssp'] = pd_gcm_tas['gcm'] +'_'+pd_gcm_tas['ssp']\n", "pd_gcm_tas = pd_gcm_tas.set_index('gcm_ssp')\n", "# \"['ec-earth3_ssp119'] not in CMIP6 but in Dave's data ...\n", "common_gcms = list(set(pd_gcm_tas.index).intersection(pd_temp_ch_dr.index))\n", "pd_gcm_tas = pd_gcm_tas.loc[common_gcms]" ] }, { "cell_type": "code", "execution_count": 209, "id": "bc005428-399d-49a0-b826-9f84476c5db4", "metadata": {}, "outputs": [], "source": [ "load = False\n", "if load:\n", " period_l = []\n", " gmc_ssp_l = []\n", " temp_change_l = []\n", " temp_change_dr_l = []\n", " for gcm_ssp in common_gcms:\n", " ds = xr.open_dataset(pd_gcm_tas.loc[gcm_ssp].path)\n", " ds = ds.resample(time='1Y').mean()\n", " # Weight\n", " weight = np.cos(np.deg2rad(ds.lat.astype(np.float64))).clip(0)\n", " weight = ds.tas.isel(time=0) * 0. + weight\n", "\n", " ds['weight'] = (('lat', 'lon'), weight.values / weight.values.sum())\n", " gmt = (ds.tas* ds.weight).sum(dim=['lon','lat']) - 273.15 # from K to °C\n", " ref_period_avg = gmt.sel(time=slice(str(1986),str(2005))).mean()\n", "\n", " for exp_time in [2041, 2081]:\n", " exp_period_avg = gmt.sel(time=slice(str(exp_time), str(exp_time+19))).mean(dim='time')\n", " gmc_ssp_l.append(gcm_ssp)\n", " period_l.append(f'{str(exp_time)}-{str(exp_time+19)}')\n", " temp_change_l.append((exp_period_avg-ref_period_avg + 0.63).values)\n", " if exp_time == 2081:\n", " temp_change_dr_l.append(pd_temp_ch_dr.loc[gcm_ssp].values[0])\n", " else:\n", " temp_change_dr_l.append(np.NaN)\n", " pd_temp_ch_manual_extract = pd.DataFrame(index=gmc_ssp_l)\n", " pd_temp_ch_manual_extract['period'] = period_l\n", " pd_temp_ch_manual_extract['temp_change'] = temp_change_l\n", " pd_temp_ch_manual_extract['temp_change_dr'] = temp_change_dr_l\n", " pd_temp_ch_manual_extract.to_csv('global_temp_ch_gcms.csv')\n", "else:\n", " pd_temp_ch_manual_extract = pd.read_csv('global_temp_ch_gcms.csv', index_col=[0])\n", " # Ok, Dave's and my computations are almost equal\n", " _pd_temp = pd_temp_ch_manual_extract.loc[pd_temp_ch_manual_extract.period=='2081-2100']\n", " np.testing.assert_allclose(_pd_temp['temp_change'], _pd_temp['temp_change_dr'], rtol=0.001)\n", " # let's only look at my computations then\n", " pd_temp_ch = pd_temp_ch_manual_extract[['period', 'temp_change']]" ] }, { "cell_type": "code", "execution_count": 210, "id": "15076241-2c95-4428-bbf7-e1ded712e40f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | period | \n", "temp_change | \n", "
|---|---|---|
| bcc-csm2-mr_ssp126 | \n", "2041-2060 | \n", "1.827834 | \n", "
| bcc-csm2-mr_ssp126 | \n", "2081-2100 | \n", "1.737504 | \n", "
| inm-cm5-0_ssp370 | \n", "2041-2060 | \n", "2.049540 | \n", "
| inm-cm5-0_ssp370 | \n", "2081-2100 | \n", "3.240870 | \n", "
| cesm2-waccm_ssp245 | \n", "2041-2060 | \n", "2.372428 | \n", "
| ... | \n", "... | \n", "... | \n", "
| ec-earth3-veg_ssp126 | \n", "2081-2100 | \n", "2.120679 | \n", "
| inm-cm4-8_ssp370 | \n", "2041-2060 | \n", "1.913100 | \n", "
| inm-cm4-8_ssp370 | \n", "2081-2100 | \n", "3.219084 | \n", "
| mri-esm2-0_ssp585 | \n", "2041-2060 | \n", "2.629347 | \n", "
| mri-esm2-0_ssp585 | \n", "2081-2100 | \n", "4.542293 | \n", "
102 rows × 2 columns
\n", "