1
Fork 0

Use npz in post

This commit is contained in:
Edgar P. Burkhart 2022-03-03 16:02:52 +01:00
parent a51c727349
commit 1a789ced40
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 11 additions and 17 deletions

1
swash/.gitignore vendored
View file

@ -1,2 +1,3 @@
/inp*
/out*
/swash_buoytoartha

View file

@ -27,25 +27,18 @@ root = pathlib.Path(config.get("swash", "out"))
log.info(f"Reading bathymetry from '{cache}'")
bathy = pd.read_hdf(cache.joinpath("bathy.h5"), "bathy")
n = bathy.index.size
log.info(f"Reading swash output from '{root}'")
botl = read_nohead_scalar(root.joinpath("botl.dat"), n)
dep = np.maximum(0, read_nohead_scalar(root.joinpath("dep.dat"), n))
vel = read_nohead_vect(root.joinpath("vel.dat"), n)
dt = config.getfloat("post", "dt")
n_t = botl.shape[0]
t = np.arange(0, n_t * dt, dt)
data = np.load(pathlib.Path(config.get("post", "inp")).joinpath("sws.npz"))
x, t = data["x"], data["t"]
# Cospectral calculations
x0 = config.getint("post", "x0")
t0 = config.getint("post", "t0")
t0 = config.getfloat("post", "t0")
dt = config.getfloat("post", "dt")
f = 1 / dt
log.info(f"Computing reflection coefficient at x={x0}")
eta = (dep - botl)[t > t0, x0]
u = vel[t > t0, 0, x0]
eta = (data["dep"] - data["botl"])[t > t0, x0]
u = data["vel"][t > t0, 0, x0]
phi_eta = np.abs(sgl.csd(eta, eta, f))
phi_u = np.abs(sgl.csd(u, u, f))
@ -60,13 +53,13 @@ R = np.sqrt(
log.info("Plotting results")
fig, (ax_dep, ax_vel) = plt.subplots(2)
ax_dep.plot(t, (dep - botl)[:, x0], label="dep")
ax_dep.plot(t, data["dep"][:, x0] - data["botl"][x0], label="dep")
ax_dep.set(xlabel="t (s)", ylabel="z (m)")
ax_dep.autoscale(axis="x", tight=True)
ax_dep.grid()
ax_dep.axvline(t0, c="k", alpha=0.2)
ax_vel.plot(t, vel[:, 0, x0], label="vel")
ax_vel.plot(t, data["vel"][:, 0, x0], label="vel")
ax_vel.set(xlabel="t (s)", ylabel="U (m/s)")
ax_vel.autoscale(axis="x", tight=True)
ax_vel.grid()
@ -82,8 +75,8 @@ ax_r.set(ylim=(0, 1), xlabel="f (Hz)", ylabel="R")
ax_r.grid()
fig_x, ax_x = plt.subplots()
ax_x.plot(-botl[0, :], color="k")
ax_x.plot((dep - botl)[t == t0, :].T)
ax_x.plot(-data["botl"], color="k")
ax_x.plot(data["dep"][t == t0, :] - data["botl"])
ax_x.axvline(x0, c="k", alpha=0.2)
ax_x.set(xlabel="x (m)", ylabel="z (m)")
ax_x.autoscale(axis="x", tight=True)