1
Fork 0
internship/swash/processing/animate.py

59 lines
1.3 KiB
Python
Raw Normal View History

2022-03-10 10:56:19 +01:00
import argparse
import configparser
import logging
import pathlib
import matplotlib.animation as animation
2022-03-16 07:50:44 +01:00
import matplotlib.pyplot as plt
2022-03-10 10:56:19 +01:00
import numpy as np
parser = argparse.ArgumentParser(description="Animate swash output")
parser.add_argument("-v", "--verbose", action="count", default=0)
2022-03-29 09:38:11 +02:00
parser.add_argument("-c", "--config", default="config.ini")
2022-03-10 10:56:19 +01:00
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()
2022-03-29 09:38:11 +02:00
config.read(args.config)
2022-03-10 10:56:19 +01:00
inp = pathlib.Path(config.get("post", "inp"))
root = pathlib.Path(config.get("swash", "out"))
2022-03-29 10:48:46 +02:00
out = pathlib.Path(config.get("post", "out"))
2022-03-29 15:34:26 +02:00
out.mkdir(parents=True, exist_ok=True)
2022-03-10 10:56:19 +01:00
2022-03-29 09:47:45 +02:00
def data(var):
return np.load(inp.joinpath(f"{var}.npy"))
2022-03-29 09:47:45 +02:00
2022-04-07 11:04:51 +02:00
x = data("x")
#t = data("t")
watl = data("watl")
botl = data("botl")
wl = np.maximum(watl, -botl)
# print(x.size, -np.arange(0, 1 * bathy.hstru.size, 1)[::-1].size)
2022-03-10 10:56:19 +01:00
fig, ax = plt.subplots()
ax.plot(x, -botl, c="k")
# ax.fill_between(
# x, -botl, -data["botl"] + bathy.hstru, color="k", alpha=0.2
# )
2022-03-10 10:56:19 +01:00
(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
)
2022-03-28 14:03:29 +02:00
ani.save(out.joinpath("anim.mp4"))