diff --git a/docs/learning/notebooks/making_a_nice_table_for_michael.ipynb b/docs/learning/notebooks/making_a_nice_table_for_michael.ipynb new file mode 100644 index 0000000..414f9b9 --- /dev/null +++ b/docs/learning/notebooks/making_a_nice_table_for_michael.ipynb @@ -0,0 +1,2683 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a3c14f42-3116-428d-9103-85198c40d34b", + "metadata": {}, + "source": [ + "# Making a nice table " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "72775985-b77d-4217-9ac5-bb2ae989e433", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import xarray as xr\n", + "xr.set_options(display_style='html')\n", + "import intake\n", + "import cftime\n", + "import matplotlib.pyplot as plt\n", + "import cartopy.crs as ccrs\n", + "import numpy as np\n", + "import pandas as pd\n", + "import datetime\n", + "import seaborn as sns" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "8f12259a-c66c-4257-8f94-b5131336e8c0", + "metadata": {}, + "outputs": [], + "source": [ + "def global_mean(ds):\n", + " if 'lat' in ds:\n", + " la = 'lat'\n", + " lo = 'lon'\n", + " weights = np.cos(np.deg2rad(ds.lat))\n", + " elif 'latitude' in ds:\n", + " weights = np.cos(np.deg2rad(ds.latitude))\n", + " la = 'latitude'\n", + " lo = 'longitude'\n", + " else:\n", + " weights = np.cos(np.deg2rad(ds.lat))\n", + " \n", + " return ds.weighted(weights).mean(la)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "002f95b0-bc05-4072-9c48-5544a3d63c77", + "metadata": { + "tags": [] + }, + "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", + "
variable_idtable_idsource_idexperiment_idmember_idgrid_labeltime_rangeactivity_idinstitution_idversionpathdcpp_init_year
0tasAmonCanESM5-1historicalr1i1p1f1gn185001-201412CMIPCCCmav20190429/mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/CC...NaN
1cltAmonE3SM-1-0historicalr1i1p1f1gr185001-187412CMIPE3SM-Projectv20190913/mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3...NaN
2cltAmonE3SM-1-0historicalr1i1p1f1gr187501-189912CMIPE3SM-Projectv20190913/mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3...NaN
3cltAmonE3SM-1-0historicalr1i1p1f1gr190001-192412CMIPE3SM-Projectv20190913/mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3...NaN
4cltAmonE3SM-1-0historicalr1i1p1f1gr192501-194912CMIPE3SM-Projectv20190913/mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3...NaN
\n", + "
" + ], + "text/plain": [ + " variable_id table_id source_id experiment_id member_id grid_label \\\n", + "0 tas Amon CanESM5-1 historical r1i1p1f1 gn \n", + "1 clt Amon E3SM-1-0 historical r1i1p1f1 gr \n", + "2 clt Amon E3SM-1-0 historical r1i1p1f1 gr \n", + "3 clt Amon E3SM-1-0 historical r1i1p1f1 gr \n", + "4 clt Amon E3SM-1-0 historical r1i1p1f1 gr \n", + "\n", + " time_range activity_id institution_id version \\\n", + "0 185001-201412 CMIP CCCma v20190429 \n", + "1 185001-187412 CMIP E3SM-Project v20190913 \n", + "2 187501-189912 CMIP E3SM-Project v20190913 \n", + "3 190001-192412 CMIP E3SM-Project v20190913 \n", + "4 192501-194912 CMIP E3SM-Project v20190913 \n", + "\n", + " path dcpp_init_year \n", + "0 /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/CC... NaN \n", + "1 /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3... NaN \n", + "2 /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3... NaN \n", + "3 /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3... NaN \n", + "4 /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/CMIP/E3... NaN " + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#cat_url = \"https://storage.googleapis.com/cmip6/pangeo-cmip6.json\"\n", + "#cat_url = \"/mnt/craas1-ns9989k-geo4992/data/cmip6.json\"\n", + "cat_url = '/mnt/craas1-ns9989k-geo4992/data/catalogs/cmip6.json'\n", + "col = intake.open_esm_datastore(cat_url)\n", + "col\n", + "varl = ['tas','clt']\n", + "\n", + "models = ['CESM2','CanESM5-1','EC-Earth3-Veg-LR','GISS-E2-2-H','E3SM-1-0']\n", + "cat = col.search(source_id = models, \n", + " experiment_id=['historical'], \n", + " table_id=['Amon',], \n", + " variable_id=varl, \n", + " member_id=['r1i1p1f1'],\n", + " )\n", + "cat.df.head()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "0a2ee2ab-4ac7-4e19-a833-3dec2dddaf24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['CanESM5-1', 'E3SM-1-0', 'EC-Earth3-Veg-LR', 'GISS-E2-2-H',\n", + " 'CESM2'], dtype=object)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat.df['source_id'].unique()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "f9c02c24-763c-4bfe-915d-cd51433b7285", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['activity_id', 'experiment_id', 'source_id', 'table_id', 'grid_label']" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cat.esmcat.aggregation_control.groupby_attrs = ['activity_id','experiment_id', 'source_id','table_id','grid_label']\n", + "cat.esmcat.aggregation_control.groupby_attrs" + ] + }, + { + "cell_type": "markdown", + "id": "91058183-9ced-4f4c-bba1-844dbeca0cd4", + "metadata": {}, + "source": [ + "### Create dictionary from the list of datasets we found\n", + "- This step may take several minutes so be patient!" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "e6d44011-694b-4dc5-931e-b923ac0edf5f", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--> The keys in the returned dictionary of datasets are constructed as follows:\n", + "\t'activity_id.experiment_id.source_id.table_id.grid_label'\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + "
\n", + " \n", + " 100.00% [5/5 00:30<00:00]\n", + "
\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/opt/conda/envs/pangeo-notebook/lib/python3.11/site-packages/xarray/conventions.py:286: SerializationWarning: variable 'clt' has multiple fill values {1e+20, 1e+20} defined, decoding all values to NaN.\n", + " var = coder.decode(var, name=name)\n", + "/opt/conda/envs/pangeo-notebook/lib/python3.11/site-packages/xarray/conventions.py:286: SerializationWarning: variable 'tas' has multiple fill values {1e+20, 1e+20} defined, decoding all values to NaN.\n", + " var = coder.decode(var, name=name)\n" + ] + } + ], + "source": [ + "dset_dict = cat.to_dataset_dict(zarr_kwargs={'use_cftime':True})" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "6b7dcb7e-b89b-4709-b046-0345e40235dc", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "['CMIP.historical.CanESM5-1.Amon.gn',\n", + " 'CMIP.historical.GISS-E2-2-H.Amon.gn',\n", + " 'CMIP.historical.CESM2.Amon.gn',\n", + " 'CMIP.historical.E3SM-1-0.Amon.gr',\n", + " 'CMIP.historical.EC-Earth3-Veg-LR.Amon.gr']" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(dset_dict.keys())" + ] + }, + { + "cell_type": "markdown", + "id": "e60a8de2-cc32-4dbc-a5e9-3a3436901c6d", + "metadata": {}, + "source": [ + "### simplify keys:" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "757e956e-c607-49d6-a04c-17cd412dd108", + "metadata": {}, + "outputs": [], + "source": [ + "ds_dict = {}\n", + "for k in dset_dict.keys():\n", + " mod = k.split('.')[2]\n", + " ds_dict[mod] = dset_dict[k]" + ] + }, + { + "cell_type": "markdown", + "id": "1680308a-cf31-42fb-8090-7533885eeb43", + "metadata": {}, + "source": [ + "## Compute global mean (replace by whatever you want to calculate)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "38224fb5-ecd0-4ecf-80fe-b2127febfecf", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset> Size: 65MB\n",
+       "Dimensions:    (time: 1980, bnds: 2, lat: 64, lon: 128, member_id: 1)\n",
+       "Coordinates:\n",
+       "  * time       (time) object 16kB 1850-01-16 12:00:00 ... 2014-12-16 12:00:00\n",
+       "  * lat        (lat) float64 512B -87.86 -85.1 -82.31 ... 82.31 85.1 87.86\n",
+       "  * lon        (lon) float64 1kB 0.0 2.812 5.625 8.438 ... 351.6 354.4 357.2\n",
+       "    height     float64 8B ...\n",
+       "  * member_id  (member_id) object 8B 'r1i1p1f1'\n",
+       "Dimensions without coordinates: bnds\n",
+       "Data variables:\n",
+       "    time_bnds  (time, bnds) object 32kB dask.array<chunksize=(1, 2), meta=np.ndarray>\n",
+       "    lat_bnds   (lat, bnds) float64 1kB dask.array<chunksize=(64, 2), meta=np.ndarray>\n",
+       "    lon_bnds   (lon, bnds) float64 2kB dask.array<chunksize=(128, 2), meta=np.ndarray>\n",
+       "    tas        (member_id, time, lat, lon) float32 65MB dask.array<chunksize=(1, 1, 64, 128), meta=np.ndarray>\n",
+       "Attributes: (12/67)\n",
+       "    CCCma_model_hash:                 c8708a7ff559a1daeee0b713f94508a26a04c6b7\n",
+       "    CCCma_parent_runid:               v510b-pict\n",
+       "    CCCma_pycmor_hash:                0db7dba6172f1fb31dd9a4af1ae40a53189337ea\n",
+       "    CCCma_runid:                      v5.1-histens-01\n",
+       "    Conventions:                      CF-1.7 CMIP-6.2\n",
+       "    YMDH_branch_time_in_child:        1850:01:01:00\n",
+       "    ...                               ...\n",
+       "    intake_esm_attrs:activity_id:     CMIP\n",
+       "    intake_esm_attrs:institution_id:  CCCma\n",
+       "    intake_esm_attrs:version:         v20190429\n",
+       "    intake_esm_attrs:path:            /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/...\n",
+       "    intake_esm_attrs:_data_format_:   netcdf\n",
+       "    intake_esm_dataset_key:           CMIP.historical.CanESM5-1.Amon.gn
" + ], + "text/plain": [ + " Size: 65MB\n", + "Dimensions: (time: 1980, bnds: 2, lat: 64, lon: 128, member_id: 1)\n", + "Coordinates:\n", + " * time (time) object 16kB 1850-01-16 12:00:00 ... 2014-12-16 12:00:00\n", + " * lat (lat) float64 512B -87.86 -85.1 -82.31 ... 82.31 85.1 87.86\n", + " * lon (lon) float64 1kB 0.0 2.812 5.625 8.438 ... 351.6 354.4 357.2\n", + " height float64 8B ...\n", + " * member_id (member_id) object 8B 'r1i1p1f1'\n", + "Dimensions without coordinates: bnds\n", + "Data variables:\n", + " time_bnds (time, bnds) object 32kB dask.array\n", + " lat_bnds (lat, bnds) float64 1kB dask.array\n", + " lon_bnds (lon, bnds) float64 2kB dask.array\n", + " tas (member_id, time, lat, lon) float32 65MB dask.array\n", + "Attributes: (12/67)\n", + " CCCma_model_hash: c8708a7ff559a1daeee0b713f94508a26a04c6b7\n", + " CCCma_parent_runid: v510b-pict\n", + " CCCma_pycmor_hash: 0db7dba6172f1fb31dd9a4af1ae40a53189337ea\n", + " CCCma_runid: v5.1-histens-01\n", + " Conventions: CF-1.7 CMIP-6.2\n", + " YMDH_branch_time_in_child: 1850:01:01:00\n", + " ... ...\n", + " intake_esm_attrs:activity_id: CMIP\n", + " intake_esm_attrs:institution_id: CCCma\n", + " intake_esm_attrs:version: v20190429\n", + " intake_esm_attrs:path: /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/...\n", + " intake_esm_attrs:_data_format_: netcdf\n", + " intake_esm_dataset_key: CMIP.historical.CanESM5-1.Amon.gn" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "_ds" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "e4704f8a-64b2-4fbf-b223-bbf62db6c90b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
<xarray.Dataset> Size: 65MB\n",
+       "Dimensions:    (time: 1980, bnds: 2, lat: 64, lon: 128, member_id: 1)\n",
+       "Coordinates:\n",
+       "  * time       (time) object 16kB 1850-01-16 12:00:00 ... 2014-12-16 12:00:00\n",
+       "  * lat        (lat) float64 512B -87.86 -85.1 -82.31 ... 82.31 85.1 87.86\n",
+       "  * lon        (lon) float64 1kB 0.0 2.812 5.625 8.438 ... 351.6 354.4 357.2\n",
+       "    height     float64 8B ...\n",
+       "  * member_id  (member_id) object 8B 'r1i1p1f1'\n",
+       "Dimensions without coordinates: bnds\n",
+       "Data variables:\n",
+       "    time_bnds  (time, bnds) object 32kB dask.array<chunksize=(1, 2), meta=np.ndarray>\n",
+       "    lat_bnds   (lat, bnds) float64 1kB dask.array<chunksize=(64, 2), meta=np.ndarray>\n",
+       "    lon_bnds   (lon, bnds) float64 2kB dask.array<chunksize=(128, 2), meta=np.ndarray>\n",
+       "    tas        (member_id, time, lat, lon) float32 65MB dask.array<chunksize=(1, 1, 64, 128), meta=np.ndarray>\n",
+       "Attributes: (12/67)\n",
+       "    CCCma_model_hash:                 c8708a7ff559a1daeee0b713f94508a26a04c6b7\n",
+       "    CCCma_parent_runid:               v510b-pict\n",
+       "    CCCma_pycmor_hash:                0db7dba6172f1fb31dd9a4af1ae40a53189337ea\n",
+       "    CCCma_runid:                      v5.1-histens-01\n",
+       "    Conventions:                      CF-1.7 CMIP-6.2\n",
+       "    YMDH_branch_time_in_child:        1850:01:01:00\n",
+       "    ...                               ...\n",
+       "    intake_esm_attrs:activity_id:     CMIP\n",
+       "    intake_esm_attrs:institution_id:  CCCma\n",
+       "    intake_esm_attrs:version:         v20190429\n",
+       "    intake_esm_attrs:path:            /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/...\n",
+       "    intake_esm_attrs:_data_format_:   netcdf\n",
+       "    intake_esm_dataset_key:           CMIP.historical.CanESM5-1.Amon.gn
" + ], + "text/plain": [ + " Size: 65MB\n", + "Dimensions: (time: 1980, bnds: 2, lat: 64, lon: 128, member_id: 1)\n", + "Coordinates:\n", + " * time (time) object 16kB 1850-01-16 12:00:00 ... 2014-12-16 12:00:00\n", + " * lat (lat) float64 512B -87.86 -85.1 -82.31 ... 82.31 85.1 87.86\n", + " * lon (lon) float64 1kB 0.0 2.812 5.625 8.438 ... 351.6 354.4 357.2\n", + " height float64 8B ...\n", + " * member_id (member_id) object 8B 'r1i1p1f1'\n", + "Dimensions without coordinates: bnds\n", + "Data variables:\n", + " time_bnds (time, bnds) object 32kB dask.array\n", + " lat_bnds (lat, bnds) float64 1kB dask.array\n", + " lon_bnds (lon, bnds) float64 2kB dask.array\n", + " tas (member_id, time, lat, lon) float32 65MB dask.array\n", + "Attributes: (12/67)\n", + " CCCma_model_hash: c8708a7ff559a1daeee0b713f94508a26a04c6b7\n", + " CCCma_parent_runid: v510b-pict\n", + " CCCma_pycmor_hash: 0db7dba6172f1fb31dd9a4af1ae40a53189337ea\n", + " CCCma_runid: v5.1-histens-01\n", + " Conventions: CF-1.7 CMIP-6.2\n", + " YMDH_branch_time_in_child: 1850:01:01:00\n", + " ... ...\n", + " intake_esm_attrs:activity_id: CMIP\n", + " intake_esm_attrs:institution_id: CCCma\n", + " intake_esm_attrs:version: v20190429\n", + " intake_esm_attrs:path: /mnt/craas1-ns9989k-ns9560k/ESGF/CMIP6/...\n", + " intake_esm_attrs:_data_format_: netcdf\n", + " intake_esm_dataset_key: CMIP.historical.CanESM5-1.Amon.gn" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ds_dict[mod]" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "e1f22c7c-e2f2-4126-9db1-3b49020f6908", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CanESM5-1\n", + "GISS-E2-2-H\n", + "CESM2\n", + "E3SM-1-0\n", + "EC-Earth3-Veg-LR\n" + ] + } + ], + "source": [ + "ds_vals_mod_var = {}\n", + "for mod in ds_dict.keys():\n", + " print(mod)\n", + " ds_vals_mod_var[mod]=dict()\n", + " _ds = ds_dict[mod]\n", + " _ds_m = global_mean(_ds.sel(time=slice('1990','2015'))).mean()\n", + " for v in varl:\n", + " if v in _ds_m:\n", + " val = float(_ds_m[v].values)\n", + " ds_vals_mod_var[mod][v] = val\n", + " else:\n", + " ds_vals_mod_var[mod][v] = np.nan\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "7b99f917-256d-4285-a76d-5080523ccf7c", + "metadata": {}, + "outputs": [], + "source": [ + "ds_vals_mod_var_meas = {}\n", + "for mod in ds_dict.keys():\n", + " ds_vals_mod_var_meas[mod]=dict()\n", + " _ds = ds_dict[mod].copy()\n", + " meas = {}\n", + " \n", + " meas['mean'] = global_mean(_ds.sel(time=slice('1990','2015')).mean('lon').mean('time'))\n", + " meas['median']= global_mean(_ds.sel(time=slice('1990','2015')).mean('lon').median('time'))\n", + " meas['std'] = global_mean(_ds.sel(time=slice('1990','2015')).mean('lon').std('time'))\n", + " for v in varl:\n", + " ds_vals_mod_var_meas[mod][v] =dict()\n", + " for m in meas:\n", + " if v in meas[m]:\n", + " try:\n", + " ds_vals_mod_var_meas[mod][v][m] = float(meas[m][v].squeeze().values)\n", + " except:\n", + " ds_vals_mod_var_meas[mod][v][m] = np.nan\n", + " \n", + " else:\n", + " ds_vals_mod_var_meas[mod][v][m] = np.nan\n", + " " + ] + }, + { + "cell_type": "markdown", + "id": "963fe788-dc55-44fe-b3d3-dc7bc37ddb30", + "metadata": {}, + "source": [ + "## Extract units" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "0f3cdb98-9f3c-4205-a19b-d6e10931546b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
units
tasK
clt%
\n", + "
" + ], + "text/plain": [ + " units\n", + "tas K\n", + "clt %" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "_ds = ds_dict[models[0]]\n", + "u_dic = {v:_ds[v].units for v in varl}\n", + "units = pd.DataFrame.from_dict(u_dic,orient='index',columns=['units'] )#index=['units'])\n", + "\n", + "units" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "1618c668-fd95-4f93-af5e-42ecd8f7cce7", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "fcdc6ef4-c2a1-4939-bf8f-cfa37d92b214", + "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", + "
unitsCanESM5-1GISS-E2-2-HCESM2E3SM-1-0EC-Earth3-Veg-LR
tasK287.65NaN287.94287.47287.54
clt%NaNNaN69.7467.7864.10
\n", + "
" + ], + "text/plain": [ + " units CanESM5-1 GISS-E2-2-H CESM2 \\\n", + "tas K 287.65 NaN 287.94 \n", + "clt % NaN NaN 69.74 \n", + "\n", + " E3SM-1-0 EC-Earth3-Veg-LR \n", + "tas 287.47 287.54 \n", + "clt 67.78 64.10 " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df_nice =pd.DataFrame.from_dict(ds_vals_mod_var)\n", + "df_nice = pd.concat([units,df_nice], axis=1)\n", + "#pd.options.display.float_format = '{:20,.2f}'.format\n", + "pd.set_option('display.float_format','{:20,.2f}'.format)\n", + "display(df_nice)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "4a96d08c-69cb-4e6f-a263-56d065a91be9", + "metadata": {}, + "outputs": [], + "source": [ + "ls_meas = list()\n", + "for m in ds_vals_mod_var_meas:\n", + " _df = pd.DataFrame.from_dict(ds_vals_mod_var_meas[m])\n", + " _df['model']=m\n", + " ls_meas.append(_df)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "70ae7434-5a90-4bea-b217-7d6494732bdf", + "metadata": {}, + "outputs": [], + "source": [ + "df_out = pd.concat(ls_meas).reset_index().sort_values('index').set_index(['index','model'])" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "9622c00a-946b-4f1c-8488-62e287f9d475", + "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", + "
tasclt
indexmodel
meanCanESM5-1287.65NaN
GISS-E2-2-HNaNNaN
CESM2287.9469.74
E3SM-1-0287.4767.78
EC-Earth3-Veg-LR287.5464.10
medianCanESM5-1287.47NaN
GISS-E2-2-HNaNNaN
CESM2287.9270.04
E3SM-1-0287.3568.22
EC-Earth3-Veg-LR287.2964.48
stdCanESM5-13.70NaN
GISS-E2-2-HNaNNaN
CESM23.475.73
E3SM-1-03.615.48
EC-Earth3-Veg-LR3.656.35
\n", + "
" + ], + "text/plain": [ + " tas clt\n", + "index model \n", + "mean CanESM5-1 287.65 NaN\n", + " GISS-E2-2-H NaN NaN\n", + " CESM2 287.94 69.74\n", + " E3SM-1-0 287.47 67.78\n", + " EC-Earth3-Veg-LR 287.54 64.10\n", + "median CanESM5-1 287.47 NaN\n", + " GISS-E2-2-H NaN NaN\n", + " CESM2 287.92 70.04\n", + " E3SM-1-0 287.35 68.22\n", + " EC-Earth3-Veg-LR 287.29 64.48\n", + "std CanESM5-1 3.70 NaN\n", + " GISS-E2-2-H NaN NaN\n", + " CESM2 3.47 5.73\n", + " E3SM-1-0 3.61 5.48\n", + " EC-Earth3-Veg-LR 3.65 6.35" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pd.set_option('display.float_format','{:20,.2f}'.format)\n", + "\n", + "df_out" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "c4c45620-d1fe-4bd8-a247-854cf61fddaa", + "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", + "
indexmeanmedianstd
modelCanESM5-1GISS-E2-2-HCESM2E3SM-1-0EC-Earth3-Veg-LRCanESM5-1GISS-E2-2-HCESM2E3SM-1-0EC-Earth3-Veg-LRCanESM5-1GISS-E2-2-HCESM2E3SM-1-0EC-Earth3-Veg-LR
tas287.65NaN287.94287.47287.54287.47NaN287.92287.35287.293.70NaN3.473.613.65
cltNaNNaN69.7467.7864.10NaNNaN70.0468.2264.48NaNNaN5.735.486.35
\n", + "
" + ], + "text/plain": [ + "index mean \\\n", + "model CanESM5-1 GISS-E2-2-H CESM2 \n", + "tas 287.65 NaN 287.94 \n", + "clt NaN NaN 69.74 \n", + "\n", + "index median \\\n", + "model E3SM-1-0 EC-Earth3-Veg-LR CanESM5-1 \n", + "tas 287.47 287.54 287.47 \n", + "clt 67.78 64.10 NaN \n", + "\n", + "index \\\n", + "model GISS-E2-2-H CESM2 E3SM-1-0 \n", + "tas NaN 287.92 287.35 \n", + "clt NaN 70.04 68.22 \n", + "\n", + "index std \\\n", + "model EC-Earth3-Veg-LR CanESM5-1 GISS-E2-2-H \n", + "tas 287.29 3.70 NaN \n", + "clt 64.48 NaN NaN \n", + "\n", + "index \n", + "model CESM2 E3SM-1-0 EC-Earth3-Veg-LR \n", + "tas 3.47 3.61 3.65 \n", + "clt 5.73 5.48 6.35 " + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_out.T\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0df46de1-c00a-4e84-bafd-226a59fd7668", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:pangeo-notebook]", + "language": "python", + "name": "conda-env-pangeo-notebook-py" + }, + "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.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}