Server side scripts & all
This commit is contained in:
parent
a000c67e93
commit
b92e52ecbb
20 changed files with 629 additions and 58 deletions
|
@ -10,5 +10,5 @@ mpi=8
|
|||
[post]
|
||||
inp=inp_post/ts_4lay_1h
|
||||
out=out_post/ts_4lay_1h
|
||||
x0=-1250
|
||||
x0=-50
|
||||
t0=180
|
||||
|
|
|
@ -9,7 +9,7 @@ mpi=8
|
|||
|
||||
[post]
|
||||
inp=inp_post/real_spec_interp
|
||||
#compare=inp_post/real_spec_interp_nb
|
||||
compare=inp_post/real_spec_interp_nb
|
||||
out=out_post/real_spec_interp
|
||||
x0=-1250
|
||||
t0=180
|
||||
|
|
|
@ -7,8 +7,6 @@ import matplotlib.pyplot as plt
|
|||
import numpy as np
|
||||
import scipy.signal as sgl
|
||||
|
||||
from .read_swash import *
|
||||
|
||||
parser = argparse.ArgumentParser(description="Post-process swash output")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
parser.add_argument("-c", "--config", default="config.ini")
|
||||
|
@ -30,7 +28,8 @@ t = np.load(inp.joinpath("t.npy"))
|
|||
|
||||
botl = np.load(inp.joinpath("botl.npy"))
|
||||
watl = np.load(inp.joinpath("watl.npy"))
|
||||
vel = np.load(inp.joinpath("vel_x.npy"))
|
||||
#vel = np.load(inp.joinpath("vel_x.npy"))
|
||||
vel = np.load(inp.joinpath("vel.npy"))[0]
|
||||
|
||||
# Cospectral calculations
|
||||
x0 = config.getint("post", "x0")
|
||||
|
@ -65,22 +64,25 @@ R = np.sqrt(
|
|||
|
||||
if config.has_option("post", "compare"):
|
||||
inp_comp = pathlib.Path(config.get("post", "compare"))
|
||||
x_ = np.load(inp_comp.joinpath("xp.npy"))
|
||||
t_ = np.load(inp_comp.joinpath("tsec.npy"))
|
||||
x_ = np.load(inp_comp.joinpath("x.npy"))
|
||||
t_ = np.load(inp_comp.joinpath("t.npy"))
|
||||
|
||||
botl_ = np.load(inp_comp.joinpath("botl.npy"))
|
||||
watl_ = np.load(inp_comp.joinpath("watl.npy"))
|
||||
vel_ = np.load(inp_comp.joinpath("vel_x.npy"))
|
||||
|
||||
# Cospectral calculations
|
||||
arg_x0_ = np.abs(x_ - x0).argmin()
|
||||
arg_t0_ = np.abs(t_ - t0).argmin()
|
||||
dt_ = np.diff(t_).mean() * 1e-3
|
||||
f_ = 1 / dt_
|
||||
|
||||
eta_ = watl_[t_ > t0, arg_x0_]
|
||||
u_ = vel_[t_ > t0, arg_x0_]
|
||||
|
||||
phi_eta_ = sgl.welch(eta_, f, nperseg=nperseg)
|
||||
phi_u_ = sgl.welch(u_, f, nperseg=nperseg)
|
||||
phi_eta_u_ = sgl.csd(eta_, u_, f, nperseg=nperseg)
|
||||
phi_eta_ = sgl.welch(eta_, f_, nperseg=nperseg)
|
||||
phi_u_ = sgl.welch(u_, f_, nperseg=nperseg)
|
||||
phi_eta_u_ = sgl.csd(eta_, u_, f_, nperseg=nperseg)
|
||||
|
||||
H_ = np.sqrt(np.abs(phi_eta_[1]))
|
||||
U_ = np.sqrt(np.abs(phi_u_[1]))
|
||||
|
@ -91,10 +93,6 @@ if config.has_option("post", "compare"):
|
|||
(np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) - 2 * phi_eta_u_[1].real)
|
||||
/ (np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) + 2 * phi_eta_u_[1].real)
|
||||
)
|
||||
# R_ = np.sqrt(
|
||||
# (1 + G_**2 - 2 * G_ * np.cos(th_eta_u_))
|
||||
# / (1 + G_**2 + 2 * G_ * np.cos(th_eta_u_))
|
||||
# )
|
||||
|
||||
|
||||
# Plotting
|
||||
|
|
|
@ -30,7 +30,7 @@ botl = np.load(inp.joinpath("botl.npy"))
|
|||
watl = np.load(inp.joinpath("watl.npy"))
|
||||
vel = np.load(inp.joinpath("vel.npy"))[0]
|
||||
|
||||
t0 = np.linspace(23 * 60 + 8, 23 * 60 + 8 + 100, 5)
|
||||
t0 = np.linspace(23 * 60 + 8, 23 * 60 + 8 + 100, 6)
|
||||
|
||||
# Plotting
|
||||
log.info("Plotting results")
|
||||
|
@ -38,10 +38,10 @@ log.info("Plotting results")
|
|||
vlim = np.nanmin(np.maximum(watl, -botl)), np.nanmax(np.maximum(watl, -botl))
|
||||
|
||||
fig_x, ax = plt.subplots(
|
||||
len(t0), figsize=(10 / 2.54, 4 / 3 * 10 / 2.54), constrained_layout=True
|
||||
3, 2, figsize=(15 / 2.54, 2 / 3 * 10 / 2.54), constrained_layout=True
|
||||
)
|
||||
i0 = np.argmin(np.abs(t * 1e-3 - t0[0]))
|
||||
for ax_x, t0_x in zip(ax, t0):
|
||||
for ax_x, t0_x in zip(ax.reshape(-1), t0):
|
||||
ax_x.plot(x, -botl, color="k")
|
||||
i = np.argmin(np.abs(t * 1e-3 - t0_x))
|
||||
ax_x.plot(
|
||||
|
@ -67,5 +67,6 @@ log.info(f"Saving plots in '{out}'")
|
|||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
fig_x.savefig(out.joinpath("x.pdf"))
|
||||
fig_x.savefig(out.joinpath("x.jpg"), dpi=200)
|
||||
|
||||
log.info("Finished post-processing")
|
||||
|
|
87
swash/processing/wavelet.py
Normal file
87
swash/processing/wavelet.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import scipy.signal as sgl
|
||||
|
||||
parser = argparse.ArgumentParser(description="Post-process swash output")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
parser.add_argument("-c", "--config", default="config.ini")
|
||||
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(args.config)
|
||||
|
||||
inp = pathlib.Path(config.get("post", "inp"))
|
||||
root = pathlib.Path(config.get("swash", "out"))
|
||||
|
||||
log.info(f"Reading data from '{inp}'")
|
||||
x = np.load(inp.joinpath("x.npy"))
|
||||
t = np.load(inp.joinpath("t.npy")) * 1e-3
|
||||
|
||||
botl = np.load(inp.joinpath("botl.npy"))
|
||||
watl = np.load(inp.joinpath("watl.npy"))
|
||||
vel = np.load(inp.joinpath("vel.npy"))[0]
|
||||
|
||||
# Plotting
|
||||
log.info("Plotting results")
|
||||
|
||||
vlim = np.nanmin(np.maximum(watl, -botl)), np.nanmax(np.maximum(watl, -botl))
|
||||
|
||||
x0 = np.linspace(-600, -200, 5)
|
||||
i0 = np.argmin(np.abs(x[:, None] - x0), axis=0)
|
||||
|
||||
fig_x, ax = plt.subplots(
|
||||
5, 1, figsize=(15 / 2.54, 15/ 2.54), constrained_layout=True
|
||||
)
|
||||
dt = np.mean(np.diff(t))
|
||||
N = t.size
|
||||
s0 = 2 * dt
|
||||
dj = 0.5
|
||||
J = 1 / dj * np.log2(N * dt / s0)
|
||||
j = np.arange(0, J)
|
||||
sj = s0 * 2 ** (j * dj)
|
||||
Mw = sj / dt
|
||||
sig = np.var(watl[:, i0])
|
||||
M = np.stack([(np.abs(sgl.cwt(watl[:, i], sgl.morlet2, Mw))/sig)**2 for i in i0])
|
||||
v = np.max(M)
|
||||
|
||||
for ax_x, M_, x_ in zip(ax.reshape(-1), M, x[i0]):
|
||||
c = ax_x.contourf(t, sj, M_, cmap="Greys", vmin=0, levels=[1, 2.5, 5, 10, 20, 40], extend="both")
|
||||
fig_x.colorbar(c, ax=ax_x, label="NWPS")
|
||||
ax_x.grid(color="k", alpha=0.2)
|
||||
ax_x.text(
|
||||
0.95,
|
||||
0.95,
|
||||
f"x={x_:.0f}m",
|
||||
horizontalalignment="right",
|
||||
verticalalignment="top",
|
||||
transform=ax_x.transAxes,
|
||||
#c="w",
|
||||
)
|
||||
ax_x.semilogy()
|
||||
ax_x.autoscale(True, "both", True)
|
||||
ax_x.set_rasterization_zorder(1.5)
|
||||
ax_x.set(ylabel="T (s)", ylim=(sj[0], sj[-1]))
|
||||
|
||||
if ax_x != ax.reshape(-1)[-1]:
|
||||
ax_x.axes.set_xticklabels([])
|
||||
else:
|
||||
ax_x.set(xlabel="t (s)")
|
||||
|
||||
out = pathlib.Path(config.get("post", "out")).joinpath(f"trans")
|
||||
log.info(f"Saving plots in '{out}'")
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
fig_x.savefig(out.joinpath("wavelet.pdf"), dpi=300)
|
||||
fig_x.savefig(out.joinpath("wavelet.jpg"), dpi=200)
|
||||
fig_x.savefig(out.joinpath("wavelet.png"), dpi=200)
|
||||
|
||||
log.info("Finished post-processing")
|
|
@ -38,6 +38,9 @@ w0_comp = watl_comp[:, arg_x0]
|
|||
cr0 = np.where(np.diff(np.sign(w0)))[0]
|
||||
cr0_comp = np.where(np.diff(np.sign(w0_comp)))[0]
|
||||
|
||||
log.info(f"1: {cr0.size} waves")
|
||||
log.info(f"2: {cr0_comp.size} waves")
|
||||
|
||||
wave = np.fromiter(
|
||||
(
|
||||
np.abs(
|
||||
|
@ -72,9 +75,22 @@ ax.autoscale(True, "x", True)
|
|||
ax.grid()
|
||||
fig.savefig(out.joinpath("wsize.pdf"))
|
||||
|
||||
fig2, ax2 = plt.subplots(figsize=(10/2.54, 2/3*10/2.54), constrained_layout=True)
|
||||
ax2.plot(t[cr0[i0 - 5] : cr0[i0 + 7]] * 1e-3, w0[cr0[i0 - 5] : cr0[i0 + 7]], color="k", label="Case 1")
|
||||
ax2.plot(t[cr0[i0 - 5] : cr0[i0 + 7]] * 1e-3, w0_comp[cr0[i0 - 5] : cr0[i0 + 7]], color="k", ls="-.", label="Case 2")
|
||||
fig2, ax2 = plt.subplots(
|
||||
figsize=(10 / 2.54, 2 / 3 * 10 / 2.54), constrained_layout=True
|
||||
)
|
||||
ax2.plot(
|
||||
t[cr0[i0 - 5] : cr0[i0 + 7]] * 1e-3,
|
||||
w0[cr0[i0 - 5] : cr0[i0 + 7]],
|
||||
color="k",
|
||||
label="Cas 1",
|
||||
)
|
||||
ax2.plot(
|
||||
t[cr0[i0 - 5] : cr0[i0 + 7]] * 1e-3,
|
||||
w0_comp[cr0[i0 - 5] : cr0[i0 + 7]],
|
||||
color="k",
|
||||
ls="-.",
|
||||
label="Cas 2",
|
||||
)
|
||||
ax2.set(xlabel="t (s)", ylabel="z (m)")
|
||||
ax2.autoscale(True, "x", True)
|
||||
ax2.grid()
|
||||
|
@ -82,7 +98,11 @@ ax2.legend()
|
|||
fig2.savefig(out.joinpath("maxw.pdf"))
|
||||
fig2.savefig(out.joinpath("maxw.jpg"), dpi=200)
|
||||
|
||||
log.info(f"RMS difference: {np.sqrt(np.mean((w0_comp-w0)**2))}m ; {np.sqrt(np.mean((w0_comp-w0)**2))/(w0.max()-w0.min()):%}")
|
||||
log.info(
|
||||
f"RMS difference: {np.sqrt(np.mean((w0_comp-w0)**2))}m ; {np.sqrt(np.mean((w0_comp-w0)**2))/(w0.max()-w0.min()):%}"
|
||||
)
|
||||
log.info(f"Bias: {np.mean(w0_comp-w0)}m")
|
||||
log.info(f"Maximum wave size: {wave.max()}m ; {wave_comp.max()}m")
|
||||
log.info(f"Maximum wave size difference: {abs(wave_comp.max()-wave.max())/wave.max():%}")
|
||||
log.info(
|
||||
f"Maximum wave size difference: {abs(wave_comp.max()-wave.max())/wave.max():%}"
|
||||
)
|
||||
|
|
Reference in a new issue