From d69a39f25bcc57e8f55a835d75754a56c87bb6db Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 10 Mar 2022 10:56:19 +0100 Subject: [PATCH] Animate swash output --- swash/processing/animate.py | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 swash/processing/animate.py diff --git a/swash/processing/animate.py b/swash/processing/animate.py new file mode 100644 index 0000000..a316d15 --- /dev/null +++ b/swash/processing/animate.py @@ -0,0 +1,54 @@ +import argparse +import configparser +import logging +import pathlib + +import matplotlib.pyplot as plt +import matplotlib.animation as animation +import numpy as np +import pandas as pd + + +parser = argparse.ArgumentParser(description="Animate swash output") +parser.add_argument("-v", "--verbose", action="count", default=0) +args = parser.parse_args() + +logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) +log = logging.getLogger("post") + +log.info("Starting post-processing") +config = configparser.ConfigParser() +config.read("config.ini") + +inp = pathlib.Path(config.get("post", "inp")) +root = pathlib.Path(config.get("swash", "out")) + +data = np.load(inp.joinpath(config.get("post", "case"))) +bathy = pd.read_hdf( + pathlib.Path(config.get("data", "out")).joinpath("bathy.h5"), "bathy" +) + +x = data["x"] +t = data["t"] + +wl = np.maximum(data["watl"], -data["botl"]) +print(x.size, -np.arange(0, 1 * bathy.hstru.size, 1)[::-1].size) + +fig, ax = plt.subplots() +ax.plot(x, -data["botl"], c="k") +ax.fill_between( + x, -data["botl"], -data["botl"] + bathy.hstru, color="k", alpha=0.2 +) +(line,) = ax.plot(x, wl[0]) + + +def animate(i): + line.set_ydata(wl[i]) + return (line,) + + +ani = animation.FuncAnimation( + fig, animate, frames=wl[:, 0].size, interval=20, blit=True +) + +plt.show(block=True)