1
Fork 0

isort + black reformat

This commit is contained in:
Edgar P. Burkhart 2022-03-29 09:47:45 +02:00
parent cf54c91fa8
commit 81f7a1299b
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
7 changed files with 32 additions and 41 deletions
data/processing
olaflow/processing
swash/processing

View file

@ -5,6 +5,7 @@ import pathlib
import numpy as np import numpy as np
from scipy import interpolate from scipy import interpolate
try: try:
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
except ImportError: except ImportError:
@ -49,9 +50,7 @@ log.debug(f"Cartesian bathy: {bathy}")
artha_curvi = np.array( artha_curvi = np.array(
(config.getfloat("artha", "lon"), config.getfloat("artha", "lat")) (config.getfloat("artha", "lon"), config.getfloat("artha", "lat"))
) )
buoy_curvi = np.array( buoy_curvi = np.array((config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat")))
(config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat"))
)
artha = np.asarray(projection.cartesian(*artha_curvi)) artha = np.asarray(projection.cartesian(*artha_curvi))
buoy = np.asarray(projection.cartesian(*buoy_curvi)) buoy = np.asarray(projection.cartesian(*buoy_curvi))
@ -91,12 +90,8 @@ log.debug(f"Hires crossing: {hires_crossing}")
z_crossing = np.diff(np.signbit(z - z_cr)).nonzero()[0][-1] z_crossing = np.diff(np.signbit(z - z_cr)).nonzero()[0][-1]
log.debug(f"Z crossing: {z_crossing}") log.debug(f"Z crossing: {z_crossing}")
x_min_hires = x[z_crossing] + ( x_min_hires = x[z_crossing] + (bathy_hires[:, 0].min() - bathy_hires[hires_crossing, 0])
bathy_hires[:, 0].min() - bathy_hires[hires_crossing, 0] x_max_hires = x[z_crossing] + (bathy_hires[:, 0].max() - bathy_hires[hires_crossing, 0])
)
x_max_hires = x[z_crossing] + (
bathy_hires[:, 0].max() - bathy_hires[hires_crossing, 0]
)
log.debug(f"Replacing range: [{x_min_hires},{x_max_hires}]") log.debug(f"Replacing range: [{x_min_hires},{x_max_hires}]")
flt_x = (x > x_min_hires) & (x < x_max_hires) flt_x = (x > x_min_hires) & (x < x_max_hires)
@ -114,21 +109,21 @@ else:
hstru_in = np.loadtxt(hstru_inp)[::-1] hstru_in = np.loadtxt(hstru_inp)[::-1]
hstru[flt_x] = interpolate.griddata( hstru[flt_x] = interpolate.griddata(
(bathy_hires[:,0],), (bathy_hires[:, 0],),
hstru_in, hstru_in,
(x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]), (x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]),
) )
poro_in = np.loadtxt(poro_inp)[::-1] poro_in = np.loadtxt(poro_inp)[::-1]
poro[flt_x] = interpolate.griddata( poro[flt_x] = interpolate.griddata(
(bathy_hires[:,0],), (bathy_hires[:, 0],),
poro_in, poro_in,
(x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]), (x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]),
) )
psize_in = np.loadtxt(psize_inp)[::-1] psize_in = np.loadtxt(psize_inp)[::-1]
psize[flt_x] = interpolate.griddata( psize[flt_x] = interpolate.griddata(
(bathy_hires[:,0],), (bathy_hires[:, 0],),
psize_in, psize_in,
(x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]), (x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]),
) )
@ -141,5 +136,5 @@ np.savetxt(out_root.joinpath("psize.dat"), psize[::-1], newline=" ")
if plt is not None and config.getboolean("out", "plot", fallback=False): if plt is not None and config.getboolean("out", "plot", fallback=False):
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot(-x, z, color="k") ax.plot(-x, z, color="k")
ax.fill_between(-x, z+hstru, z, color="k", alpha=.2) ax.fill_between(-x, z + hstru, z, color="k", alpha=0.2)
fig.savefig(out_root.joinpath("bathy.pdf")) fig.savefig(out_root.joinpath("bathy.pdf"))

View file

@ -17,12 +17,8 @@ log.info("Starting bathymetry pre-processing")
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(args.config) config.read(args.config)
artha = np.array( artha = np.array((config.getfloat("artha", "lon"), config.getfloat("artha", "lat")))
(config.getfloat("artha", "lon"), config.getfloat("artha", "lat")) buoy = np.array((config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat")))
)
buoy = np.array(
(config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat"))
)
log.debug(f"artha: {artha}") log.debug(f"artha: {artha}")
log.debug(f"buoy: {buoy}") log.debug(f"buoy: {buoy}")
@ -44,9 +40,7 @@ raw_bathy = np.loadtxt(bathy_inp)
log.debug(f"Initial size: {raw_bathy.shape}") log.debug(f"Initial size: {raw_bathy.shape}")
bathy = raw_bathy[ bathy = raw_bathy[
((raw_bathy[:, :2] > domain[0]) & (raw_bathy[:, :2] < domain[1])).all( ((raw_bathy[:, :2] > domain[0]) & (raw_bathy[:, :2] < domain[1])).all(axis=1)
axis=1
)
] ]
del raw_bathy del raw_bathy
log.debug(f"Final size: {bathy.shape}") log.debug(f"Final size: {bathy.shape}")

View file

@ -7,9 +7,7 @@ import numpy as np
from .stl import stl_from_1d 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"
)
parser.add_argument("-v", "--verbose", action="count", default=0) parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("-c", "--config", default="config.ini") parser.add_argument("-c", "--config", default="config.ini")
args = parser.parse_args() args = parser.parse_args()

View file

@ -3,15 +3,13 @@ import configparser
import logging import logging
import pathlib import pathlib
import matplotlib.pyplot as plt
import numpy as np import numpy as np
from scipy import interpolate from scipy import interpolate
import matplotlib.pyplot as plt
from .olaflow import OFModel from .olaflow import OFModel
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(description="Convert swash output to olaFlow input")
description="Convert swash output to olaFlow input"
)
parser.add_argument("-v", "--verbose", action="count", default=0) parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("-c", "--config", default="config.ini") parser.add_argument("-c", "--config", default="config.ini")
args = parser.parse_args() args = parser.parse_args()
@ -24,9 +22,12 @@ config = configparser.ConfigParser()
config.read(args.config) config.read(args.config)
sws_out = pathlib.Path(config.get("swash", "np_out")) sws_out = pathlib.Path(config.get("swash", "np_out"))
def data(var): def data(var):
return np.load(sws_out.joinpath(f"{var}.npy")) return np.load(sws_out.joinpath(f"{var}.npy"))
x = data("xp") x = data("xp")
t = data("tsec") t = data("tsec")
@ -43,7 +44,7 @@ watl_t = interpolate.interp1d(x, watl[680])
alpha_water = np.where(model.z < watl_t(model.x), 1, 0) alpha_water = np.where(model.z < watl_t(model.x), 1, 0)
zk_t = interpolate.interp1d(x, zk[680]) zk_t = interpolate.interp1d(x, zk[680])
velk_t = interpolate.interp1d(x, velk[680,:,0,:])(model.x) velk_t = interpolate.interp1d(x, velk[680, :, 0, :])(model.x)
vz_t = interpolate.interp1d(x, vz[680])(model.x) vz_t = interpolate.interp1d(x, vz[680])(model.x)
zk_tl = zk_t(model.x) zk_tl = zk_t(model.x)
@ -56,6 +57,6 @@ for zk_l, velk_l, vz_l in zip(zk_tl, velk_t, vz_t):
ux = np.where(model.z < zk_l, velk_l, ux) ux = np.where(model.z < zk_l, velk_l, ux)
uz = np.where(model.z < zk_l, vz_l, uz) uz = np.where(model.z < zk_l, vz_l, uz)
print(np.stack((ux,uy,uz)).T) print(np.stack((ux, uy, uz)).T)
model.write_field("alpha.water", alpha_water) model.write_field("alpha.water", alpha_water)
model.write_vector_field("U", np.stack((ux, uy, uz)).T) model.write_vector_field("U", np.stack((ux, uy, uz)).T)

View file

@ -24,9 +24,11 @@ root = pathlib.Path(config.get("swash", "out"))
out = pathlib.Path(config.get("plot", "out")) out = pathlib.Path(config.get("plot", "out"))
out.mkdir(exist_ok=True) out.mkdir(exist_ok=True)
def data(var): def data(var):
return np.load(inp.joinpath(f"{var}.npy")) return np.load(inp.joinpath(f"{var}.npy"))
x = data("xp") x = data("xp")
t = data("tsec") t = data("tsec")

View file

@ -24,6 +24,7 @@ root = pathlib.Path(config.get("swash", "out"))
out = pathlib.Path(config.get("plot", "out")) out = pathlib.Path(config.get("plot", "out"))
out.mkdir(exist_ok=True) out.mkdir(exist_ok=True)
def data(var): def data(var):
return np.load(inp.joinpath(f"{var}.npy")) return np.load(inp.joinpath(f"{var}.npy"))

View file

@ -56,13 +56,13 @@ G = H / U
th_eta_u = np.angle(phi_eta_u[1]) th_eta_u = np.angle(phi_eta_u[1])
R = np.sqrt( R = np.sqrt(
(np.abs(phi_eta[1]) + np.abs(phi_u[1]) - 2 * np.abs(phi_eta_u[1])) (np.abs(phi_eta[1]) + np.abs(phi_u[1]) - 2 * np.abs(phi_eta_u[1]))
/ (np.abs(phi_eta[1]) + np.abs(phi_u[1]) + 2 * np.abs(phi_eta_u[1])) / (np.abs(phi_eta[1]) + np.abs(phi_u[1]) + 2 * np.abs(phi_eta_u[1]))
) )
#R = np.sqrt( # R = np.sqrt(
# (1 + G**2 - 2 * G * np.cos(th_eta_u)) # (1 + G**2 - 2 * G * np.cos(th_eta_u))
# / (1 + G**2 + 2 * G * np.cos(th_eta_u)) # / (1 + G**2 + 2 * G * np.cos(th_eta_u))
#) # )
if config.has_option("post", "compare"): if config.has_option("post", "compare"):
inp_comp = pathlib.Path(config.get("post", "compare")) inp_comp = pathlib.Path(config.get("post", "compare"))
@ -89,13 +89,13 @@ if config.has_option("post", "compare"):
th_eta_u_ = np.angle(phi_eta_u_[1]) th_eta_u_ = np.angle(phi_eta_u_[1])
R_ = np.sqrt( R_ = np.sqrt(
(np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) - 2 * np.abs(phi_eta_u_[1])) (np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) - 2 * np.abs(phi_eta_u_[1]))
/ (np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) + 2 * np.abs(phi_eta_u_[1])) / (np.abs(phi_eta_[1]) + np.abs(phi_u_[1]) + 2 * np.abs(phi_eta_u_[1]))
) )
#R_ = np.sqrt( # R_ = np.sqrt(
# (1 + G_**2 - 2 * G_ * np.cos(th_eta_u_)) # (1 + G_**2 - 2 * G_ * np.cos(th_eta_u_))
# / (1 + G_**2 + 2 * G_ * np.cos(th_eta_u_)) # / (1 + G_**2 + 2 * G_ * np.cos(th_eta_u_))
#) # )
# Plotting # Plotting