2022-03-03 15:44:39 +01:00
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
import pathlib
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
|
2022-03-03 15:47:31 +01:00
|
|
|
from .read_swash import *
|
|
|
|
|
2022-03-03 15:44:39 +01:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Convert swash output to numpy")
|
|
|
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
2022-03-03 15:52:31 +01:00
|
|
|
log = logging.getLogger("sws_npz")
|
2022-03-03 15:44:39 +01:00
|
|
|
|
|
|
|
log.info("Starting sws -> npz converter")
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read("config.ini")
|
|
|
|
|
|
|
|
data_out = pathlib.Path(config.get("data", "out"))
|
|
|
|
sws_out = pathlib.Path(config.get("swash", "out"))
|
|
|
|
inp = pathlib.Path(config.get("post", "inp"))
|
|
|
|
|
|
|
|
log.info(f"Reading bathymetry from '{data_out}'")
|
|
|
|
bathy = pd.read_hdf(data_out.joinpath("bathy.h5"), "bathy")
|
|
|
|
n_x = bathy.index.size
|
|
|
|
|
|
|
|
log.info(f"Reading swash output from '{sws_out}'")
|
2022-03-03 15:54:18 +01:00
|
|
|
botl = read_nohead_scalar(sws_out.joinpath("botl.dat"), n_x)[0, :]
|
2022-03-03 15:48:30 +01:00
|
|
|
dep = np.maximum(0, read_nohead_scalar(sws_out.joinpath("dep.dat"), n_x))
|
|
|
|
vel = read_nohead_vect(sws_out.joinpath("vel.dat"), n_x)
|
2022-03-03 15:44:39 +01:00
|
|
|
|
2022-03-03 15:55:48 +01:00
|
|
|
dt = config.getfloat("post", "dt")
|
|
|
|
n_t = botl.shape[0]
|
|
|
|
t = np.arange(0, n_t * dt, dt)
|
|
|
|
|
2022-03-03 15:54:18 +01:00
|
|
|
log.info(f"Writing npz file in '{inp}'")
|
2022-03-03 15:51:40 +01:00
|
|
|
inp.mkdir(exist_ok=True)
|
2022-03-03 15:55:48 +01:00
|
|
|
np.savez_compressed(
|
|
|
|
inp.joinpath("sws"), x=bathy.index, t=t, botl=botl, dep=dep, vel=vel
|
|
|
|
)
|