From 81f7a1299ba0f141346f148a6e1f36176cea7e4f Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 29 Mar 2022 09:47:45 +0200 Subject: [PATCH] isort + black reformat --- data/processing/projection.py | 25 ++++++++++--------------- data/processing/subdomain.py | 12 +++--------- olaflow/processing/bathy.py | 4 +--- olaflow/processing/sws_ola.py | 13 +++++++------ swash/processing/animate.py | 2 ++ swash/processing/layers.py | 1 + swash/processing/post.py | 16 ++++++++-------- 7 files changed, 32 insertions(+), 41 deletions(-) diff --git a/data/processing/projection.py b/data/processing/projection.py index 4add6bc..da8f5ae 100644 --- a/data/processing/projection.py +++ b/data/processing/projection.py @@ -5,6 +5,7 @@ import pathlib import numpy as np from scipy import interpolate + try: import matplotlib.pyplot as plt except ImportError: @@ -49,9 +50,7 @@ log.debug(f"Cartesian bathy: {bathy}") artha_curvi = np.array( (config.getfloat("artha", "lon"), config.getfloat("artha", "lat")) ) -buoy_curvi = np.array( - (config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat")) -) +buoy_curvi = np.array((config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat"))) artha = np.asarray(projection.cartesian(*artha_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] log.debug(f"Z crossing: {z_crossing}") -x_min_hires = x[z_crossing] + ( - 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_min_hires = x[z_crossing] + (bathy_hires[:, 0].min() - 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}]") flt_x = (x > x_min_hires) & (x < x_max_hires) @@ -114,21 +109,21 @@ else: hstru_in = np.loadtxt(hstru_inp)[::-1] hstru[flt_x] = interpolate.griddata( - (bathy_hires[:,0],), + (bathy_hires[:, 0],), hstru_in, (x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]), ) - + poro_in = np.loadtxt(poro_inp)[::-1] poro[flt_x] = interpolate.griddata( - (bathy_hires[:,0],), + (bathy_hires[:, 0],), poro_in, (x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]), ) - + psize_in = np.loadtxt(psize_inp)[::-1] psize[flt_x] = interpolate.griddata( - (bathy_hires[:,0],), + (bathy_hires[:, 0],), psize_in, (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): fig, ax = plt.subplots() 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")) diff --git a/data/processing/subdomain.py b/data/processing/subdomain.py index edba50a..06e3c16 100644 --- a/data/processing/subdomain.py +++ b/data/processing/subdomain.py @@ -17,12 +17,8 @@ log.info("Starting bathymetry pre-processing") config = configparser.ConfigParser() config.read(args.config) -artha = np.array( - (config.getfloat("artha", "lon"), config.getfloat("artha", "lat")) -) -buoy = np.array( - (config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat")) -) +artha = np.array((config.getfloat("artha", "lon"), config.getfloat("artha", "lat"))) +buoy = np.array((config.getfloat("buoy", "lon"), config.getfloat("buoy", "lat"))) log.debug(f"artha: {artha}") log.debug(f"buoy: {buoy}") @@ -44,9 +40,7 @@ raw_bathy = np.loadtxt(bathy_inp) log.debug(f"Initial size: {raw_bathy.shape}") bathy = raw_bathy[ - ((raw_bathy[:, :2] > domain[0]) & (raw_bathy[:, :2] < domain[1])).all( - axis=1 - ) + ((raw_bathy[:, :2] > domain[0]) & (raw_bathy[:, :2] < domain[1])).all(axis=1) ] del raw_bathy log.debug(f"Final size: {bathy.shape}") diff --git a/olaflow/processing/bathy.py b/olaflow/processing/bathy.py index 85834cf..128acf8 100644 --- a/olaflow/processing/bathy.py +++ b/olaflow/processing/bathy.py @@ -7,9 +7,7 @@ import numpy as np from .stl import stl_from_1d -parser = argparse.ArgumentParser( - description="Convert swash output to olaFlow input" -) +parser = argparse.ArgumentParser(description="Convert swash output to olaFlow input") parser.add_argument("-v", "--verbose", action="count", default=0) parser.add_argument("-c", "--config", default="config.ini") args = parser.parse_args() diff --git a/olaflow/processing/sws_ola.py b/olaflow/processing/sws_ola.py index dd67763..4a0d4aa 100644 --- a/olaflow/processing/sws_ola.py +++ b/olaflow/processing/sws_ola.py @@ -3,15 +3,13 @@ import configparser import logging import pathlib +import matplotlib.pyplot as plt import numpy as np from scipy import interpolate -import matplotlib.pyplot as plt from .olaflow import OFModel -parser = argparse.ArgumentParser( - description="Convert swash output to olaFlow input" -) +parser = argparse.ArgumentParser(description="Convert swash output to olaFlow input") parser.add_argument("-v", "--verbose", action="count", default=0) parser.add_argument("-c", "--config", default="config.ini") args = parser.parse_args() @@ -24,9 +22,12 @@ config = configparser.ConfigParser() config.read(args.config) sws_out = pathlib.Path(config.get("swash", "np_out")) + + def data(var): return np.load(sws_out.joinpath(f"{var}.npy")) + x = data("xp") 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) 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) 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) 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_vector_field("U", np.stack((ux, uy, uz)).T) diff --git a/swash/processing/animate.py b/swash/processing/animate.py index 6749f74..1162399 100644 --- a/swash/processing/animate.py +++ b/swash/processing/animate.py @@ -24,9 +24,11 @@ root = pathlib.Path(config.get("swash", "out")) out = pathlib.Path(config.get("plot", "out")) out.mkdir(exist_ok=True) + def data(var): return np.load(inp.joinpath(f"{var}.npy")) + x = data("xp") t = data("tsec") diff --git a/swash/processing/layers.py b/swash/processing/layers.py index b1943dc..e2d2f05 100644 --- a/swash/processing/layers.py +++ b/swash/processing/layers.py @@ -24,6 +24,7 @@ root = pathlib.Path(config.get("swash", "out")) out = pathlib.Path(config.get("plot", "out")) out.mkdir(exist_ok=True) + def data(var): return np.load(inp.joinpath(f"{var}.npy")) diff --git a/swash/processing/post.py b/swash/processing/post.py index 671153c..ca6a785 100644 --- a/swash/processing/post.py +++ b/swash/processing/post.py @@ -56,13 +56,13 @@ G = H / U th_eta_u = np.angle(phi_eta_u[1]) 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)) -#) +# ) if config.has_option("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]) 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_)) - #) + # ) # Plotting