1
Fork 0

Black reformat + favor non gzip pickle

This commit is contained in:
Edgar P. Burkhart 2022-04-15 10:31:55 +02:00
parent ec5a503c63
commit 47bf31fb3a
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
4 changed files with 36 additions and 19 deletions

View File

@ -27,9 +27,11 @@ config.read(args.config)
out = pathlib.Path(config.get("post", "out"))
out.mkdir(parents=True, exist_ok=True)
with gzip.open(gzf, "rb") if (
gzf := out.joinpath("pickle.gz")
).exists() else gzf.with_suffix("").open("rb") as f:
with (
path.open("rb")
if (path := out.joinpath("pickle")).exists()
else gzip.open(path.with_suffix(".gz"), "rb")
) as f:
model = pickle.load(f)
x0 = config.getfloat("post", "x")
@ -85,13 +87,26 @@ def anim(i):
aw_m.set_array(AW[i])
figU, axU = plt.subplots(figsize=(19.2, 10.8), dpi=100)
u_m = axU.pcolormesh(
X, Z, U[0], cmap="BuPu", vmin=0, vmax=np.nanquantile(U, .99), zorder=1, alpha=np.nan_to_num(AW[0]).clip(0, 1)
X,
Z,
U[0],
cmap="BuPu",
vmin=0,
vmax=np.nanquantile(U, 0.99),
zorder=1,
alpha=np.nan_to_num(AW[0]).clip(0, 1),
)
ur_m = axU.pcolormesh(
X, Z, U[0], cmap="YlOrBr", vmin=0, vmax=np.nanquantile(U, .99), zorder=1, alpha=1-np.nan_to_num(AW[0]).clip(0, 1)
X,
Z,
U[0],
cmap="YlOrBr",
vmin=0,
vmax=np.nanquantile(U, 0.99),
zorder=1,
alpha=1 - np.nan_to_num(AW[0]).clip(0, 1),
)
# aw_u = axU.contour(X, Z, AW[0], levels=(.5,))
figU.colorbar(u_m)
@ -112,11 +127,11 @@ def animU(i):
u_m.set_array(U[i])
u_m.set_alpha(np.nan_to_num(AW[i]).clip(0, 1))
ur_m.set_array(U[i])
ur_m.set_alpha(1-np.nan_to_num(AW[i]).clip(0, 1))
ur_m.set_alpha(1 - np.nan_to_num(AW[i]).clip(0, 1))
ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1/24)
aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1/24)
ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1 / 24)
aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1 / 24)
ani.save(out.joinpath("anim.mp4"), fps=24)
aniU.save(out.joinpath("animU.mp4"), fps=24)

View File

@ -29,9 +29,11 @@ config.read(args.config)
out = pathlib.Path(config.get("post", "out"))
out.mkdir(parents=True, exist_ok=True)
with gzip.open(gzf, "rb") if (
gzf := out.joinpath("pickle.gz")
).exists() else gzf.with_suffix("").open("rb") as f:
with (
path.open("rb")
if (path := out.joinpath("pickle")).exists()
else gzip.open(path.with_suffix(".gz"), "rb")
) as f:
model = pickle.load(f)
x0_conf = config.getfloat("post", "x")
@ -67,10 +69,10 @@ with plt.rc_context(
ha = ax1.plot(model.t, U, lw=1)
ax1.set(xlabel="t (s)", ylabel="U (m/s)")
ax2.plot(model.t, P*1e-3, lw=1)
ax2.plot(model.t, P * 1e-3, lw=1)
ax2.set(xlabel="t (s)", ylabel="P (kPa)")
ax3.plot(model.t, P_rgh*1e-3, lw=1)
ax3.plot(model.t, P_rgh * 1e-3, lw=1)
ax3.set(xlabel="t (s)", ylabel="P_rgh (kPa)")
for a in ax:
@ -81,8 +83,8 @@ with plt.rc_context(
list(
starmap(lambda x, z: f"x={x:8}m; z={z:8}m", zip(model.x[i0], model.z[i0]))
),
bbox_to_anchor=(1.05, .5),
loc="center left"
bbox_to_anchor=(1.05, 0.5),
loc="center left",
)
plt.show()

View File

@ -33,7 +33,7 @@ t0 = config.getfloat("olaflow", "t0")
x = data("x")
t = data("t")
arg_t0 = np.argmin(np.abs(t - t0*1e3))
arg_t0 = np.argmin(np.abs(t - t0 * 1e3))
watl = data("watl")
zk = data("zk")
@ -44,7 +44,7 @@ olaflow_root = args.output
model = OFModel(olaflow_root)
model.read_mesh()
level = config.getfloat("bathy", "level", fallback=0.)
level = config.getfloat("bathy", "level", fallback=0.0)
watl_t = interpolate.interp1d(x, watl[arg_t0] + level)
alpha_water = np.where(model.z < watl_t(model.x), 1, 0)

View File

@ -22,7 +22,7 @@ log = logging.getLogger("sws_ola")
log.info("Starting sws -> olaFlow converter")
config = configparser.ConfigParser()
config.read(args.config)
level = config.getfloat("bathy", "level", fallback=0.)
level = config.getfloat("bathy", "level", fallback=0.0)
sws_out = pathlib.Path(config.get("swash", "np_out"))