Conversion from swash mat to npy
This commit is contained in:
parent
ffdc0fbc37
commit
d05a80d98d
2 changed files with 73 additions and 5 deletions
52
swash/processing/mat_npz.py
Normal file
52
swash/processing/mat_npz.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import argparse
|
||||
import configparser
|
||||
from datetime import datetime, time
|
||||
import logging
|
||||
import pathlib
|
||||
import re
|
||||
from multiprocessing.pool import ThreadPool
|
||||
|
||||
import numpy as np
|
||||
import scipy.io as sio
|
||||
|
||||
parser = argparse.ArgumentParser(description="Convert swash output to numpy")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
parser.add_argument("-c", "--config", default="config.ini")
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||||
log = logging.getLogger("sws_npz")
|
||||
|
||||
log.info("Starting sws -> npz converter")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
sws_out = pathlib.Path(config.get("swash", "out"))
|
||||
inp = pathlib.Path(config.get("post", "inp"))
|
||||
inp.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
log.info(f"Reading swash output from '{sws_out}'")
|
||||
raw_tsec = sio.loadmat(sws_out.joinpath("tsec.mat"))
|
||||
i = np.fromiter((k[5:] for k in raw_tsec.keys() if re.compile(r"^Tsec_").match(k)), dtype="U10")
|
||||
t = np.fromiter((raw_tsec[f"Tsec_{k}"][0,0]*10**3 for k in i), dtype=np.uintc)
|
||||
np.save(inp.joinpath("t"), t)
|
||||
del raw_tsec
|
||||
raw_xp = sio.loadmat(sws_out.joinpath("xp.mat"), variable_names="Xp")
|
||||
x = raw_xp["Xp"][0]
|
||||
np.save(inp.joinpath("x"), x)
|
||||
del raw_xp
|
||||
|
||||
raw_botl = sio.loadmat(sws_out.joinpath("botl.mat"), variable_names="Botlev")
|
||||
botl = raw_botl["Botlev"][0]
|
||||
np.save(inp.joinpath("botl"), botl)
|
||||
del raw_botl
|
||||
|
||||
raw_watl = sio.loadmat(sws_out.joinpath("watl.mat"))
|
||||
watl = np.asarray([raw_watl[i0][0] for i0 in np.char.add("Watlev_", i)], dtype=np.single)
|
||||
np.save(inp.joinpath("watl"), watl)
|
||||
del raw_watl
|
||||
|
||||
raw_vel = sio.loadmat(sws_out.joinpath("vel.mat"))
|
||||
vel_x = np.asarray([raw_vel[i0][0] for i0 in np.char.add("vel_x_", i)], dtype=np.single)
|
||||
np.save(inp.joinpath("vel_x"), vel_x)
|
||||
del raw_vel
|
|
@ -3,12 +3,12 @@ PROJ 'GW' 'T1'
|
|||
SET NAUT
|
||||
SET LEVEL 4.5
|
||||
SET MAXERR 1
|
||||
SET DEPMIN 0.01
|
||||
$SET DEPMIN 0.001
|
||||
MODE NONST ONED
|
||||
$************************ GRIDS ***************************************
|
||||
CGRID REG -1450 0 0 1750 0 1750 0
|
||||
INPGRID BOT REG -1450 0 0 1750 0 1 0 $x0 y0 theta nx-1 ny-1 dx dy
|
||||
VERT 4
|
||||
VERT 2
|
||||
READ BOTTOM -1 'bathy.dat' 3 0 FREE
|
||||
|
||||
INPGRID PORO REG -1450 0 0 1750 0 1 0
|
||||
|
@ -22,7 +22,8 @@ READINP HSTRUC 1 'hstru.dat' 3 0 FREE
|
|||
|
||||
$*********************** BOUNDARIES ****************************************
|
||||
INIT ZERO
|
||||
BOUN SIDE W BTYPE WEAK SMOOT 10 SEC ADDBOUNDWAVE CON SPECFILE 'spec.dat'
|
||||
BOUN SHAP JON SIG PEAK DSPR DEGR
|
||||
BOUN SIDE W BTYPE WEAK SMOOT 10 SEC ADDBOUNDWAVE CON SPECT 7.31 16.9 0 0 CYCLE 20 MIN
|
||||
SPON E 250
|
||||
|
||||
|
||||
|
@ -39,6 +40,21 @@ TIMEI 0.2 0.6
|
|||
|
||||
$*********************** OUTPUTS *******************************************
|
||||
SET OUTLEV 1
|
||||
BLOCK 'COMPGRID' NOHEAD 'out.mat' LAY 3 TSEC XP DEP BOTL WATL PRESS NHPRSK PRESSK VEL VZ VELK ZK OUTPUT 000000.00 0.25 SEC
|
||||
COMPUTE 000000.000 0.015 SEC 000100.000 $timeini dtini unit timefin
|
||||
$BLOCK 'COMPGRID' HEAD 'test.txt' LAY 4 TSEC XP DEP BOTL WATL PRESS DISCH USTAR VEL VZ VELK ZK BRKP OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'tsec.dat' TSEC OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'xp.dat' XP OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'dep.dat' DEP OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'botl.dat' BOTL OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'watl.dat' WATL OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'press.dat' PRESS OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'nhprsk.dat' NHPRSK OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'pressk.dat' PRESSK OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'disch.dat' DISCH OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'ustar.dat' USTAR OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'vel.dat' VEL OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'vz.dat' VZ OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'velk.dat' VELK OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'zk.dat' ZK OUTPUT 000000.00 0.25 SEC
|
||||
BLOCK 'COMPGRID' NOHEAD 'brkp.dat' BRKP OUTPUT 000000.00 0.25 SEC
|
||||
COMPUTE 000000.000 0.015 SEC 002500.000 $timeini dtini unit timefin
|
||||
STOP
|
||||
|
|
Loading…
Reference in a new issue