Pre-processing
This commit is contained in:
parent
0461cb7e08
commit
f816c25865
2 changed files with 30 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
[proc]
|
[proc]
|
||||||
plot=True
|
#plot=True
|
||||||
|
|
||||||
[data]
|
[data]
|
||||||
root=data
|
root=data
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
@ -12,7 +13,11 @@ except ImportError:
|
||||||
plt = None
|
plt = None
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level="INFO")
|
parser = argparse.ArgumentParser(description="Pre-process bathymetry")
|
||||||
|
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||||||
log = logging.getLogger("bathy")
|
log = logging.getLogger("bathy")
|
||||||
|
|
||||||
log.info("Starting bathymetry pre-processing")
|
log.info("Starting bathymetry pre-processing")
|
||||||
|
@ -25,6 +30,8 @@ log.info(f"Reading input data from '{root}'")
|
||||||
bathy_hires = np.loadtxt(root.joinpath(config.get("data", "hires")))
|
bathy_hires = np.loadtxt(root.joinpath(config.get("data", "hires")))
|
||||||
bathy_lores = np.loadtxt(root.joinpath(config.get("data", "bathy")))
|
bathy_lores = np.loadtxt(root.joinpath(config.get("data", "bathy")))
|
||||||
hstru = np.loadtxt(root.joinpath(config.get("data", "hstru")))
|
hstru = np.loadtxt(root.joinpath(config.get("data", "hstru")))
|
||||||
|
poro = np.loadtxt(root.joinpath(config.get("data", "poro")))
|
||||||
|
psize = np.loadtxt(root.joinpath(config.get("data", "psize")))
|
||||||
|
|
||||||
log.info("Generating grid")
|
log.info("Generating grid")
|
||||||
x_hires = np.arange(-0.5 * bathy_hires.size, 0, 0.5)
|
x_hires = np.arange(-0.5 * bathy_hires.size, 0, 0.5)
|
||||||
|
@ -37,19 +44,33 @@ bathy_lores_pd = pd.Series(bathy_lores.copy(), index=x_lores)
|
||||||
|
|
||||||
bathy = pd.DataFrame(
|
bathy = pd.DataFrame(
|
||||||
index=bathy_lores_pd.index.union(bathy_hires_pd.index),
|
index=bathy_lores_pd.index.union(bathy_hires_pd.index),
|
||||||
columns=("z", "hstru"),
|
columns=("z", "hstru", "poro", "psize"),
|
||||||
|
data=0,
|
||||||
)
|
)
|
||||||
bathy.z[bathy_lores_pd.index] = bathy_lores_pd
|
bathy.z[bathy_lores_pd.index] = bathy_lores_pd
|
||||||
bathy.z[bathy_hires_pd.index] = bathy_hires_pd
|
bathy.z[bathy_hires_pd.index] = bathy_hires_pd
|
||||||
|
|
||||||
bathy.hstru = 0
|
bathy.loc[x_hstru, ("hstru", "poro", "psize")] = np.array(
|
||||||
bathy.loc[x_hstru, "hstru"] = hstru
|
(hstru, poro, psize)
|
||||||
|
).T
|
||||||
|
|
||||||
|
bathy = bathy.reindex(bathy_lores_pd.index)
|
||||||
|
log.debug(f"Bathymetry:\n{bathy}")
|
||||||
|
log.info(
|
||||||
|
f"xmin: {bathy.index.min()}, "
|
||||||
|
f"xmax: {bathy.index.max()}, "
|
||||||
|
f"n: {bathy.index.size}"
|
||||||
|
)
|
||||||
|
|
||||||
if config.has_section("out"):
|
if config.has_section("out"):
|
||||||
log.info("Writing output data")
|
|
||||||
out = pathlib.Path(config.get("out", "root"))
|
out = pathlib.Path(config.get("out", "root"))
|
||||||
|
log.info(f"Writing output data to '{out}'")
|
||||||
np.savetxt(out.joinpath("bathy.dat"), bathy.z, newline=" ")
|
np.savetxt(out.joinpath("bathy.dat"), bathy.z, newline=" ")
|
||||||
np.savetxt(out.joinpath("hstru.dat"), bathy.hstru, newline=" ")
|
np.savetxt(out.joinpath("hstru.dat"), bathy.hstru, newline=" ")
|
||||||
|
np.savetxt(out.joinpath("poro.dat"), bathy.poro, newline=" ")
|
||||||
|
np.savetxt(out.joinpath("psize.dat"), bathy.psize, newline=" ")
|
||||||
|
|
||||||
|
bathy.to_hdf(out.joinpath("bathy.h5"), "bathy", mode="w")
|
||||||
|
|
||||||
if config.getboolean("proc", "plot", fallback=False):
|
if config.getboolean("proc", "plot", fallback=False):
|
||||||
if plt is None:
|
if plt is None:
|
||||||
|
@ -63,6 +84,8 @@ if config.getboolean("proc", "plot", fallback=False):
|
||||||
ax.plot(x_lores, bathy_lores, label="Low-res")
|
ax.plot(x_lores, bathy_lores, label="Low-res")
|
||||||
ax.plot(bathy.index, bathy.z, ls="-.", c="k", label="Combined")
|
ax.plot(bathy.index, bathy.z, ls="-.", c="k", label="Combined")
|
||||||
ax.plot(bathy.index, bathy.hstru, label="Hstru")
|
ax.plot(bathy.index, bathy.hstru, label="Hstru")
|
||||||
|
ax.plot(bathy.index, bathy.poro, label="Poro")
|
||||||
|
ax.plot(bathy.index, bathy.psize, label="Psize")
|
||||||
|
|
||||||
ax.grid()
|
ax.grid()
|
||||||
ax.legend()
|
ax.legend()
|
||||||
|
|
Loading…
Reference in a new issue