Skip to content
Snippets Groups Projects
Commit 9bd8a99e authored by Florian Zill's avatar Florian Zill Committed by Tobias Meisel
Browse files

Progress Bars

parent ae1b8f8f
No related branches found
No related tags found
No related merge requests found
......@@ -122,6 +122,9 @@ autodoc_typehints = "description"
pyvista.BUILDING_GALLERY = True
pyvista.OFF_SCREEN = True
# Disable progress bars in sphinx
os.environ["TQDM_DISABLE"] = "1"
sphinx_gallery_conf = {
"examples_dirs": ["examples"],
"gallery_dirs": ["auto_examples"],
......
......@@ -24,6 +24,7 @@ mesh_series = examples.meshseries_CT_2D
# Let's use fixed scale limits to prevent rescaling during the animation.
setup.p_min = 0
setup.p_max = 100
setup.dpi = 50
# %%
# You can choose which timesteps to render by passing either an int array
......
# Third-party applications
```{eval-rst}
.. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ)
```
`ogstools` makes use of some several third party python packages:
- [tqdm](https://github.com/tqdm/tqdm): progress bars in computionally
expensive loops
- if you want to globally deactivate them please set the following environt
variable: `os.environ["TQDM_DISABLE"] = "1"`
- ...
......@@ -9,25 +9,13 @@ import matplotlib as mpl
import numpy as np
from matplotlib import figure as mfigure
from matplotlib.animation import FFMpegWriter, FuncAnimation, ImageMagickWriter
from tqdm.auto import tqdm
from ogstools.meshlib import MeshSeries
from ogstools.propertylib import Property
from . import setup
from .core import _plot_on_figure, plot, plt
def timeline(ax: plt.Axes, x: float, xticks: list[float]) -> None:
y = 1.1
ap = {"arrowstyle": "-", "color": "k"}
axfr = "axes fraction"
ax.annotate("", (1, y), (0, y), axfr, arrowprops=ap)
align = dict(ha="center", va="center") # noqa: C408: noqa
for xt in xticks:
ax.annotate("|", (xt, y), (xt, y), axfr, **align, size=28)
align = dict(ha="center", va="center") # noqa: C408: noqa
style = dict(color="g", size=36, weight="bold") # noqa: C408: noqa
ax.annotate("|", (x, y), (x, y), axfr, **align, **style)
from .core import _plot_on_figure, plot
def animate(
......@@ -48,12 +36,7 @@ def animate(
setup.layout = "tight"
ts = mesh_series.timesteps if timesteps is None else timesteps
tv = mesh_series.timevalues
def t_frac(t):
return (t - tv[0]) / (tv[-1] - tv[0])
xticks = [t_frac(t) for t in tv]
fig = plot(mesh_series.read(0, False), property)
def init() -> None:
......@@ -61,10 +44,6 @@ def animate(
def animate_func(i: Union[int, float], fig: mfigure.Figure) -> None:
index = np.argmin(np.abs(np.asarray(ts) - i))
progress = 100 * index / (len(ts) - 1)
bar = "" * int(progress) + "-" * (100 - int(progress))
end = "\n" if index == (len(ts) - 1) else "\r"
print(f"progress: |{bar}| {progress:.2f}% complete", end=end)
fig.axes[-1].remove() # remove colorbar
for ax in np.ravel(fig.axes):
......@@ -78,12 +57,17 @@ def animate(
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fig = _plot_on_figure(fig, mesh, property)
x = i / len(ts) if isinstance(i, int) else t_frac(i)
timeline(fig.axes[0], x, xticks)
_func = partial(animate_func, fig=fig)
return FuncAnimation(
fig, _func, ts, blit=False, interval=50, repeat=False, init_func=init
fig,
_func,
frames=tqdm(ts),
blit=False,
interval=50,
repeat=False,
init_func=init,
)
......@@ -99,7 +83,7 @@ def save_animation(anim: FuncAnimation, filename: str, fps: int) -> bool:
print("Start saving animation...")
codec_args = (
"-crf 28 -preset ultrafast -pix_fmt yuv420p "
"-vf crop='iw-mod(iw,2)':'ih-mod(ih,2)'"
"-vf pad=ceil(iw/2)*2:ceil(ih/2)*2"
).split(" ")
writer = None
......
......@@ -5,6 +5,7 @@ import numpy as np
import pandas as pd
import pyvista as pv
from pint import UnitRegistry
from tqdm.auto import tqdm
from ogstools import meshlib, propertylib
......@@ -270,7 +271,7 @@ def convergence_metrics_evolution(
p_metrics_per_t = np.empty((0, 6))
timestep_sizes = [np.mean(np.diff(ms.timevalues)) for ms in mesh_series]
for timevalue in common_timevalues:
for timevalue in tqdm(common_timevalues):
meshes = [ms.read_closest(timevalue) for ms in mesh_series]
reference = richardson_extrapolation(
meshes, property, meshes[-3], refinement_ratio
......
......@@ -25,6 +25,7 @@ dependencies = [
"papermill>=2.4.0",
"ogs>=6.5.0",
"ogs6py>=0.370",
"tqdm>=4.60",
]
[project.urls]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment