Black reformat + favor non gzip pickle
This commit is contained in:
parent
ec5a503c63
commit
47bf31fb3a
4 changed files with 36 additions and 19 deletions
|
@ -27,9 +27,11 @@ config.read(args.config)
|
||||||
out = pathlib.Path(config.get("post", "out"))
|
out = pathlib.Path(config.get("post", "out"))
|
||||||
out.mkdir(parents=True, exist_ok=True)
|
out.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with gzip.open(gzf, "rb") if (
|
with (
|
||||||
gzf := out.joinpath("pickle.gz")
|
path.open("rb")
|
||||||
).exists() else gzf.with_suffix("").open("rb") as f:
|
if (path := out.joinpath("pickle")).exists()
|
||||||
|
else gzip.open(path.with_suffix(".gz"), "rb")
|
||||||
|
) as f:
|
||||||
model = pickle.load(f)
|
model = pickle.load(f)
|
||||||
|
|
||||||
x0 = config.getfloat("post", "x")
|
x0 = config.getfloat("post", "x")
|
||||||
|
@ -85,13 +87,26 @@ def anim(i):
|
||||||
aw_m.set_array(AW[i])
|
aw_m.set_array(AW[i])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
figU, axU = plt.subplots(figsize=(19.2, 10.8), dpi=100)
|
figU, axU = plt.subplots(figsize=(19.2, 10.8), dpi=100)
|
||||||
u_m = axU.pcolormesh(
|
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(
|
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,))
|
# aw_u = axU.contour(X, Z, AW[0], levels=(.5,))
|
||||||
figU.colorbar(u_m)
|
figU.colorbar(u_m)
|
||||||
|
@ -112,11 +127,11 @@ def animU(i):
|
||||||
u_m.set_array(U[i])
|
u_m.set_array(U[i])
|
||||||
u_m.set_alpha(np.nan_to_num(AW[i]).clip(0, 1))
|
u_m.set_alpha(np.nan_to_num(AW[i]).clip(0, 1))
|
||||||
ur_m.set_array(U[i])
|
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)
|
ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1 / 24)
|
||||||
aniU = animation.FuncAnimation(figU, animU, 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)
|
ani.save(out.joinpath("anim.mp4"), fps=24)
|
||||||
aniU.save(out.joinpath("animU.mp4"), fps=24)
|
aniU.save(out.joinpath("animU.mp4"), fps=24)
|
||||||
|
|
|
@ -29,9 +29,11 @@ config.read(args.config)
|
||||||
out = pathlib.Path(config.get("post", "out"))
|
out = pathlib.Path(config.get("post", "out"))
|
||||||
out.mkdir(parents=True, exist_ok=True)
|
out.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with gzip.open(gzf, "rb") if (
|
with (
|
||||||
gzf := out.joinpath("pickle.gz")
|
path.open("rb")
|
||||||
).exists() else gzf.with_suffix("").open("rb") as f:
|
if (path := out.joinpath("pickle")).exists()
|
||||||
|
else gzip.open(path.with_suffix(".gz"), "rb")
|
||||||
|
) as f:
|
||||||
model = pickle.load(f)
|
model = pickle.load(f)
|
||||||
|
|
||||||
x0_conf = config.getfloat("post", "x")
|
x0_conf = config.getfloat("post", "x")
|
||||||
|
@ -67,10 +69,10 @@ with plt.rc_context(
|
||||||
ha = ax1.plot(model.t, U, lw=1)
|
ha = ax1.plot(model.t, U, lw=1)
|
||||||
ax1.set(xlabel="t (s)", ylabel="U (m/s)")
|
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)")
|
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)")
|
ax3.set(xlabel="t (s)", ylabel="P_rgh (kPa)")
|
||||||
|
|
||||||
for a in ax:
|
for a in ax:
|
||||||
|
@ -81,8 +83,8 @@ with plt.rc_context(
|
||||||
list(
|
list(
|
||||||
starmap(lambda x, z: f"x={x:8}m; z={z:8}m", zip(model.x[i0], model.z[i0]))
|
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),
|
bbox_to_anchor=(1.05, 0.5),
|
||||||
loc="center left"
|
loc="center left",
|
||||||
)
|
)
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
|
@ -33,7 +33,7 @@ t0 = config.getfloat("olaflow", "t0")
|
||||||
x = data("x")
|
x = data("x")
|
||||||
t = data("t")
|
t = data("t")
|
||||||
|
|
||||||
arg_t0 = np.argmin(np.abs(t - t0*1e3))
|
arg_t0 = np.argmin(np.abs(t - t0 * 1e3))
|
||||||
|
|
||||||
watl = data("watl")
|
watl = data("watl")
|
||||||
zk = data("zk")
|
zk = data("zk")
|
||||||
|
@ -44,7 +44,7 @@ olaflow_root = args.output
|
||||||
model = OFModel(olaflow_root)
|
model = OFModel(olaflow_root)
|
||||||
model.read_mesh()
|
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)
|
watl_t = interpolate.interp1d(x, watl[arg_t0] + level)
|
||||||
alpha_water = np.where(model.z < watl_t(model.x), 1, 0)
|
alpha_water = np.where(model.z < watl_t(model.x), 1, 0)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ log = logging.getLogger("sws_ola")
|
||||||
log.info("Starting sws -> olaFlow converter")
|
log.info("Starting sws -> olaFlow converter")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(args.config)
|
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"))
|
sws_out = pathlib.Path(config.get("swash", "np_out"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue