Changed swash reading procedure to read time and space data from output
This commit is contained in:
parent
2a2793f92e
commit
868e34777e
2 changed files with 59 additions and 32 deletions
|
@ -1,28 +1,55 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
def read_nohead(path):
|
class ReadSwash:
|
||||||
|
def __init__(self):
|
||||||
|
self._n_x = None
|
||||||
|
self._n_t = None
|
||||||
|
self._t = None
|
||||||
|
self._x = None
|
||||||
|
self._data = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def read_nohead(cls, path):
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
return file.read()
|
return np.asarray(file.read().split(), dtype=np.float64)
|
||||||
|
|
||||||
|
def read_time(self, path):
|
||||||
|
self._t = np.unique(self.read_nohead(path))
|
||||||
|
self._n_t = self._t.size
|
||||||
|
|
||||||
def read_reshape(path, shape):
|
def read_x(self, path):
|
||||||
return np.asarray(read_nohead(path).split(), dtype=np.float64).reshape(
|
self._x = np.unique(self.read_nohead(path))
|
||||||
shape
|
self._n_x = self._x.size
|
||||||
|
|
||||||
|
def read_scalar(self, path):
|
||||||
|
self._data[path.stem] = self.read_nohead(path).reshape(
|
||||||
|
(self._n_t, self._n_x)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def read_vector(self, path):
|
||||||
|
self._data[path.stem] = self.read_nohead(path).reshape(
|
||||||
|
(self._n_t, 2, self._n_x)
|
||||||
|
)
|
||||||
|
|
||||||
def read_nohead_scalar(path, n):
|
def read_scalar_lay(self, path):
|
||||||
return read_reshape(path, (-1, n))
|
self._data[path.stem] = self.read_nohead(path).reshape(
|
||||||
|
(self._n_t, -1, self._n_x)
|
||||||
|
)
|
||||||
|
|
||||||
|
def read_vector_lay(self, path):
|
||||||
|
self._data[path.stem] = self.read_nohead(path).reshape(
|
||||||
|
(self._n_t, 2, -1, self._n_x)
|
||||||
|
)
|
||||||
|
|
||||||
def read_nohead_k(path, n, k):
|
@property
|
||||||
return read_reshape(path, (-1, n, k))
|
def t(self):
|
||||||
|
return self._t
|
||||||
|
|
||||||
|
@property
|
||||||
|
def x(self):
|
||||||
|
return self._x
|
||||||
|
|
||||||
def read_nohead_vect(path, n):
|
@property
|
||||||
return read_reshape(path, (-1, 2, n))
|
def data(self):
|
||||||
|
return self._data
|
||||||
|
|
||||||
def read_nohead_vect_k(path, n):
|
|
||||||
return read_reshape(path, (-1, 2, n, k))
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import pathlib
|
|
||||||
import logging
|
import logging
|
||||||
|
import pathlib
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
from .read_swash import *
|
from .read_swash import ReadSwash
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Convert swash output to numpy")
|
parser = argparse.ArgumentParser(description="Convert swash output to numpy")
|
||||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||||
|
@ -19,25 +18,26 @@ log.info("Starting sws -> npz converter")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
|
|
||||||
data_out = pathlib.Path(config.get("data", "out"))
|
|
||||||
sws_out = pathlib.Path(config.get("swash", "out"))
|
sws_out = pathlib.Path(config.get("swash", "out"))
|
||||||
inp = pathlib.Path(config.get("post", "inp"))
|
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}'")
|
log.info(f"Reading swash output from '{sws_out}'")
|
||||||
botl = read_nohead_scalar(sws_out.joinpath("botl.dat"), n_x)
|
rsws = ReadSwash()
|
||||||
dep = np.maximum(0, read_nohead_scalar(sws_out.joinpath("dep.dat"), n_x))
|
rsws.read_time(sws_out.joinpath("tsec.dat"))
|
||||||
vel = read_nohead_vect(sws_out.joinpath("vel.dat"), n_x)
|
rsws.read_x(sws_out.joinpath("xp.dat"))
|
||||||
|
|
||||||
dt = config.getfloat("post", "dt")
|
rsws.read_scalar(sws_out.joinpath("dep.dat"))
|
||||||
n_t = botl.shape[0]
|
rsws.read_scalar(sws_out.joinpath("botl.dat"))
|
||||||
t = np.arange(0, n_t * dt, dt)
|
rsws.read_scalar(sws_out.joinpath("watl.dat"))
|
||||||
|
rsws.read_scalar(sws_out.joinpath("press.dat"))
|
||||||
|
rsws.read_vector(sws_out.joinpath("disch.dat"))
|
||||||
|
rsws.read_scalar(sws_out.joinpath("ustar.dat"))
|
||||||
|
rsws.read_vector(sws_out.joinpath("vel.dat"))
|
||||||
|
rsws.read_scalar_lay(sws_out.joinpath("vz.dat"))
|
||||||
|
rsws.read_vector_lay(sws_out.joinpath("velk.dat"))
|
||||||
|
rsws.read_scalar_lay(sws_out.joinpath("zk.dat"))
|
||||||
|
rsws.read_scalar(sws_out.joinpath("brkp.dat"))
|
||||||
|
|
||||||
log.info(f"Writing npz file in '{inp}'")
|
log.info(f"Writing npz file in '{inp}'")
|
||||||
inp.mkdir(exist_ok=True)
|
inp.mkdir(exist_ok=True)
|
||||||
np.savez_compressed(
|
np.savez_compressed(inp.joinpath("sws"), t=rsws.t, x=rsws.x, *rsws.data)
|
||||||
inp.joinpath("sws"), x=bathy.index, t=t, botl=botl[0, :], dep=dep, vel=vel
|
|
||||||
)
|
|
||||||
|
|
Reference in a new issue