1
Fork 0
internship/swash/processing/sws_npz.py

49 lines
1.4 KiB
Python

import argparse
import configparser
import logging
import pathlib
from multiprocessing.pool import ThreadPool
import numpy as np
from .read_swash import ReadSwash
parser = argparse.ArgumentParser(description="Convert swash output to numpy")
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("sws_npz")
log.info("Starting sws -> npz converter")
config = configparser.ConfigParser()
config.read(args.config)
sws_out = pathlib.Path(config.get("swash", "out"))
inp = pathlib.Path(config.get("post", "inp"))
inp.mkdir(parents=True, exist_ok=True)
log.info(f"Reading swash output from '{sws_out}'")
rsws = ReadSwash()
np.save(inp.joinpath("tsec"), rsws.read_time(sws_out.joinpath("tsec.dat")))
np.save(inp.joinpath("xp"), rsws.read_x(sws_out.joinpath("xp.dat")))
var = {
# "dep": rsws.read_scalar,
"botl": rsws.read_const,
"watl": rsws.read_scalar,
# "pressk": rsws.read_scalar_lay,
# "nhprsk": rsws.read_scalar_lay,
# "zk": rsws.read_scalar_lay,
# "velk": rsws.read_vector_lay,
# "vz": rsws.read_scalar_lay,
"vel": rsws.read_vector,
}
for name, f in var.items():
log.info(f"Converting {name}")
np.save(
inp.joinpath(name),
f(sws_out.joinpath(name).with_suffix(".dat")),
)