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

50 lines
1.4 KiB
Python
Raw Normal View History

2022-03-03 15:44:39 +01:00
import argparse
import configparser
import logging
import pathlib
2022-03-16 07:50:44 +01:00
from multiprocessing.pool import ThreadPool
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
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)
2022-03-29 09:38:11 +02:00
parser.add_argument("-c", "--config", default="config.ini")
2022-03-03 15:44:39 +01:00
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()
2022-03-29 09:38:11 +02:00
config.read(args.config)
2022-03-03 15:44:39 +01:00
sws_out = pathlib.Path(config.get("swash", "out"))
inp = pathlib.Path(config.get("post", "inp"))
2022-03-29 10:52:42 +02:00
inp.mkdir(parents=True, exist_ok=True)
2022-03-03 15:44:39 +01:00
log.info(f"Reading swash output from '{sws_out}'")
rsws = ReadSwash()
2022-03-15 11:45:29 +01:00
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")))
2022-03-15 11:37:59 +01:00
var = {
2022-04-07 11:51:03 +02:00
# "dep": rsws.read_scalar,
2022-03-30 11:20:43 +02:00
"botl": rsws.read_const,
"watl": rsws.read_scalar,
2022-04-07 11:51:03 +02:00
# "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,
2022-03-30 11:20:43 +02:00
"vel": rsws.read_vector,
2022-03-15 11:37:59 +01:00
}
2022-04-07 11:06:17 +02:00
for name, f in var.items():
log.info(f"Converting {name}")
np.save(
inp.joinpath(name),
f(sws_out.joinpath(name).with_suffix(".dat")),
2022-03-15 11:37:59 +01:00
)