From 3a6508ff24c9f3db7fd8ec8d2260f128fa2a5253 Mon Sep 17 00:00:00 2001 From: Peter La Follette Date: Sun, 3 Nov 2024 13:09:12 -0800 Subject: [PATCH] adding notebooks for animating LGARTO synthetic tests --- tests/lgarto_profile_animation_synth_1.ipynb | 890 +++++++++++++++++++ tests/lgarto_profile_animation_synth_2.ipynb | 885 ++++++++++++++++++ tests/lgarto_profile_animation_synth_3.ipynb | 890 +++++++++++++++++++ tests/lgarto_profile_animation_synth_4.ipynb | 890 +++++++++++++++++++ 4 files changed, 3555 insertions(+) create mode 100644 tests/lgarto_profile_animation_synth_1.ipynb create mode 100644 tests/lgarto_profile_animation_synth_2.ipynb create mode 100644 tests/lgarto_profile_animation_synth_3.ipynb create mode 100644 tests/lgarto_profile_animation_synth_4.ipynb diff --git a/tests/lgarto_profile_animation_synth_1.ipynb b/tests/lgarto_profile_animation_synth_1.ipynb new file mode 100644 index 0000000..1d90f8f --- /dev/null +++ b/tests/lgarto_profile_animation_synth_1.ipynb @@ -0,0 +1,890 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "8b26a1c1", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "import matplotlib.animation as animation\n", + "from matplotlib.animation import FuncAnimation, PillowWriter \n", + "import sys, os\n", + "import imageio, re\n", + "import importlib as imp\n", + "import copy\n", + "import pandas as pd\n", + "\n", + "from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes\n", + "from mpl_toolkits.axes_grid1.inset_locator import mark_inset\n", + "import matplotlib.dates as mdates\n", + "from matplotlib.patches import Rectangle\n", + "\n", + "import pickle\n", + "\n", + "from datetime import datetime\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ede7ad3", + "metadata": {}, + "outputs": [], + "source": [ + "layer_depth = [0.0, 10.0, 10.0+45.0, 10.0+45.0+45.0]\n", + "#51.0,99.0,53.0[cm]\n", + "time_step_for_plotting = 1\n", + "theta_e_vec = [0.41,0.43,0.45] #edit for your scenario \n", + "max_depth = layer_depth[-1]\n", + "# 36.0,111.0,107.0\n", + "\n", + "synth_case = str(1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a9f5ba8", + "metadata": {}, + "outputs": [], + "source": [ + "c_path_layers = 'outputs/synthetic'+synth_case + '_LGARTO/data_layers.csv'\n", + "sim_case = 'outputs/synthetic'+synth_case+'_LGARTO/data_variables.csv' \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72f8e45a", + "metadata": {}, + "outputs": [], + "source": [ + "# hydrus_path_layers = '/Users/peterlafollette/Desktop/ngen_test_2/ngen/extern/LGARTO-C/tests/HYDRUS_outputs/Geneva/Nod_Inf.csv'\n", + "# data_sim_hydrus = pd.read_csv(hydrus_path_layers, sep='\\s+')\n", + "\n", + "# # data_sim_hydrus = data_sim_hydrus[0:100]\n", + "# # data_sim_hydrus = data_sim_hydrus[101:201]\n", + "# # data_sim_hydrus = data_sim_hydrus[202:302]\n", + "# data_sim_hydrus = data_sim_hydrus[202:]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "efb644ba", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5ef98a57", + "metadata": {}, + "outputs": [], + "source": [ + "data_sim_c = np.loadtxt(c_path_layers,dtype='str')\n", + "# data_sim_py = data_sim_c #setting these equal for now to get code working -- attempting to remove data_sim_py from code \n", + "\n", + "Depth_d = []\n", + "Theta_d = []\n", + "Head_d = []\n", + "Dat_u = []\n", + "Dat_v = []\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29115339", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f820a6b0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9ff759c", + "metadata": {}, + "outputs": [], + "source": [ + "count = 0\n", + "for u in data_sim_c:\n", + " u1 = u[1:-1].split('|')\n", + " val_u = []\n", + "\n", + " for u2 in u1:\n", + " u3 = u2[1:-1].split(',')\n", + " u4 = [float(u3[0]), float(u3[1]), float(u3[4])]\n", + " val_u.append(u4)\n", + " \n", + " count = count + 1\n", + " Dat_u.append(val_u)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "276f3f5c", + "metadata": {}, + "outputs": [], + "source": [ + "def data_gen1():\n", + " for u in data_sim_c[::12]:\n", + " v1 = u[1:-1].split('|')\n", + " val_c = []\n", + " \n", + " for v2 in v1:\n", + " v3 = v2[1:-1].split(',')\n", + " v4 = [float(v3[0]), float(v3[1]), float(v3[4])]\n", + " val_c.append(v4)\n", + " \n", + " yield val_c\n", + " \n", + "time = np.arange(0,len(Dat_u)/12.,1.) # 1/12 = 5/60 (min/hr)\n", + "time = [round (t,3) for t in time]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cd9c78e9", + "metadata": {}, + "outputs": [], + "source": [ + "def data_gen2():\n", + " c = -1\n", + " #print (len(time))\n", + " for u in data_sim_c[::12]:\n", + " u1 = u[1:-1].split('|')\n", + "# v1 = v[1:-1].split('],')\n", + " val_u = []\n", + "# val_v = []\n", + " for u2 in u1:\n", + " u3 = u2[1:-1].split(',')\n", + " u4 = [float(u3[0]), float(u3[1]), float(u3[4])]\n", + " val_u.append(u4)\n", + "\n", + "# for v2 in v1:\n", + "# v3 = v2[1:-1].split(',')\n", + "# v3[0] = v3[0].replace('[', '')\n", + "# depth = float(v3[0]) + layer_depth[int(v3[2])]\n", + "# v4 = [depth, round(float(v3[1]),6), float(v3[2])]\n", + "# #v4 = [float(v3[0]), round(float(v3[1]),6), float(v3[3])]\n", + "# val_v.append(v4)\n", + " c = c +1\n", + " \n", + " yield time[c], val_u\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0e3bb2a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b982e58a", + "metadata": {}, + "outputs": [], + "source": [ + "# %matplotlib notebook\n", + "fig, axs = plt.subplots(2,1,figsize=(6*1.3,4*1.3))\n", + "fig.tight_layout(pad=1.8)\n", + "len_simulation = len(Dat_u)\n", + "\n", + "# for i in range(time_step_for_plotting-1,time_step_for_plotting):\n", + "i = time_step_for_plotting-1\n", + "d = Dat_u[i]\n", + "num_wf = len(d)\n", + "\n", + "lines_LGARTO = axs[0].hlines(0,0,0,color='k',lw=1)\n", + "###plots theta vs depth\n", + "for j in range(num_wf):\n", + " if j ==0 :\n", + " axs[0].vlines(d[j][1],0,d[j][0]*0.1,color='k',lw=1)\n", + " else:\n", + " axs[0].vlines(d[j][1],d[j-1][0]*0.1,d[j][0]*0.1,color='k',lw=1)\n", + " lines_LGARTO = axs[0].hlines(d[j-1][0]*0.1,d[j-1][1],d[j][1],color='k',lw=1)\n", + "\n", + "axs[0].set_ylim(0,layer_depth[-1])\n", + "axs[0].invert_yaxis()\n", + "axs[0].set_xlim(0,0.5)\n", + "\n", + "axs[0].set_ylabel('Depth (cm)',fontsize=12)\n", + "axs[0].set_xlabel('Volumetric water content (-)',fontsize=12)\n", + "\n", + "count = 0\n", + "for k in layer_depth:\n", + " #print (k)\n", + " if (k!=layer_depth[-1]):\n", + " axs[0].vlines(theta_e_vec[count], ymin=k, ymax=layer_depth[count+1],color='blue')\n", + "\n", + " if ((count==1)|(count==2)):\n", + " axs[0].hlines(k, xmin=theta_e_vec[count], xmax=theta_e_vec[count-1],color='blue')\n", + "\n", + " if (k==layer_depth[-1]):\n", + " axs[0].axhline(k, ls='solid', color='black', lw=1, zorder=10)\n", + " else:\n", + " axs[0].axhline(k, ls='dashed', color='lightgrey', lw=1, zorder=10)\n", + "\n", + " count = count + 1\n", + "\n", + "\n", + "\n", + "\n", + "max_val_psi = 0\n", + "for row in d:\n", + " if (max_val_psi