From 49dec9b76e523f765949aea4c2ff2de77cabc1d7 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 8 Apr 2022 12:43:53 +0200 Subject: [PATCH] Remove old sws_npz scripts --- swash/processing/read_swash.py | 60 ---------------------------------- swash/processing/sws_npz.py | 49 --------------------------- 2 files changed, 109 deletions(-) delete mode 100644 swash/processing/read_swash.py delete mode 100644 swash/processing/sws_npz.py diff --git a/swash/processing/read_swash.py b/swash/processing/read_swash.py deleted file mode 100644 index 6a4e5dc..0000000 --- a/swash/processing/read_swash.py +++ /dev/null @@ -1,60 +0,0 @@ -import logging -import subprocess -import tempfile - -import numpy as np - - -log = logging.getLogger("read_swash") - - -class ReadSwash: - def __init__(self): - self._n_x = None - self._n_t = None - self._t = None - self._x = None - - @classmethod - def read_nohead(cls, path): - data = [] - with path.open() as inp: - for line in inp: - data += line.split() - - return np.asarray(data, dtype=float) - - def read_time(self, path): - self._t = np.unique(self.read_nohead(path)) - self._n_t = self._t.size - return self.t - - def read_x(self, path): - self._x = np.unique(self.read_nohead(path)) - self._n_x = self._x.size - return self.x - - def read_scalar(self, path, const=False): - if const: - return self.read_nohead(path).reshape((self._n_t, self._n_x))[0, :] - return self.read_nohead(path).reshape((self._n_t, self._n_x)) - - def read_const(self, path): - return self.read_scalar(path, const=True) - - def read_vector(self, path): - return self.read_nohead(path).reshape((self._n_t, 2, self._n_x)) - - def read_scalar_lay(self, path): - return self.read_nohead(path).reshape((self._n_t, -1, self._n_x)) - - def read_vector_lay(self, path): - return self.read_nohead(path).reshape((self._n_t, -1, 2, self._n_x)) - - @property - def t(self): - return self._t - - @property - def x(self): - return self._x diff --git a/swash/processing/sws_npz.py b/swash/processing/sws_npz.py deleted file mode 100644 index 99caabd..0000000 --- a/swash/processing/sws_npz.py +++ /dev/null @@ -1,49 +0,0 @@ -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")), - )