Added post-processing config
This commit is contained in:
parent
14ff5eef13
commit
55d19e710f
2 changed files with 21 additions and 2 deletions
|
@ -17,3 +17,5 @@ out=out
|
|||
|
||||
[post]
|
||||
out=out_post
|
||||
dt=0.25
|
||||
x0=125
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import configparser
|
||||
import pathlib
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
@ -9,15 +11,25 @@ import scipy.signal as sgl
|
|||
from .read_swash import *
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="Pre-process bathymetry")
|
||||
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")
|
||||
|
||||
cache = pathlib.Path(config.get("data", "out"))
|
||||
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)
|
||||
|
@ -25,8 +37,9 @@ vel = read_nohead_vect(root.joinpath("vel.dat"), n)
|
|||
n_t = botl.shape[0]
|
||||
|
||||
# Cospectral calculations
|
||||
pos_x = n // 10
|
||||
f = 1 / 0.25
|
||||
pos_x = config.getint("post", "x0")
|
||||
f = 1 / config.getfloat("post", "dt")
|
||||
log.info(f"Computing reflection coefficient at x={pos_x}")
|
||||
|
||||
eta = (dep - botl)[n_t // 2 :, pos_x]
|
||||
u = vel[n_t // 2 :, 0, pos_x]
|
||||
|
@ -41,6 +54,7 @@ R = np.sqrt(
|
|||
)
|
||||
|
||||
# Plotting
|
||||
log.info("Plotting results")
|
||||
fig, (ax_dep, ax_vel) = plt.subplots(2)
|
||||
|
||||
ax_dep.plot((dep - botl)[:, pos_x], label="dep", color="#0066ff")
|
||||
|
@ -63,7 +77,10 @@ ax_r.set(ylim=(0, 1), xlabel="f (Hz)", ylabel="R")
|
|||
ax_r.grid()
|
||||
|
||||
out = pathlib.Path(config.get("post", "out"))
|
||||
log.info(f"Saving plots in '{out}'")
|
||||
out.mkdir(exist_ok=True)
|
||||
|
||||
fig.savefig(out.joinpath(f"{pos_x}.png"))
|
||||
fig_r.savefig(out.joinpath(f"R{pos_x}.png"))
|
||||
|
||||
log.info("Finished post-processing")
|
||||
|
|
Loading…
Reference in a new issue