Skip to content

Commit

Permalink
use tqdm for progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Oct 20, 2024
1 parent 01fc7ec commit ee4b05a
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from IPython.display import clear_output\n",
"from tqdm import trange\n",
"\n",
"from landlab import RasterModelGrid\n",
"from landlab.components import river_flow_dynamics\n",
Expand Down Expand Up @@ -154,7 +155,9 @@
"outputs": [],
"source": [
"# The grid represents a basic rectangular channel with slope equal to 0.01 m/m\n",
"te = grid.add_field(\"topographic__elevation\", 1.0 - channel_slope * grid.x_of_node, at=\"node\")\n",
"te = grid.add_field(\n",
" \"topographic__elevation\", 1.0 - channel_slope * grid.x_of_node, at=\"node\"\n",
")\n",
"te[grid.y_of_node > 1.5] = 2.5\n",
"te[grid.y_of_node < 0.5] = 2.5"
]
Expand Down Expand Up @@ -285,24 +288,15 @@
"metadata": {},
"outputs": [],
"source": [
"# The simulation may take a long time to run,\n",
"# so we added a progress report\n",
"progress0 = 0\n",
"\n",
"# Set displayAnimation to True if you want to see how\n",
"# the water moves throughout the channel\n",
"displayAnimation = True\n",
"displayAnimationFreq = 5\n",
"disp = 0\n",
"\n",
"for timestep in range(n_timesteps):\n",
"for timestep in trange(n_timesteps):\n",
" rfd.run_one_step()\n",
"\n",
" progress = int(((timestep + 1) / n_timesteps) * 100)\n",
" if progress > progress0 + 1:\n",
" print(\"\\r\" + f\"Progress: [{progress}%]\", end=\"\")\n",
" progress0 = progress\n",
"\n",
" if disp >= displayAnimationFreq:\n",
" clear_output(wait=True) # This will clear the previous image\n",
" grid.imshow(\"surface_water__depth\")\n",
Expand Down Expand Up @@ -591,24 +585,15 @@
"metadata": {},
"outputs": [],
"source": [
"# The simulation may take a long time to run,\n",
"# so we added a progress report\n",
"progress0 = 0\n",
"\n",
"# Set displayAnimation to True if you want to see how\n",
"# the water moves throughout the channel\n",
"displayAnimation = True\n",
"displayAnimationFreq = 5\n",
"disp = 0\n",
"\n",
"for timestep in range(n_timesteps):\n",
"for timestep in trange(n_timesteps):\n",
" rfd.run_one_step()\n",
"\n",
" progress = int(((timestep + 1) / n_timesteps) * 100)\n",
" if progress > progress0 + 1:\n",
" print(\"\\r\" + f\"Progress: [{progress}%]\", end=\"\")\n",
" progress0 = progress\n",
"\n",
" if disp >= displayAnimationFreq:\n",
" clear_output(wait=True) # This will clear the previous image\n",
" grid.imshow(\"surface_water__depth\")\n",
Expand Down

0 comments on commit ee4b05a

Please sign in to comment.