1
Fork 0
internship/olaflow/processing/bathy.py

36 lines
979 B
Python
Raw Normal View History

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"))