Bathy to stl + porosity
This commit is contained in:
parent
c64ba2b31c
commit
764e2cc5bc
4 changed files with 43 additions and 13 deletions
2
olaflow/.gitignore
vendored
Normal file
2
olaflow/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/inp*
|
||||||
|
/out*
|
8
olaflow/config.ini
Normal file
8
olaflow/config.ini
Normal 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
|
|
@ -2,12 +2,11 @@ import argparse
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
from .stl import stl_from_1d
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Convert swash output to olaFlow input"
|
description="Convert swash output to olaFlow input"
|
||||||
)
|
)
|
||||||
|
@ -22,14 +21,17 @@ config = configparser.ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
|
|
||||||
bathy = np.loadtxt(config.get("bathy", "bathy"))
|
bathy = np.loadtxt(config.get("bathy", "bathy"))
|
||||||
|
poro = bathy + np.loadtxt(config.get("bathy", "hstru"))
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmppath:
|
out = pathlib.Path(config.get("bathy", "out"))
|
||||||
tmpdir = pathlib.Path(tmppath)
|
out.mkdir(exist_ok=True)
|
||||||
np.savetxt(tmpdir.joinpath("bathy.dat"), np.stack((bathy, bathy)))
|
stl_from_1d(
|
||||||
shutil.copy2(
|
bathy,
|
||||||
pathlib.Path(config.get("bathy", "scad")), tmpdir.joinpath("scad")
|
out.joinpath("bathy.stl"),
|
||||||
)
|
config.get("bathy", "scale"),
|
||||||
|
)
|
||||||
subprocess.run(("openscad", "scad", "-o", "bathy.stl"), cwd=tmpdir)
|
stl_from_1d(
|
||||||
|
poro,
|
||||||
shutil.copy2(tmpdir.joinpath("bathy.stl"), config.get("bathy", "out"))
|
out.joinpath("poro.stl"),
|
||||||
|
config.get("bathy", "scale"),
|
||||||
|
)
|
||||||
|
|
18
olaflow/processing/stl.py
Normal file
18
olaflow/processing/stl.py
Normal 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)
|
Loading…
Reference in a new issue