1
Fork 0

Bathy to stl + porosity

This commit is contained in:
Edgar P. Burkhart 2022-03-04 13:11:31 +01:00
parent c64ba2b31c
commit 764e2cc5bc
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
4 changed files with 43 additions and 13 deletions

2
olaflow/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/inp*
/out*

8
olaflow/config.ini Normal file
View file

@ -0,0 +1,8 @@
[swash]
npz_out=../swash/inp_post
[bathy]
bathy=../swash/data/bathyhires.dat
hstru=../swash/data/Hstru.dat
scale=[0.5,10,1]
out=out_bathy

View file

@ -2,12 +2,11 @@ import argparse
import configparser
import logging
import pathlib
import subprocess
import tempfile
import shutil
import numpy as np
from .stl import stl_from_1d
parser = argparse.ArgumentParser(
description="Convert swash output to olaFlow input"
)
@ -22,14 +21,17 @@ config = configparser.ConfigParser()
config.read("config.ini")
bathy = np.loadtxt(config.get("bathy", "bathy"))
poro = bathy + np.loadtxt(config.get("bathy", "hstru"))
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"))
out = pathlib.Path(config.get("bathy", "out"))
out.mkdir(exist_ok=True)
stl_from_1d(
bathy,
out.joinpath("bathy.stl"),
config.get("bathy", "scale"),
)
stl_from_1d(
poro,
out.joinpath("poro.stl"),
config.get("bathy", "scale"),
)

18
olaflow/processing/stl.py Normal file
View file

@ -0,0 +1,18 @@
import pathlib
import shutil
import subprocess
import tempfile
import numpy as np
def stl_from_1d(data, output, scale=[1, 1, 1]):
with tempfile.TemporaryDirectory() as tmppath:
tmpdir = pathlib.Path(tmppath)
np.savetxt(tmpdir.joinpath("data.dat"), np.stack((data, data)))
with open(tmpdir.joinpath("scad"), "wt") as scad:
scad.write(f"""scale({scale})surface("data.dat");""")
subprocess.run(("openscad", "scad", "-o", "data.stl"), cwd=tmpdir)
shutil.copy2(tmpdir.joinpath("data.stl"), output)