2022-03-03 15:44:39 +01:00
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
import logging
|
2022-03-04 10:21:02 +01:00
|
|
|
import pathlib
|
2022-03-03 15:44:39 +01:00
|
|
|
|
2022-03-04 10:33:26 +01:00
|
|
|
import numpy as np
|
2022-03-03 15:44:39 +01:00
|
|
|
import pandas as pd
|
|
|
|
|
2022-03-04 10:21:02 +01:00
|
|
|
from .read_swash import ReadSwash
|
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")
|
|
|
|
|
|
|
|
sws_out = pathlib.Path(config.get("swash", "out"))
|
|
|
|
inp = pathlib.Path(config.get("post", "inp"))
|
|
|
|
|
|
|
|
log.info(f"Reading swash output from '{sws_out}'")
|
2022-03-04 10:21:02 +01:00
|
|
|
rsws = ReadSwash()
|
|
|
|
rsws.read_time(sws_out.joinpath("tsec.dat"))
|
|
|
|
rsws.read_x(sws_out.joinpath("xp.dat"))
|
|
|
|
|
2022-03-15 10:43:29 +01:00
|
|
|
inp.mkdir(exist_ok=True)
|
|
|
|
log.info(f"Wrinting output in '{inp}'")
|
2022-03-04 10:25:05 +01:00
|
|
|
log.info("Reading 'dep'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(inp.joinpath("dep"), rsws.read_scalar(sws_out.joinpath("dep.dat")))
|
2022-03-04 10:25:05 +01:00
|
|
|
log.info("Reading 'botl'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(
|
|
|
|
inp.joinpath("botl"),
|
|
|
|
rsws.read_scalar(sws_out.joinpath("botl.dat"), const=True),
|
|
|
|
)
|
2022-03-04 10:25:05 +01:00
|
|
|
log.info("Reading 'watl'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(inp.joinpath("watl"), rsws.read_scalar(sws_out.joinpath("watl.dat")))
|
2022-03-04 10:25:05 +01:00
|
|
|
log.info("Reading 'vel'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(inp.joinpath("vel"), rsws.read_vector(sws_out.joinpath("vel.dat")))
|
2022-03-15 10:31:18 +01:00
|
|
|
log.info("Reading 'press'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(inp.joinpath("press"), rsws.read_scalar(sws_out.joinpath("press.dat")))
|
2022-03-15 10:29:55 +01:00
|
|
|
log.info("Reading 'zk'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(inp.joinpath("zk"), rsws.read_scalar_lay(sws_out.joinpath("zk.dat")))
|
2022-03-15 10:29:55 +01:00
|
|
|
log.info("Reading 'velk'")
|
2022-03-15 10:43:29 +01:00
|
|
|
np.save(
|
|
|
|
inp.joinpath("velk"), rsws.read_vector_lay(sws_out.joinpath("velk.dat"))
|
|
|
|
)
|
2022-03-15 10:25:13 +01:00
|
|
|
|
|
|
|
log.info(f"Writing npz file in '{inp}'")
|
|
|
|
inp.mkdir(exist_ok=True)
|
|
|
|
np.savez_compressed(inp.joinpath("sws"), t=rsws.t, x=rsws.x, **rsws.data)
|