{ "cells": [ { "cell_type": "code", "execution_count": 5, "id": "0690ad59-8593-4b88-805d-93f37246d063", "metadata": {}, "outputs": [], "source": [ "end_yr = 2100" ] }, { "cell_type": "code", "execution_count": 78, "id": "21567acc-fce7-4aea-bd78-c63d4fd4aaad", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-05-12 10:09:51: oggm.cfg: Reading default parameters from the OGGM `params.cfg` configuration file.\n", "2023-05-12 10:09:51: oggm.cfg: Multiprocessing switched OFF according to the parameter file.\n", "2023-05-12 10:09:51: oggm.cfg: Multiprocessing: using all available processors (N=32)\n", "2023-05-12 10:09:51: oggm.cfg: PARAMS['border'] changed from `80` to `160`.\n", "2023-05-12 10:09:51: oggm.cfg: PARAMS['store_model_geometry'] changed from `False` to `True`.\n", "2023-05-12 10:09:51: oggm.workflow: init_glacier_directories from prepro level 5 on 1 glaciers.\n", "2023-05-12 10:09:51: oggm.workflow: Execute entity tasks [gdir_from_prepro] on 1 glaciers\n", "2023-05-12 10:09:51: oggm.cfg: PARAMS['store_diagnostic_variables'] changed from `['volume', 'volume_bsl', 'volume_bwl', 'area', 'length', 'calving', 'calving_rate', 'off_area', 'on_area', 'melt_off_glacier', 'melt_on_glacier', 'liq_prcp_off_glacier', 'liq_prcp_on_glacier', 'snowfall_off_glacier', 'snowfall_on_glacier']` to `['volume', 'volume_bsl', 'volume_bwl', 'area', 'length', 'calving', 'calving_rate', 'off_area', 'on_area', 'melt_off_glacier', 'melt_on_glacier', 'liq_prcp_off_glacier', 'liq_prcp_on_glacier', 'snowfall_off_glacier', 'snowfall_on_glacier', 'model_mb', 'residual_mb', 'snow_bucket']`.\n", "2023-05-12 10:09:54: oggm.utils: InvalidWorkflowError occurred during task merge_consecutive_run_outputs_merged_from_2000_run_CMIP6_CESM2-WACCM_ssp126_endyr2100_bc_2000_2019 on RGI60-01.16122: The two files seem incompatible by data on variable : volume_bwl_m3\n" ] }, { "ename": "InvalidWorkflowError", "evalue": "The two files seem incompatible by data on variable : volume_bwl_m3", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mInvalidWorkflowError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [78]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 81\u001b[0m process_cmip_data(gdir,filesuffix\u001b[38;5;241m=\u001b[39mrid\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_bc_2000_2019\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;66;03m# recognize the climate file for later\u001b[39;00m\n\u001b[1;32m 82\u001b[0m fpath_temp\u001b[38;5;241m=\u001b[39mft, \u001b[38;5;66;03m# temperature projections\u001b[39;00m\n\u001b[1;32m 83\u001b[0m fpath_precip\u001b[38;5;241m=\u001b[39mfp, \u001b[38;5;66;03m# precip projections\u001b[39;00m\n\u001b[1;32m 84\u001b[0m year_range\u001b[38;5;241m=\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2000\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2019\u001b[39m\u001b[38;5;124m'\u001b[39m),\n\u001b[1;32m 85\u001b[0m \u001b[38;5;66;03m#y0=2000-10,y1=2100+10,\u001b[39;00m\n\u001b[1;32m 86\u001b[0m );\n\u001b[1;32m 90\u001b[0m tasks\u001b[38;5;241m.\u001b[39mrun_with_hydro(gdir,\n\u001b[1;32m 91\u001b[0m run_task\u001b[38;5;241m=\u001b[39mtasks\u001b[38;5;241m.\u001b[39mrun_from_climate_data,\n\u001b[1;32m 92\u001b[0m ys\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2020\u001b[39m, \u001b[38;5;66;03m# this is important! Start from 2020 glacier\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;66;03m# add monthly diagnostics\u001b[39;00m\n\u001b[1;32m 105\u001b[0m store_monthly_hydro\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m);\n\u001b[0;32m--> 108\u001b[0m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmerge_consecutive_run_outputs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 109\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_filesuffix_1\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_historical_from_2000_run\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 110\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_filesuffix_2\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_future_run\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mrid\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 111\u001b[0m \u001b[43m \u001b[49m\u001b[43moutput_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_merged_from_2000_run\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mrid\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_endyr\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mend_yr\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 112\u001b[0m \u001b[43m \u001b[49m\u001b[43mdelete_input\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 113\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:491\u001b[0m, in \u001b[0;36mentity_task.__call__.._entity_task\u001b[0;34m(gdir, reset, print_log, return_value, continue_on_error, add_to_log_file, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m signal\u001b[38;5;241m.\u001b[39malarm(cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 490\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[0;32m--> 491\u001b[0m out \u001b[38;5;241m=\u001b[39m \u001b[43mtask_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 492\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m-\u001b[39m ex_t\n\u001b[1;32m 493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:1055\u001b[0m, in \u001b[0;36mmerge_consecutive_run_outputs\u001b[0;34m(gdir, input_filesuffix_1, input_filesuffix_2, output_filesuffix, delete_input)\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 1054\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ds2[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m-> 1055\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidWorkflowError(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe two files seem incompatible \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1056\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mby data on variable : \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mv\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 1057\u001b[0m bucket \u001b[38;5;241m=\u001b[39m ds1[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m 1058\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m:\n", "\u001b[0;31mInvalidWorkflowError\u001b[0m: The two files seem incompatible by data on variable : volume_bwl_m3" ] } ], "source": [ "import os\n", "import logging \n", "import sys\n", "\n", "# Libs\n", "import xarray as xr\n", "import pandas as pd\n", "import numpy as np\n", "import geopandas as gpd\n", "import matplotlib.pyplot as plt\n", "\n", "# Locals\n", "import oggm.cfg as cfg\n", "\n", "from oggm import utils, workflow, tasks\n", "\n", "# only after PR is accepted\n", "from oggm.shop.gcm_climate import process_cmip_data\n", "\n", "# Initialize OGGM and set up the default run parameters\n", "cfg.initialize(logging_level='ERROR')\n", "rgi_version = '62'\n", "\n", "cfg.PARAMS['border'] = 160 # changed for OGGM v16\n", "\n", "cfg.PARAMS['continue_on_error'] = False\n", "cfg.PARAMS['use_multiprocessing']=False\n", "cfg.PARAMS['store_model_geometry'] = True\n", " \n", "\n", "cfg.PATHS['working_dir'] = utils.gettempdir('OGGM_gcm_run', reset=False)\n", "\n", "\n", "rgi_reg = '17'\n", "\n", "\n", "# RGI glaciers \n", "rgi_ids = ['RGI60-01.16122']\n", "\n", "# Go - get the pre-processed glacier directories\n", "# TODO -> need to change the preprocessed directory here \n", "base_url = 'https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.6/L3-L5_files/2023.2/elev_bands/W5E5_spinup'\n", "# ole_v2023.1: base_url = 'https://cluster.klima.uni-bremen.de/~oggm/gdirs/oggm_v1.6/L3-L5_files/2023.1/elev_bands/W5E5_spinup'\n", "gdirs = workflow.init_glacier_directories(rgi_ids, from_prepro_level=5, prepro_border=160,\n", " prepro_base_url=base_url, prepro_rgi_version=rgi_version)\n", "\n", "ALL_DIAGS = ['volume', 'volume_bsl', 'volume_bwl',\n", " 'area', 'length', 'calving', 'calving_rate',\n", " 'off_area', 'on_area', 'melt_off_glacier',\n", " 'melt_on_glacier', 'liq_prcp_off_glacier', 'liq_prcp_on_glacier',\n", " 'snowfall_off_glacier', 'snowfall_on_glacier', 'model_mb',\n", " 'residual_mb', 'snow_bucket']\n", "# Add debug vars\n", "cfg.PARAMS['store_diagnostic_variables'] = ALL_DIAGS\n", "\n", "\n", "\n", " \n", "tasks.run_with_hydro(gdir, run_task=tasks.run_from_climate_data,\n", " climate_filename='climate_historical',\n", " ys=2000, init_model_yr=2000,\n", " store_monthly_hydro=True,\n", " init_model_filesuffix='_spinup_historical',\n", " ref_geometry_filesuffix='_spinup_historical',\n", " ref_area_yr = 2000,\n", " output_filesuffix='_historical_from_2000_run')\n", "\n", "gcms_cmip6 = pd.read_csv('/home/www/oggm/cmip6/all_gcm_list.csv', index_col=0)\n", "# take all gcms (can't say that we only want to process 2000-2100 ....\n", "for gcm in gcms_cmip6.gcm.unique()[:1]: ##TEST:\n", " df1 = gcms_cmip6.loc[gcms_cmip6.gcm == gcm]\n", " for ssp in df1.ssp.unique()[:1]:\n", " df2 = df1.loc[df1.ssp == ssp]\n", " assert len(df2) == 2\n", " ft = df2.loc[df2['var'] == 'tas'].iloc[0]\n", " fp = df2.loc[df2['var'] == 'pr'].iloc[0].path\n", " rid = ft.fname.replace('_r1i1p1f1_tas.nc', '')\n", " rid='_CMIP6_' + rid\n", " ft = ft.path\n", "\n", " process_cmip_data(gdir,filesuffix=rid+'_bc_2000_2019', # recognize the climate file for later\n", " fpath_temp=ft, # temperature projections\n", " fpath_precip=fp, # precip projections\n", " year_range=('2000', '2019'),\n", " #y0=2000-10,y1=2100+10,\n", " );\n", "\n", "\n", " \n", " tasks.run_with_hydro(gdir,\n", " run_task=tasks.run_from_climate_data,\n", " ys=2020, # this is important! Start from 2020 glacier\n", " ye=end_yr,\n", " # use gcm_data, not climate_historical\n", " climate_filename='gcm_data',\n", " # use the chosen scenario\n", " climate_input_filesuffix=rid+'_bc_2000_2019',\n", " # we start from the previous run, \n", " init_model_filesuffix='_historical_from_2000_run',\n", " ref_geometry_filesuffix='_historical_from_2000_run', \n", " ref_area_yr = 2000,\n", " # recognize the run for later\n", " output_filesuffix=f'_future_run{rid}'+'_bc_2000_2019',\n", " # add monthly diagnostics\n", " store_monthly_hydro=True);\n", "\n", "\n", "utils.merge_consecutive_run_outputs(gdir,\n", " input_filesuffix_1='_historical_from_2000_run',\n", " input_filesuffix_2=f'_future_run{rid}'+'_bc_2000_2019',\n", " output_filesuffix=f'_merged_from_2000_run{rid}_endyr{end_yr}_bc_2000_2019',\n", " delete_input=False,\n", " ) # we will delete that later" ] }, { "cell_type": "code", "execution_count": 79, "id": "8f9db756-2816-45d8-b4a1-c2428e248120", "metadata": {}, "outputs": [], "source": [ "df = xr.open_dataset(f'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/model_diagnostics_future_run{rid}'+'_bc_2000_2019.nc')\n", "dh = xr.open_dataset('/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/model_diagnostics_historical_from_2000_run.nc')" ] }, { "cell_type": "code", "execution_count": 82, "id": "d7eb8b99-a248-4034-aa1b-a1d65c4cebac", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.DataArray 'volume_bwl_m3' ()>\n",
       "array(2.916507e+09)\n",
       "Coordinates:\n",
       "    time            float64 2.02e+03\n",
       "    calendar_year   int64 2020\n",
       "    calendar_month  int64 1\n",
       "    hydro_year      int64 2020\n",
       "    hydro_month     int64 4\n",
       "Attributes:\n",
       "    description:  Glacier volume below water-level\n",
       "    unit:         m 3
" ], "text/plain": [ "\n", "array(2.916507e+09)\n", "Coordinates:\n", " time float64 2.02e+03\n", " calendar_year int64 ...\n", " calendar_month int64 ...\n", " hydro_year int64 ...\n", " hydro_month int64 ...\n", "Attributes:\n", " description: Glacier volume below water-level\n", " unit: m 3" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dh.volume_bwl_m3.sel(time=2020), \n" ] }, { "cell_type": "code", "execution_count": 81, "id": "f8e56c38-24e7-4b93-8731-927fcb56b008", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.DataArray 'volume_bwl_m3' (time: 81)>\n",
       "array([2.029594e+09, 2.029594e+09, 2.029594e+09, 2.029594e+09, 2.023112e+09,\n",
       "       2.016336e+09, 2.006386e+09, 2.000814e+09, 1.991653e+09, 1.982263e+09,\n",
       "       1.970191e+09, 1.960187e+09, 1.948230e+09, 1.935669e+09, 1.917310e+09,\n",
       "       1.899247e+09, 1.878210e+09, 1.854544e+09, 1.824109e+09, 1.789316e+09,\n",
       "       1.757660e+09, 1.723041e+09, 1.693973e+09, 1.664198e+09, 1.635968e+09,\n",
       "       1.602742e+09, 1.572505e+09, 1.531707e+09, 1.496572e+09, 1.452187e+09,\n",
       "       1.422061e+09, 1.378542e+09, 1.333578e+09, 1.283958e+09, 1.240207e+09,\n",
       "       1.190983e+09, 1.133951e+09, 1.076799e+09, 1.029195e+09, 9.713440e+08,\n",
       "       9.143386e+08, 8.624094e+08, 8.184969e+08, 7.859111e+08, 7.563120e+08,\n",
       "       7.268151e+08, 6.957368e+08, 6.677581e+08, 6.368683e+08, 5.997715e+08,\n",
       "       5.632919e+08, 5.341504e+08, 5.087423e+08, 4.773650e+08, 4.518088e+08,\n",
       "       4.196475e+08, 3.797101e+08, 3.481730e+08, 3.160744e+08, 2.739612e+08,\n",
       "       2.332571e+08, 2.048595e+08, 1.820051e+08, 1.668449e+08, 1.566938e+08,\n",
       "       1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n",
       "       1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n",
       "       1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n",
       "       1.534813e+08])\n",
       "Coordinates:\n",
       "  * time            (time) float64 2.02e+03 2.021e+03 ... 2.099e+03 2.1e+03\n",
       "    calendar_year   (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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",
       "    hydro_year      (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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",
       "Attributes:\n",
       "    description:  Glacier volume below water-level\n",
       "    unit:         m 3
" ], "text/plain": [ "\n", "array([2.029594e+09, 2.029594e+09, 2.029594e+09, 2.029594e+09, 2.023112e+09,\n", " 2.016336e+09, 2.006386e+09, 2.000814e+09, 1.991653e+09, 1.982263e+09,\n", " 1.970191e+09, 1.960187e+09, 1.948230e+09, 1.935669e+09, 1.917310e+09,\n", " 1.899247e+09, 1.878210e+09, 1.854544e+09, 1.824109e+09, 1.789316e+09,\n", " 1.757660e+09, 1.723041e+09, 1.693973e+09, 1.664198e+09, 1.635968e+09,\n", " 1.602742e+09, 1.572505e+09, 1.531707e+09, 1.496572e+09, 1.452187e+09,\n", " 1.422061e+09, 1.378542e+09, 1.333578e+09, 1.283958e+09, 1.240207e+09,\n", " 1.190983e+09, 1.133951e+09, 1.076799e+09, 1.029195e+09, 9.713440e+08,\n", " 9.143386e+08, 8.624094e+08, 8.184969e+08, 7.859111e+08, 7.563120e+08,\n", " 7.268151e+08, 6.957368e+08, 6.677581e+08, 6.368683e+08, 5.997715e+08,\n", " 5.632919e+08, 5.341504e+08, 5.087423e+08, 4.773650e+08, 4.518088e+08,\n", " 4.196475e+08, 3.797101e+08, 3.481730e+08, 3.160744e+08, 2.739612e+08,\n", " 2.332571e+08, 2.048595e+08, 1.820051e+08, 1.668449e+08, 1.566938e+08,\n", " 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n", " 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n", " 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08, 1.534813e+08,\n", " 1.534813e+08])\n", "Coordinates:\n", " * time (time) float64 2.02e+03 2.021e+03 ... 2.099e+03 2.1e+03\n", " calendar_year (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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", " hydro_year (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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", "Attributes:\n", " description: Glacier volume below water-level\n", " unit: m 3" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 62, "id": "11af6345-83d4-4fa4-8f23-9c2d5227174b", "metadata": {}, "outputs": [], "source": [ "input_filesuffix_1 = '_historical_from_2000_run'\n", "input_filesuffix_2 = f'_future_run{rid}'+'_bc_2000_2019'" ] }, { "cell_type": "code", "execution_count": 69, "id": "018b9b53-8890-48c4-af9f-dc642d337b52", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "152176563455.63937" ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds1[v].data[-1]" ] }, { "cell_type": "code", "execution_count": 70, "id": "871fe4a6-19f3-41c9-9d1f-4c8f68d7c3d2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "152176563455.63928" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds2[v].data[0]" ] }, { "cell_type": "code", "execution_count": 72, "id": "6a1d5079-26ba-4374-824b-ab63c7cde473", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(ds1[v].data[-1], ds2[v].data[0])" ] }, { "cell_type": "code", "execution_count": 63, "id": "27833849-b937-4cc1-a0b0-35f2cb97d98d", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'InvalidWorkflowError' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [63]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ds2[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m---> 23\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[43mInvalidWorkflowError\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe two files seem incompatible \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mby data on variable : \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mv\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 25\u001b[0m bucket \u001b[38;5;241m=\u001b[39m ds1[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m:\n", "\u001b[0;31mNameError\u001b[0m: name 'InvalidWorkflowError' is not defined" ] } ], "source": [ " # Read in the input files and check\n", " fp1 = gdir.get_filepath('model_diagnostics', filesuffix=input_filesuffix_1)\n", " with xr.open_dataset(fp1) as ds:\n", " ds1 = ds.load()\n", " fp2 = gdir.get_filepath('model_diagnostics', filesuffix=input_filesuffix_2)\n", " with xr.open_dataset(fp2) as ds:\n", " ds2 = ds.load()\n", " if ds1.time[-1] != ds2.time[0]:\n", " raise InvalidWorkflowError('The two files are incompatible by time')\n", "\n", " # Samity check for all variables as well\n", " for v in ds1:\n", " if not np.all(np.isfinite(ds1[v].data[-1])):\n", " # This is the last year of hydro output - we will discard anyway\n", " continue\n", " if np.allclose(ds1[v].data[-1], ds2[v].data[0]):\n", " # This means that we're OK - the two match\n", " continue\n", "\n", " # This has to be a bucket of some sort, probably snow or calving\n", " if len(ds2[v].data.shape) == 1:\n", " if ds2[v].data[0] != 0:\n", " raise InvalidWorkflowError('The two files seem incompatible '\n", " f'by data on variable : {v}')\n", " bucket = ds1[v].data[-1]\n", " elif len(ds2[v].data.shape) == 2:\n", " if ds2[v].data[0, 0] != 0:\n", " raise InvalidWorkflowError('The two files seem incompatible '\n", " f'by data on variable : {v}')\n", " bucket = ds1[v].data[-1, -1]\n", " # Carry it to the rest\n", " ds2[v] = ds2[v] + bucket\n", "\n", " # Merge by removing the last step of file 1 and delete the files if asked\n", " out_ds = xr.concat([ds1.isel(time=slice(0, -1)), ds2], dim='time')\n", " if delete_input:\n", " os.remove(fp1)\n", " os.remove(fp2)\n", " # Write out and return\n", " fp = gdir.get_filepath('model_diagnostics', filesuffix=output_filesuffix)\n", " out_ds.to_netcdf(fp)\n", " return out_ds" ] }, { "cell_type": "code", "execution_count": 68, "id": "db1ef923-34d7-4923-946a-890c4d2525c0", "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "'continue' not properly in loop (2530398915.py, line 4)", "output_type": "error", "traceback": [ "\u001b[0;36m Input \u001b[0;32mIn [68]\u001b[0;36m\u001b[0m\n\u001b[0;31m continue\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m 'continue' not properly in loop\n" ] } ], "source": [ "v = 'volume_m3'\n", "if not np.all(np.isfinite(ds1[v].data[-1])):\n", " # This is the last year of hydro output - we will discard anyway\n", " continue\n", "if np.allclose(ds1[v].data[-1], ds2[v].data[0]):\n", " # This means that we're OK - the two match\n", " continue" ] }, { "cell_type": "code", "execution_count": null, "id": "521e2175-f324-4bbc-a718-2f747c27d6fa", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "ff122912-5e6b-4b49-a08a-4c722326b7df", "metadata": {}, "outputs": [], "source": [ " for v in ds1:\n", " if not np.all(np.isfinite(ds1[v].data[-1])):\n", " # This is the last year of hydro output - we will discard anyway\n", " continue\n", " if np.allclose(ds1[v].data[-1], ds2[v].data[0]):\n", " # This means that we're OK - the two match\n", " continue" ] }, { "cell_type": "code", "execution_count": 66, "id": "e925dd86-3344-4ed1-bd1f-f97f2708b11b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "not np.all(np.isfinite(ds1[v].data[-1]))" ] }, { "cell_type": "code", "execution_count": 65, "id": "4a9ade9d-788a-4a3e-a61e-ff94f48f736c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.allclose(ds1[v].data[-1], ds2[v].data[0])" ] }, { "cell_type": "code", "execution_count": 64, "id": "e7808893-96a2-48ab-8037-773a422bdc31", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'volume_bwl_m3'" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v" ] }, { "cell_type": "code", "execution_count": null, "id": "cf4dd238-ef11-4c2b-8ccb-25f58bf227bf", "metadata": {}, "outputs": [], "source": [ " \n", "# Now comes the actual run\n", "# first using gcm from 2000-end_yr (this is how it is done in Rounce et al., 2023)\n", "workflow.execute_entity_task(run_hydro_from_2000_ref_area_2000_hist_gcm, gdirs, end_yr = end_yr)\n", "# then using W5E5 from 2000-2019, and GCM from 2020-end_yr (this is how it has normally be done in OGGM)\n", "workflow.execute_entity_task(run_hydro_from_2000_ref_area_2000_hist_w5e5, gdirs, end_yr = end_yr)\n", "\n" ] }, { "cell_type": "code", "execution_count": 11, "id": "7f63d443-d876-4e84-b142-25aa1aa3740f", "metadata": {}, "outputs": [], "source": [ "gdir = gdirs[0]" ] }, { "cell_type": "code", "execution_count": 29, "id": "7069ca58-efde-4d05-8ea8-6076169bb765", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 33, "id": "309f3696-ca87-4c5b-9107-597b90d46577", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "5b15e196-c489-450b-a1fe-b5bae98c2661", "metadata": {}, "outputs": [], "source": [ "ds2[v].data[0] != 0:" ] }, { "cell_type": "code", "execution_count": 47, "id": "3bb473e3-ecbb-4984-b800-ddb13e5a7561", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2950032038.9243755" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dh.volume_bwl_m3.data[0]" ] }, { "cell_type": "code", "execution_count": 48, "id": "d2a80fef-4322-4ba1-a13e-97b290f5db8d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.DataArray 'volume_m3' (time: 81)>\n",
       "array([1.521766e+11, 1.514835e+11, 1.506315e+11, 1.498516e+11, 1.488973e+11,\n",
       "       1.478050e+11, 1.464810e+11, 1.459238e+11, 1.448239e+11, 1.436834e+11,\n",
       "       1.427770e+11, 1.425485e+11, 1.419761e+11, 1.412991e+11, 1.400268e+11,\n",
       "       1.394348e+11, 1.384967e+11, 1.373183e+11, 1.366982e+11, 1.356508e+11,\n",
       "       1.347067e+11, 1.340160e+11, 1.331507e+11, 1.322606e+11, 1.314263e+11,\n",
       "       1.307169e+11, 1.300671e+11, 1.293298e+11, 1.286855e+11, 1.273352e+11,\n",
       "       1.265453e+11, 1.256855e+11, 1.246239e+11, 1.235209e+11, 1.228155e+11,\n",
       "       1.218040e+11, 1.204660e+11, 1.191776e+11, 1.182569e+11, 1.165477e+11,\n",
       "       1.154732e+11, 1.143682e+11, 1.134244e+11, 1.127307e+11, 1.117880e+11,\n",
       "       1.106711e+11, 1.093848e+11, 1.085510e+11, 1.067833e+11, 1.051568e+11,\n",
       "       1.036594e+11, 1.029821e+11, 1.024501e+11, 1.017731e+11, 1.013637e+11,\n",
       "       1.004901e+11, 9.944304e+10, 9.807448e+10, 9.707007e+10, 9.621630e+10,\n",
       "       9.503362e+10, 9.410968e+10, 9.325639e+10, 9.239167e+10, 9.118798e+10,\n",
       "       8.964416e+10, 8.837261e+10, 8.749102e+10, 8.653839e+10, 8.567434e+10,\n",
       "       8.448103e+10, 8.337853e+10, 8.197230e+10, 8.068535e+10, 7.907771e+10,\n",
       "       7.816809e+10, 7.697217e+10, 7.561935e+10, 7.422438e+10, 7.320322e+10,\n",
       "       7.234413e+10])\n",
       "Coordinates:\n",
       "  * time            (time) float64 2.02e+03 2.021e+03 ... 2.099e+03 2.1e+03\n",
       "    calendar_year   (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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",
       "    hydro_year      (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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",
       "Attributes:\n",
       "    description:  Total glacier volume\n",
       "    unit:         m 3
" ], "text/plain": [ "\n", "array([1.521766e+11, 1.514835e+11, 1.506315e+11, 1.498516e+11, 1.488973e+11,\n", " 1.478050e+11, 1.464810e+11, 1.459238e+11, 1.448239e+11, 1.436834e+11,\n", " 1.427770e+11, 1.425485e+11, 1.419761e+11, 1.412991e+11, 1.400268e+11,\n", " 1.394348e+11, 1.384967e+11, 1.373183e+11, 1.366982e+11, 1.356508e+11,\n", " 1.347067e+11, 1.340160e+11, 1.331507e+11, 1.322606e+11, 1.314263e+11,\n", " 1.307169e+11, 1.300671e+11, 1.293298e+11, 1.286855e+11, 1.273352e+11,\n", " 1.265453e+11, 1.256855e+11, 1.246239e+11, 1.235209e+11, 1.228155e+11,\n", " 1.218040e+11, 1.204660e+11, 1.191776e+11, 1.182569e+11, 1.165477e+11,\n", " 1.154732e+11, 1.143682e+11, 1.134244e+11, 1.127307e+11, 1.117880e+11,\n", " 1.106711e+11, 1.093848e+11, 1.085510e+11, 1.067833e+11, 1.051568e+11,\n", " 1.036594e+11, 1.029821e+11, 1.024501e+11, 1.017731e+11, 1.013637e+11,\n", " 1.004901e+11, 9.944304e+10, 9.807448e+10, 9.707007e+10, 9.621630e+10,\n", " 9.503362e+10, 9.410968e+10, 9.325639e+10, 9.239167e+10, 9.118798e+10,\n", " 8.964416e+10, 8.837261e+10, 8.749102e+10, 8.653839e+10, 8.567434e+10,\n", " 8.448103e+10, 8.337853e+10, 8.197230e+10, 8.068535e+10, 7.907771e+10,\n", " 7.816809e+10, 7.697217e+10, 7.561935e+10, 7.422438e+10, 7.320322e+10,\n", " 7.234413e+10])\n", "Coordinates:\n", " * time (time) float64 2.02e+03 2.021e+03 ... 2.099e+03 2.1e+03\n", " calendar_year (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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", " hydro_year (time) int64 2020 2021 2022 2023 ... 2097 2098 2099 2100\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", "Attributes:\n", " description: Total glacier volume\n", " unit: m 3" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.volume_m3" ] }, { "cell_type": "code", "execution_count": 34, "id": "40ce506e-2c98-4f61-93b9-5d10ea6a1229", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:                       (time: 102, month_2d: 12)\n",
       "Coordinates:\n",
       "  * time                          (time) float64 2e+03 2.001e+03 ... 2.1e+03\n",
       "    calendar_year                 (time) int64 2000 2001 2002 ... 2098 2099 2100\n",
       "    calendar_month                (time) int64 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1\n",
       "    hydro_year                    (time) int64 2000 2001 2002 ... 2098 2099 2100\n",
       "    hydro_month                   (time) int64 4 4 4 4 4 4 4 4 ... 4 4 4 4 4 4 4\n",
       "  * month_2d                      (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n",
       "    hydro_month_2d                (month_2d) int64 4 5 6 7 8 9 10 11 12 1 2 3\n",
       "    calendar_month_2d             (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n",
       "Data variables: (12/26)\n",
       "    volume_m3                     (time) float64 1.607e+11 ... 7.234e+10\n",
       "    volume_bsl_m3                 (time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0\n",
       "    volume_bwl_m3                 (time) float64 2.95e+09 2.95e+09 ... 1.535e+08\n",
       "    area_m2                       (time) float64 4.414e+08 ... 3.965e+08\n",
       "    length_m                      (time) float64 4.92e+04 4.92e+04 ... 4.12e+04\n",
       "    calving_m3                    (time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0\n",
       "    ...                            ...\n",
       "    snowfall_on_glacier_monthly   (time, month_2d) float64 1.254e+11 ... nan\n",
       "    snow_bucket                   (time) float64 0.0 3.616e-05 ... 5.78e+10\n",
       "    snow_bucket_monthly           (time, month_2d) float64 0.0 4e-06 ... 0.0 0.0\n",
       "    model_mb                      (time) float64 4.454e+11 -1.153e+11 ... nan\n",
       "    residual_mb                   (time) float64 -4.101e+09 -4.07e+09 ... nan\n",
       "    residual_mb_monthly           (time, month_2d) float64 0.0 0.0 ... nan nan\n",
       "Attributes:\n",
       "    description:          OGGM model output\n",
       "    oggm_version:         1.3.2.dev394+gb45b78b\n",
       "    calendar:             365-day no leap\n",
       "    creation_date:        2023-05-12 07:34:16\n",
       "    water_level:          491.3637909324272\n",
       "    glen_a:               7.830101237437472e-24\n",
       "    fs:                   0\n",
       "    mb_model_class:       MultipleFlowlineMassBalance\n",
       "    mb_model_hemisphere:  nh
" ], "text/plain": [ "\n", "Dimensions: (time: 102, month_2d: 12)\n", "Coordinates:\n", " * time (time) float64 2e+03 2.001e+03 ... 2.1e+03\n", " calendar_year (time) int64 2000 2001 2002 ... 2098 2099 2100\n", " calendar_month (time) int64 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1\n", " hydro_year (time) int64 2000 2001 2002 ... 2098 2099 2100\n", " hydro_month (time) int64 4 4 4 4 4 4 4 4 ... 4 4 4 4 4 4 4\n", " * month_2d (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n", " hydro_month_2d (month_2d) int64 4 5 6 7 8 9 10 11 12 1 2 3\n", " calendar_month_2d (month_2d) int64 1 2 3 4 5 6 7 8 9 10 11 12\n", "Data variables: (12/26)\n", " volume_m3 (time) float64 1.607e+11 ... 7.234e+10\n", " volume_bsl_m3 (time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0\n", " volume_bwl_m3 (time) float64 2.95e+09 2.95e+09 ... 1.535e+08\n", " area_m2 (time) float64 4.414e+08 ... 3.965e+08\n", " length_m (time) float64 4.92e+04 4.92e+04 ... 4.12e+04\n", " calving_m3 (time) float64 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0\n", " ... ...\n", " snowfall_on_glacier_monthly (time, month_2d) float64 1.254e+11 ... nan\n", " snow_bucket (time) float64 0.0 3.616e-05 ... 5.78e+10\n", " snow_bucket_monthly (time, month_2d) float64 0.0 4e-06 ... 0.0 0.0\n", " model_mb (time) float64 4.454e+11 -1.153e+11 ... nan\n", " residual_mb (time) float64 -4.101e+09 -4.07e+09 ... nan\n", " residual_mb_monthly (time, month_2d) float64 0.0 0.0 ... nan nan\n", "Attributes:\n", " description: OGGM model output\n", " oggm_version: 1.3.2.dev394+gb45b78b\n", " calendar: 365-day no leap\n", " creation_date: 2023-05-12 07:34:16\n", " water_level: 491.3637909324272\n", " glen_a: 7.830101237437472e-24\n", " fs: 0\n", " mb_model_class: MultipleFlowlineMassBalance\n", " mb_model_hemisphere: nh" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xr.concat([dh,df], dim='time')" ] }, { "cell_type": "code", "execution_count": 21, "id": "e3a29c36-1c64-41dd-b2d6-9858c9ebc167", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/climate_historical.nc'" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gdir.get_filepath('climate_historical')" ] }, { "cell_type": "code", "execution_count": 37, "id": "1cfc79b6-39bb-4411-ac33-c9f05a0290e2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m\n", "\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmerge_consecutive_run_outputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mgdir\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0minput_filesuffix_1\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0minput_filesuffix_2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0moutput_filesuffix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mdelete_input\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "Merges the output of two model_diagnostics files into one.\n", "\n", "It assumes that the last time of file1 is equal to the first time of file2.\n", "\n", "Parameters\n", "----------\n", "gdir : the glacier directory\n", "input_filesuffix_1 : str\n", " how to recognize the first file\n", "input_filesuffix_2 : str\n", " how to recognize the second file\n", "output_filesuffix : str\n", " where to write the output (default: no suffix)\n", "\n", "Returns\n", "-------\n", "The merged dataset\n", "\n", "Notes\n", "-----\n", "Files written to the glacier directory:\n", "\u001b[0;31mFile:\u001b[0m ~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py\n", "\u001b[0;31mType:\u001b[0m function\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "utils.merge_consecutive_run_outputs?" ] }, { "cell_type": "code", "execution_count": 17, "id": "8e2d2644-0cd6-462d-a145-bde55d08b9ad", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-05-12 09:34:17: oggm.utils: InvalidWorkflowError occurred during task merge_consecutive_run_outputs_merged_from_2000_run_CMIP6_CESM2-WACCM_ssp126_endyr2100_bc_2000_2019 on RGI60-01.16122: The two files seem incompatible by data on variable : volume_bwl_m3\n" ] }, { "ename": "InvalidWorkflowError", "evalue": "The two files seem incompatible by data on variable : volume_bwl_m3", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mInvalidWorkflowError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [17]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 17\u001b[0m rid\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_CMIP6_\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m rid\n\u001b[1;32m 19\u001b[0m tasks\u001b[38;5;241m.\u001b[39mrun_with_hydro(gdir,\n\u001b[1;32m 20\u001b[0m run_task\u001b[38;5;241m=\u001b[39mtasks\u001b[38;5;241m.\u001b[39mrun_from_climate_data,\n\u001b[1;32m 21\u001b[0m ys\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2020\u001b[39m, \u001b[38;5;66;03m# this is important! Start from 2020 glacier\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[38;5;66;03m# add monthly diagnostics\u001b[39;00m\n\u001b[1;32m 34\u001b[0m store_monthly_hydro\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m);\n\u001b[0;32m---> 37\u001b[0m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmerge_consecutive_run_outputs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 38\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_filesuffix_1\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_historical_from_2000_run\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 39\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_filesuffix_2\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_future_run\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mrid\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 40\u001b[0m \u001b[43m \u001b[49m\u001b[43moutput_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_merged_from_2000_run\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mrid\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_endyr\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mend_yr\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 41\u001b[0m \u001b[43m \u001b[49m\u001b[43mdelete_input\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 42\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# we will delete that later\u001b[39;00m\n\u001b[1;32m 43\u001b[0m \u001b[38;5;28mprint\u001b[39m(gcm)\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:491\u001b[0m, in \u001b[0;36mentity_task.__call__.._entity_task\u001b[0;34m(gdir, reset, print_log, return_value, continue_on_error, add_to_log_file, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m signal\u001b[38;5;241m.\u001b[39malarm(cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 490\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[0;32m--> 491\u001b[0m out \u001b[38;5;241m=\u001b[39m \u001b[43mtask_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 492\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m-\u001b[39m ex_t\n\u001b[1;32m 493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:1055\u001b[0m, in \u001b[0;36mmerge_consecutive_run_outputs\u001b[0;34m(gdir, input_filesuffix_1, input_filesuffix_2, output_filesuffix, delete_input)\u001b[0m\n\u001b[1;32m 1053\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 1054\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ds2[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m-> 1055\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidWorkflowError(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe two files seem incompatible \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1056\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mby data on variable : \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mv\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 1057\u001b[0m bucket \u001b[38;5;241m=\u001b[39m ds1[v]\u001b[38;5;241m.\u001b[39mdata[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m 1058\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(ds2[v]\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mshape) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m:\n", "\u001b[0;31mInvalidWorkflowError\u001b[0m: The two files seem incompatible by data on variable : volume_bwl_m3" ] } ], "source": [ "m = tasks.run_with_hydro(gdir, run_task=tasks.run_from_climate_data,\n", " climate_filename='climate_historical',\n", " ys=2000, init_model_yr=2000,\n", " store_monthly_hydro=True,\n", " init_model_filesuffix='_spinup_historical',\n", " ref_geometry_filesuffix='_spinup_historical',\n", " ref_area_yr = 2000,\n", " output_filesuffix='_historical_from_2000_run')\n", "\n", "for gcm in gcms_cmip6.gcm.unique()[:5]: ##TEST:\n", " df1 = gcms_cmip6.loc[gcms_cmip6.gcm == gcm]\n", " for ssp in df1.ssp.unique():\n", " df2 = df1.loc[df1.ssp == ssp]\n", " assert len(df2) == 2\n", " ft = df2.loc[df2['var'] == 'tas'].iloc[0]\n", " rid = ft.fname.replace('_r1i1p1f1_tas.nc', '')\n", " rid='_CMIP6_' + rid\n", " \n", " tasks.run_with_hydro(gdir,\n", " run_task=tasks.run_from_climate_data,\n", " ys=2020, # this is important! Start from 2020 glacier\n", " ye=end_yr,\n", " # use gcm_data, not climate_historical\n", " climate_filename='gcm_data',\n", " # use the chosen scenario\n", " climate_input_filesuffix=rid+'_bc_2000_2019',\n", " # we start from the previous run, \n", " init_model_filesuffix='_historical_from_2000_run',\n", " ref_geometry_filesuffix='_historical_from_2000_run', \n", " ref_area_yr = 2000,\n", " # recognize the run for later\n", " output_filesuffix=f'_future_run{rid}'+'_bc_2000_2019',\n", " # add monthly diagnostics\n", " store_monthly_hydro=True);\n", " \n", " \n", " utils.merge_consecutive_run_outputs(gdir,\n", " input_filesuffix_1='_historical_from_2000_run',\n", " input_filesuffix_2=f'_future_run{rid}'+'_bc_2000_2019',\n", " output_filesuffix=f'_merged_from_2000_run{rid}_endyr{end_yr}_bc_2000_2019',\n", " delete_input=False,\n", " ) # we will delete that later\n", " print(gcm)" ] }, { "cell_type": "code", "execution_count": null, "id": "3de09366-4b24-4dad-9a78-37d20fa9a50e", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "id": "0186a835-a79a-4953-8e05-ac3539e6cd09", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-05-12 09:28:13: oggm.core.flowline: FileNotFoundError occurred during task run_from_climate_data_gcm_from_2000_run_CMIP6_MRI-ESM2-0_ssp534-over_endyr2100_bc_2000_2019 on RGI60-01.16122: [Errno 2] No such file or directory: b'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/gcm_data_CMIP6_MRI-ESM2-0_ssp534-over_bc_2000_2019.nc'\n", "2023-05-12 09:28:13: oggm.core.flowline: FileNotFoundError occurred during task run_with_hydro_gcm_from_2000_run_CMIP6_MRI-ESM2-0_ssp534-over_endyr2100_bc_2000_2019 on RGI60-01.16122: [Errno 2] No such file or directory: b'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/gcm_data_CMIP6_MRI-ESM2-0_ssp534-over_bc_2000_2019.nc'\n" ] }, { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: b'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/gcm_data_CMIP6_MRI-ESM2-0_ssp534-over_bc_2000_2019.nc'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 7\u001b[0m rid \u001b[38;5;241m=\u001b[39m ft\u001b[38;5;241m.\u001b[39mfname\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_r1i1p1f1_tas.nc\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 8\u001b[0m rid\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_CMIP6_\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m rid\n\u001b[0;32m---> 10\u001b[0m \u001b[43mtasks\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_with_hydro\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_task\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtasks\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_from_climate_data\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43mys\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m2000\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# this is important! Start from 2000 glacier\u001b[39;49;00m\n\u001b[1;32m 13\u001b[0m \u001b[43m \u001b[49m\u001b[43minit_model_yr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m2000\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 14\u001b[0m \u001b[43m \u001b[49m\u001b[43mye\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mend_yr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 15\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# use gcm_data, not climate_historical\u001b[39;49;00m\n\u001b[1;32m 16\u001b[0m \u001b[43m \u001b[49m\u001b[43mclimate_filename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mgcm_data\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 17\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# use the chosen scenario\u001b[39;49;00m\n\u001b[1;32m 18\u001b[0m \u001b[43m \u001b[49m\u001b[43mclimate_input_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrid\u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# we start from the previous run, \u001b[39;49;00m\n\u001b[1;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[43minit_model_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_spinup_historical\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[43mref_geometry_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_spinup_historical\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43mref_area_yr\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2000\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 23\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# recognize the run for later\u001b[39;49;00m\n\u001b[1;32m 24\u001b[0m \u001b[43m \u001b[49m\u001b[43moutput_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_gcm_from_2000_run\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mrid\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m_endyr\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43mend_yr\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_bc_2000_2019\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 25\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# add monthly diagnostics\u001b[39;49;00m\n\u001b[1;32m 26\u001b[0m \u001b[43m \u001b[49m\u001b[43mstore_monthly_hydro\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m;\n\u001b[1;32m 28\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m end_yr \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m2300\u001b[39m: \n\u001b[1;32m 29\u001b[0m \u001b[38;5;66;03m# only do that for comparison for the common ssps with isimip3b\u001b[39;00m\n\u001b[1;32m 30\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m gcm\u001b[38;5;241m.\u001b[39mlower() \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgfdl-esm4\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmpi-esm1-2-hr\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmri-esm2-0\u001b[39m\u001b[38;5;124m'\u001b[39m]: \n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:491\u001b[0m, in \u001b[0;36mentity_task.__call__.._entity_task\u001b[0;34m(gdir, reset, print_log, return_value, continue_on_error, add_to_log_file, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m signal\u001b[38;5;241m.\u001b[39malarm(cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 490\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[0;32m--> 491\u001b[0m out \u001b[38;5;241m=\u001b[39m \u001b[43mtask_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 492\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m-\u001b[39m ex_t\n\u001b[1;32m 493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/core/flowline.py:3654\u001b[0m, in \u001b[0;36mrun_with_hydro\u001b[0;34m(gdir, run_task, store_monthly_hydro, fixed_geometry_spinup_yr, ref_area_from_y0, ref_area_yr, ref_geometry_filesuffix, **kwargs)\u001b[0m\n\u001b[1;32m 3651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m fixed_geometry_spinup_yr \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 3652\u001b[0m kwargs[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfixed_geometry_spinup_yr\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m fixed_geometry_spinup_yr\n\u001b[0;32m-> 3654\u001b[0m out \u001b[38;5;241m=\u001b[39m \u001b[43mrun_task\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3656\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m out \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 3657\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m InvalidWorkflowError(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe run task (\u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m) did not run \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 3658\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msuccessfully.\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mformat(run_task\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m))\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:491\u001b[0m, in \u001b[0;36mentity_task.__call__.._entity_task\u001b[0;34m(gdir, reset, print_log, return_value, continue_on_error, add_to_log_file, **kwargs)\u001b[0m\n\u001b[1;32m 489\u001b[0m signal\u001b[38;5;241m.\u001b[39malarm(cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 490\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n\u001b[0;32m--> 491\u001b[0m out \u001b[38;5;241m=\u001b[39m \u001b[43mtask_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 492\u001b[0m ex_t \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m-\u001b[39m ex_t\n\u001b[1;32m 493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cfg\u001b[38;5;241m.\u001b[39mPARAMS[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtask_timeout\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/core/flowline.py:3566\u001b[0m, in \u001b[0;36mrun_from_climate_data\u001b[0;34m(gdir, ys, ye, min_ys, max_ys, fixed_geometry_spinup_yr, store_monthly_step, store_model_geometry, store_fl_diagnostics, climate_filename, mb_model, mb_model_class, climate_input_filesuffix, output_filesuffix, init_model_filesuffix, init_model_yr, init_model_fls, zero_initial_glacier, bias, temperature_bias, precipitation_factor, **kwargs)\u001b[0m\n\u001b[1;32m 3563\u001b[0m ys \u001b[38;5;241m=\u001b[39m ys \u001b[38;5;28;01mif\u001b[39;00m ys \u001b[38;5;241m<\u001b[39m max_ys \u001b[38;5;28;01melse\u001b[39;00m max_ys\n\u001b[1;32m 3565\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mb_model \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 3566\u001b[0m mb_model \u001b[38;5;241m=\u001b[39m \u001b[43mMultipleFlowlineMassBalance\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3567\u001b[0m \u001b[43m \u001b[49m\u001b[43mmb_model_class\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmb_model_class\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3568\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclimate_filename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3569\u001b[0m \u001b[43m \u001b[49m\u001b[43mbias\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 3570\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclimate_input_filesuffix\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3572\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m temperature_bias \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 3573\u001b[0m mb_model\u001b[38;5;241m.\u001b[39mtemp_bias \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m temperature_bias\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/core/massbalance.py:1194\u001b[0m, in \u001b[0;36mMultipleFlowlineMassBalance.__init__\u001b[0;34m(self, gdir, fls, mb_model_class, use_inversion_flowlines, input_filesuffix, **kwargs)\u001b[0m\n\u001b[1;32m 1190\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1191\u001b[0m rgi_filesuffix \u001b[38;5;241m=\u001b[39m input_filesuffix\n\u001b[1;32m 1193\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mflowline_mb_models\u001b[38;5;241m.\u001b[39mappend(\n\u001b[0;32m-> 1194\u001b[0m \u001b[43mmb_model_class\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgdir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minput_filesuffix\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrgi_filesuffix\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1195\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 1197\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalid_bounds \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mflowline_mb_models[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\u001b[38;5;241m.\u001b[39mvalid_bounds\n\u001b[1;32m 1198\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhemisphere \u001b[38;5;241m=\u001b[39m gdir\u001b[38;5;241m.\u001b[39mhemisphere\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/core/massbalance.py:439\u001b[0m, in \u001b[0;36mMonthlyTIModel.__init__\u001b[0;34m(self, gdir, filename, input_filesuffix, fl_id, melt_f, temp_bias, prcp_fac, bias, ys, ye, repeat, check_calib_params)\u001b[0m\n\u001b[1;32m 437\u001b[0m \u001b[38;5;66;03m# Read climate file\u001b[39;00m\n\u001b[1;32m 438\u001b[0m fpath \u001b[38;5;241m=\u001b[39m gdir\u001b[38;5;241m.\u001b[39mget_filepath(filename, filesuffix\u001b[38;5;241m=\u001b[39minput_filesuffix)\n\u001b[0;32m--> 439\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mncDataset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfpath\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m nc:\n\u001b[1;32m 440\u001b[0m \u001b[38;5;66;03m# time\u001b[39;00m\n\u001b[1;32m 441\u001b[0m time \u001b[38;5;241m=\u001b[39m nc\u001b[38;5;241m.\u001b[39mvariables[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtime\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[1;32m 442\u001b[0m time \u001b[38;5;241m=\u001b[39m cftime\u001b[38;5;241m.\u001b[39mnum2date(time[:], time\u001b[38;5;241m.\u001b[39munits, calendar\u001b[38;5;241m=\u001b[39mtime\u001b[38;5;241m.\u001b[39mcalendar)\n", "File \u001b[0;32m~/.local/lib/python3.10/site-packages/oggm/utils/_workflow.py:361\u001b[0m, in \u001b[0;36mncDataset.__init__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 360\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m--> 361\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mncDataset\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 362\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mset_auto_mask(\u001b[38;5;28;01mFalse\u001b[39;00m)\n", "File \u001b[0;32msrc/netCDF4/_netCDF4.pyx:2353\u001b[0m, in \u001b[0;36mnetCDF4._netCDF4.Dataset.__init__\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32msrc/netCDF4/_netCDF4.pyx:1963\u001b[0m, in \u001b[0;36mnetCDF4._netCDF4._ensure_nc_success\u001b[0;34m()\u001b[0m\n", "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: b'/tmp/OGGM/OGGM_gcm_output/per_glacier/RGI60-01/RGI60-01.16/RGI60-01.16122/gcm_data_CMIP6_MRI-ESM2-0_ssp534-over_bc_2000_2019.nc'" ] } ], "source": [ "for gcm in gcms_cmip6.gcm.unique(): ##TEST:\n", " df1 = gcms_cmip6.loc[gcms_cmip6.gcm == gcm]\n", " for ssp in df1.ssp.unique():\n", " df2 = df1.loc[df1.ssp == ssp]\n", " assert len(df2) == 2\n", " ft = df2.loc[df2['var'] == 'tas'].iloc[0]\n", " rid = ft.fname.replace('_r1i1p1f1_tas.nc', '')\n", " rid='_CMIP6_' + rid\n", "\n", " tasks.run_with_hydro(gdir,\n", " run_task=tasks.run_from_climate_data,\n", " ys=2000, # this is important! Start from 2000 glacier\n", " init_model_yr=2000,\n", " ye=end_yr,\n", " # use gcm_data, not climate_historical\n", " climate_filename='gcm_data',\n", " # use the chosen scenario\n", " climate_input_filesuffix=rid+'_bc_2000_2019',\n", " # we start from the previous run, \n", " init_model_filesuffix='_spinup_historical',\n", " ref_geometry_filesuffix='_spinup_historical',\n", " ref_area_yr = 2000,\n", " # recognize the run for later\n", " output_filesuffix=f'_gcm_from_2000_run{rid}_endyr{end_yr}'+'_bc_2000_2019',\n", " # add monthly diagnostics\n", " store_monthly_hydro=True);\n", "\n", " if end_yr != 2300: \n", " # only do that for comparison for the common ssps with isimip3b\n", " if gcm.lower() in ['gfdl-esm4', 'mpi-esm1-2-hr', 'mri-esm2-0']: \n", " if ssp in ['ssp126', 'ssp370', 'ssp585']:\n", " tasks.run_with_hydro(gdir,\n", " run_task=tasks.run_from_climate_data,\n", " ys=2000, # this is important! Start from 2000 glacier\n", " init_model_yr=2000,\n", " ye=end_yr,\n", " # use gcm_data, not climate_historical\n", " climate_filename='gcm_data',\n", " # use the chosen scenario\n", " climate_input_filesuffix=rid+'_bc_1979_2014',\n", " # we start from the previous run, \n", " init_model_filesuffix='_spinup_historical',\n", " ref_geometry_filesuffix='_spinup_historical',\n", " ref_area_yr = 2000,\n", " # recognize the run for later\n", " output_filesuffix=f'_gcm_from_2000_run{rid}_endyr{end_yr}'+'_bc_1979_2014',\n", " # add monthly diagnostics\n", " store_monthly_hydro=True);" ] }, { "cell_type": "code", "execution_count": null, "id": "384e2541-2b7c-48ee-a51d-1a5d3830e397", "metadata": {}, "outputs": [], "source": [ "\n", "\n", "# merge data together\n", "if end_yr == 2100:\n", " for member in isimip3b_members: \n", " for ssp in ['ssp126', 'ssp370', 'ssp585']:\n", " rid = f'_ISIMIP3b_{member}_{ssp}'\n", " # for W5E5 as past climate \n", " utils.compile_run_output(gdirs, input_filesuffix=f'_merged_from_2000_run{rid}', \n", " path=os.path.join(eq_dir, f'run_hydro_w5e5_gcm_merged_endyr2100{rid}_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_merged_from_2000_run{rid}_bc_2000_2019', \n", " path=os.path.join(eq_dir, f'run_hydro_w5e5_gcm_merged_endyr2100{rid}_bc_2000_2019_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", " \n", " # for the GCM as past climate \n", " utils.compile_run_output(gdirs, input_filesuffix=f'_gcm_from_2000_run{rid}', \n", " path=os.path.join(eq_dir, f'run_hydro_gcm_from_2000_endyr2100{rid}_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_gcm_from_2000_run{rid}_bc_2000_2019', \n", " path=os.path.join(eq_dir, f'run_hydro_gcm_from_2000_endyr2100{rid}_bc_2000_2019_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", "\n", "\n", "for gcm in gcms_cmip6.gcm.unique(): \n", " df1 = gcms_cmip6.loc[gcms_cmip6.gcm == gcm]\n", " for ssp in df1.ssp.unique():\n", " df2 = df1.loc[df1.ssp == ssp]\n", " assert len(df2) == 2\n", " ft = df2.loc[df2['var'] == 'tas'].iloc[0]\n", " rid = ft.fname.replace('_r1i1p1f1_tas.nc', '')\n", " rid='_CMIP6_' + rid\n", "\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_merged_from_2000_run{rid}_endyr{end_yr}_bc_2000_2019', \n", " path=os.path.join(eq_dir, f'run_hydro_w5e5_gcm_merged_endyr{end_yr}{rid}_bc_2000_2019_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", "\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_gcm_from_2000_run{rid}_endyr{end_yr}_bc_2000_2019', \n", " path=os.path.join(eq_dir, f'run_hydro_gcm_from_2000_endyr{end_yr}{rid}_bc_2000_2019_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", " \n", " if end_yr == 2100:\n", " # only do that for comparison for the common ssps with isimip3b\n", " if gcm.lower() in ['gfdl-esm4', 'mpi-esm1-2-hr', 'mri-esm2-0']: \n", " if ssp in ['ssp126', 'ssp370', 'ssp585']:\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_merged_from_2000_run{rid}_endyr{end_yr}_bc_1979_2014', \n", " path=os.path.join(eq_dir, f'run_hydro_w5e5_gcm_merged_endyr{end_yr}{rid}_bc_1979_2014_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", "\n", " utils.compile_run_output(gdirs, input_filesuffix=f'_gcm_from_2000_run{rid}_endyr{end_yr}_bc_1979_2014', \n", " path=os.path.join(eq_dir, f'run_hydro_gcm_from_2000_endyr{end_yr}{rid}_bc_1979_2014_rgi{rgi_reg}_{id0}_{id1}.nc'))\n", "\n", "\n", " \n", "\n", "log.workflow('OGGM Done')" ] }, { "cell_type": "code", "execution_count": null, "id": "91c27c56-17c9-4349-a52f-b02ca54c6c47", "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.8" } }, "nbformat": 4, "nbformat_minor": 5 }