From c64ba2b31cd4409755068a283203bccfd7a51633 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 4 Mar 2022 12:50:00 +0100 Subject: [PATCH] Added bathymetry generation for olaFlow (stl) --- olaflow/processing/bathy.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 olaflow/processing/bathy.py diff --git a/olaflow/processing/bathy.py b/olaflow/processing/bathy.py new file mode 100644 index 0000000..ad61b3e --- /dev/null +++ b/olaflow/processing/bathy.py @@ -0,0 +1,35 @@ +import argparse +import configparser +import logging +import pathlib +import subprocess +import tempfile +import shutil + +import numpy as np + +parser = argparse.ArgumentParser( + description="Convert swash output to olaFlow input" +) +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("sws_ola") + +log.info("Starting sws -> olaFlow converter") +config = configparser.ConfigParser() +config.read("config.ini") + +bathy = np.loadtxt(config.get("bathy", "bathy")) + +with tempfile.TemporaryDirectory() as tmppath: + tmpdir = pathlib.Path(tmppath) + np.savetxt(tmpdir.joinpath("bathy.dat"), np.stack((bathy, bathy))) + shutil.copy2( + pathlib.Path(config.get("bathy", "scad")), tmpdir.joinpath("scad") + ) + + subprocess.run(("openscad", "scad", "-o", "bathy.stl"), cwd=tmpdir) + + shutil.copy2(tmpdir.joinpath("bathy.stl"), config.get("bathy", "out"))