{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Simple Water balance calculation" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "def water_balance(avg_hs, avg_rp, avg_dis, area, cell, ofstorage, label_discharge=\"dis_0\"):\n", " \"\"\"All output units are in mm\"\"\"\n", " P = avg_hs[\"pre_0\"]\n", " AET = avg_hs[\"aet_0\"]\n", " R = avg_hs[\"rch_0\"] \n", " OF = avg_hs[\"run_0\"]\n", " Qgw = avg_hs[\"gdh_0\"]*1000.0\n", " TL = avg_hs[\"tls_0\"]*1000/np.power(cell,2)\n", " Peff = avg_hs[\"pre_0\"] - avg_hs[\"inf_0\"]\n", " Qgw = avg_hs[\"gdh_0\"]*1000.\n", " Q = avg_dis[label_discharge]*1000/area \n", " factor = avg_hs[\"tls_0\"]/avg_rp[\"tls_0\"]\n", " AER = avg_rp[\"aet_0\"]*factor\n", " Rfch = avg_rp[\"fch_0\"]*factor\n", " Rdch = avg_hs[\"rch_0\"] - Rfch\n", " ofstorage = ofstorage*factor*1000/np.power(cell,2)\n", " Qbc = avg_hs[\"chb_0\"]*1000.\n", " EGW = avg_hs[\"egw_0\"]\n", " MBuz = avg_hs[\"inf_0\"] - avg_hs[\"aet_0\"] - Rdch\n", " MB = (avg_hs[\"pre_0\"] - avg_hs[\"aet_0\"] - avg_hs[\"egw_0\"]\n", " - Q - AER - ofstorage - avg_hs[\"twsc_0\"] - Qbc)\n", " \n", " # store fluxes in a dictionary\n", " fluxes = {\"P\": [P, 100.0],\n", " \"AET\": [AET, AET*100./P], \"AER\": [AER, AER*100./P], \"EGW\": [EGW, EGW*100./P],\n", " \"R\": [R, R*100./P], \"Rfch\": [Rfch, Rfch*100./P], \"Rdch\": [Rdch, Rdch*100./P],\n", " \"Q\": [Q, Q*100./P], \"Qgw\": [Qgw, Qgw*100./P],\n", " \"Peff\": [Peff, Peff*100./P],\n", " \"OF\": [OF, OF*100./P], \"TL\": [TL, TL*100./P], \n", " \"TSWS\":[ofstorage, ofstorage*100./P],\n", " \"TWSA\":[avg_hs[\"twsc_0\"],avg_hs[\"twsc_0\"]*100./P],\n", " \"Qbc\": [Qbc, Qbc*100./P],\n", " \"MB\": [MB, MB*100./P],\n", " \"MBuz\": [MBuz, MBuz*100./P]}\n", " return pd.DataFrame.from_dict(fluxes)\n", "\n", "def calculate_water_balance_from_csv(fhillslope, friparian, fdischarge, area, cell, label_discharge=\"dis_0\"):\n", " avg_hs = pd.read_csv(fhillslope).sum()\n", " avg_rp = pd.read_csv(friparian).sum()\n", " avg_dis = pd.read_csv(fdischarge).sum()\n", " avg_rp_mean = pd.read_csv(friparian).mean()\n", " ofstorage = avg_rp_mean[\"ssz_0\"]\n", " return water_balance(avg_hs, avg_rp, avg_dis, area, cell, ofstorage, label_discharge)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Tilted-V basin test" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "folder = \"/home/andresqm/Documents/GitHub/DRYPv2.0.1/tests/tilted_v/output/\"\n", "fname_avg_hs = folder + \"test_avg.csv\"\n", "fname_avg_rp = folder + \"test_RZ_avg.csv\"\n", "fname_avg_dis = folder + \"test_p_dis.csv\"\n", "cell_size = 1000 # m\n", "basin_area = (cell_size**2)*7*10 # m2" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_7306/1726732392.py:40: FutureWarning: The default value of numeric_only in DataFrame.mean is deprecated. In a future version, it will default to False. In addition, specifying 'numeric_only=None' is deprecated. Select only valid columns or specify the value of numeric_only to silence this warning.\n", " avg_rp_mean = pd.read_csv(friparian).mean()\n" ] }, { "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", "
PAETAEREGWRRfchRdchQQgwPeffOFTLTSWSTWSAQbcMBMBuz
01499.75815.3861340.00015463.667404548.8206190.0548.820619278.084841199.5119990.0278.0848416.774715e-190.0341.8284270.00.783041135.543247
1100.0054.3681370.0000104.24520136.5941400.036.59414018.54208013.3030170.018.5420804.517229e-200.022.7923610.00.0522119.037723
\n", "
" ], "text/plain": [ " P AET AER EGW R Rfch Rdch \\\n", "0 1499.75 815.386134 0.000154 63.667404 548.820619 0.0 548.820619 \n", "1 100.00 54.368137 0.000010 4.245201 36.594140 0.0 36.594140 \n", "\n", " Q Qgw Peff OF TL TSWS TWSA \\\n", "0 278.084841 199.511999 0.0 278.084841 6.774715e-19 0.0 341.828427 \n", "1 18.542080 13.303017 0.0 18.542080 4.517229e-20 0.0 22.792361 \n", "\n", " Qbc MB MBuz \n", "0 0.0 0.783041 135.543247 \n", "1 0.0 0.052211 9.037723 " ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "calculate_water_balance_from_csv(fname_avg_hs, fname_avg_rp, fname_avg_dis,\n", " basin_area, cell_size)" ] }, { "cell_type": "code", "execution_count": null, "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.9" } }, "nbformat": 4, "nbformat_minor": 4 }