From 12ad3b5c597893c101d5bc5c7c869e6440112e23 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 15 Mar 2022 13:34:15 +0100 Subject: [PATCH] Display layered results; fix read_swash for layered vectors --- swash/processing/animate.py | 25 +++++++----- swash/processing/layers.py | 69 ++++++++++++++++++++++++++++++++++ swash/processing/read_swash.py | 2 +- 3 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 swash/processing/layers.py diff --git a/swash/processing/animate.py b/swash/processing/animate.py index a316d15..8f5f894 100644 --- a/swash/processing/animate.py +++ b/swash/processing/animate.py @@ -23,22 +23,29 @@ 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) +def data(var): + return np.load(inp.joinpath(f"{var}.npy")) + + +x = data("xp") +t = data("tsec") + +watl = data("watl") +botl = data("botl") + +wl = np.maximum(watl, -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 -) +ax.plot(x, -botl, c="k") +# ax.fill_between( +# x, -botl, -data["botl"] + bathy.hstru, color="k", alpha=0.2 +# ) (line,) = ax.plot(x, wl[0]) diff --git a/swash/processing/layers.py b/swash/processing/layers.py new file mode 100644 index 0000000..eca3219 --- /dev/null +++ b/swash/processing/layers.py @@ -0,0 +1,69 @@ +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")) + +bathy = pd.read_hdf( + pathlib.Path(config.get("data", "out")).joinpath("bathy.h5"), "bathy" +) + + +def data(var): + return np.load(inp.joinpath(f"{var}.npy")) + + +x = data("xp") +t = data("tsec") + +watl = data("watl") +botl = data("botl") +zk = data("zk") +velk = data("velk") + +wl = np.maximum(watl, -botl) +# print(x.size, -np.arange(0, 1 * bathy.hstru.size, 1)[::-1].size) + +fig, ax = plt.subplots() +ax.plot(x, -botl, c="k") +# ax.fill_between( +# x, -botl, -data["botl"] + bathy.hstru, color="k", alpha=0.2 +# ) +lines = ax.plot(x, zk[0].T) + +print(velk.shape) +velk = velk.reshape((6001, 10, 2, 1251)) +vk = np.sqrt((velk[1000] ** 2).sum(axis=1)) +print(vk.shape) +plt.imshow(vk) +plt.colorbar() + +# def animate(i): +# for line, z in zip(lines, zk[i]): +# line.set_ydata(z) +# return lines +# +# ani = animation.FuncAnimation( +# fig, animate, frames=wl[:, 0].size, interval=20, blit=True +# ) + +plt.show(block=True) diff --git a/swash/processing/read_swash.py b/swash/processing/read_swash.py index e5859da..8a983b7 100644 --- a/swash/processing/read_swash.py +++ b/swash/processing/read_swash.py @@ -41,7 +41,7 @@ class ReadSwash: return self.read_nohead(path).reshape((self._n_t, -1, self._n_x)) def read_vector_lay(self, path): - return self.read_nohead(path).reshape((self._n_t, 2, -1, self._n_x)) + return self.read_nohead(path).reshape((self._n_t, -1, 2, self._n_x)) @property def t(self):