Switched to new storage convention for swash output in sws_ola
This commit is contained in:
parent
b557712372
commit
71049d49ea
63 changed files with 174 additions and 5717 deletions
4
data/.gitignore
vendored
4
data/.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
/out
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:17bc194f27793ae12ccd604a1f667d03cc6f9b07222f4e67d633b7296cc97e24
|
||||
size 5
|
||||
|
|
|
@ -1,26 +1,3 @@
|
|||
[inp]
|
||||
root=data
|
||||
base=Database_20220224.xyz
|
||||
hires=bathyhires.dat
|
||||
hstru=Hstru.dat
|
||||
poro=Poro.dat
|
||||
psize=Psize.dat
|
||||
hires_step=0.5
|
||||
|
||||
[out]
|
||||
no_breakwater=True
|
||||
root=out
|
||||
sub=bathy_sub.npy
|
||||
out=bathy.npy
|
||||
step=1
|
||||
left=0
|
||||
right=150
|
||||
#plot=True
|
||||
|
||||
[artha]
|
||||
lat=43.398450
|
||||
lon=-1.673097
|
||||
|
||||
[buoy]
|
||||
lat=43.408333
|
||||
lon=-1.681667
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:13605228ca2c48f7bc869db92b329f5395122662ced9a7ce930241b821a11f7a
|
||||
size 300
|
||||
|
|
|
@ -1,100 +1,3 @@
|
|||
import numpy as np
|
||||
|
||||
|
||||
class Lambert:
|
||||
def __init__(
|
||||
self,
|
||||
X0=1.7e6,
|
||||
Y0=2.2e6,
|
||||
lambda0=3,
|
||||
phi0=43,
|
||||
phi1=42.25,
|
||||
phi2=43.75,
|
||||
a=6378137,
|
||||
e=0.081819190842622,
|
||||
):
|
||||
self._X0 = X0
|
||||
self._Y0 = Y0
|
||||
|
||||
self._lambda0 = np.radians(lambda0)
|
||||
self._phi0 = np.radians(phi0)
|
||||
self._phi1 = np.radians(phi1)
|
||||
self._phi2 = np.radians(phi2)
|
||||
|
||||
self._a = a
|
||||
self._e = e
|
||||
|
||||
self._set_n()
|
||||
self._set_rho0()
|
||||
|
||||
def cartesian(self, lam, phi):
|
||||
lam = np.radians(lam)
|
||||
phi = np.radians(phi)
|
||||
|
||||
theta = self._n * (lam - self._lambda0)
|
||||
rho = self._rho(phi)
|
||||
rho0 = self._rho(self._phi0)
|
||||
|
||||
X = self._X0 + rho * np.sin(theta)
|
||||
Y = self._Y0 + rho0 - rho * np.cos(theta)
|
||||
|
||||
return X, Y
|
||||
|
||||
def _set_n(self):
|
||||
self._n = (
|
||||
np.log(np.cos(self._phi2) / np.cos(self._phi1))
|
||||
+ (
|
||||
np.log(
|
||||
(1 - (self._e * np.sin(self._phi1) ** 2))
|
||||
/ (1 - (self._e * np.sin(self._phi2) ** 2))
|
||||
)
|
||||
/ 2
|
||||
)
|
||||
) / (
|
||||
np.log(
|
||||
(
|
||||
np.tan(self._phi1 / 2 + np.pi / 4)
|
||||
* (
|
||||
(1 - self._e * np.sin(self._phi2))
|
||||
* (1 + self._e * np.sin(self._phi1))
|
||||
)
|
||||
** (self._e / 2)
|
||||
)
|
||||
/ (
|
||||
np.tan(self._phi2 / 2 + np.pi / 4)
|
||||
* (
|
||||
(1 + self._e * np.sin(self._phi2))
|
||||
* (1 - self._e * np.sin(self._phi1))
|
||||
)
|
||||
** (self._e / 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def _set_rho0(self):
|
||||
self._rho0 = (
|
||||
self._a
|
||||
* np.cos(self._phi1)
|
||||
/ (self._n * np.sqrt(1 - self._e**2 * np.sin(self._phi1) ** 2))
|
||||
* (
|
||||
np.tan(self._phi1 / 2 + np.pi / 4)
|
||||
* (
|
||||
(1 - self._e * np.sin(self._phi1))
|
||||
/ (1 + self._e * np.sin(self._phi1))
|
||||
)
|
||||
** (self._e / 2)
|
||||
)
|
||||
** self._n
|
||||
)
|
||||
|
||||
def _rho(self, phi):
|
||||
return (
|
||||
self._rho0
|
||||
* (
|
||||
1
|
||||
/ np.tan(phi / 2 + np.pi / 4)
|
||||
* ((1 + self._e * np.sin(phi)) / (1 - self._e * np.sin(phi)))
|
||||
** (self._e / 2)
|
||||
)
|
||||
** self._n
|
||||
)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:418acad81c40d8d5dcde803335a86309b51121bab736b553a60c0735ff98cc19
|
||||
size 2601
|
||||
|
|
|
@ -1,144 +1,3 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import numpy as np
|
||||
from scipy import interpolate
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
except ImportError:
|
||||
plt = None
|
||||
|
||||
from .lambert import Lambert
|
||||
|
||||
parser = argparse.ArgumentParser(description="Pre-process bathymetry")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||||
log = logging.getLogger("bathy")
|
||||
|
||||
log.info("Starting bathymetry pre-processing")
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
inp_root = pathlib.Path(config.get("inp", "root"))
|
||||
out_root = pathlib.Path(config.get("out", "root"))
|
||||
bathy_inp = out_root.joinpath(config.get("out", "sub"))
|
||||
hires_inp = inp_root.joinpath(config.get("inp", "hires"))
|
||||
hstru_inp = inp_root.joinpath(config.get("inp", "hstru"))
|
||||
poro_inp = inp_root.joinpath(config.get("inp", "poro"))
|
||||
psize_inp = inp_root.joinpath(config.get("inp", "psize"))
|
||||
bathy_out = inp_root.joinpath(config.get("out", "out"))
|
||||
|
||||
log.info(f"Loading bathymetry from {bathy_inp}")
|
||||
bathy_curvi = np.load(bathy_inp)
|
||||
|
||||
projection = Lambert()
|
||||
bathy = np.stack(
|
||||
(
|
||||
*projection.cartesian(bathy_curvi[:, 0], bathy_curvi[:, 1]),
|
||||
bathy_curvi[:, 2],
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
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"))
|
||||
)
|
||||
|
||||
artha = np.asarray(projection.cartesian(*artha_curvi))
|
||||
buoy = np.asarray(projection.cartesian(*buoy_curvi))
|
||||
|
||||
D = np.diff(np.stack((artha, buoy)), axis=0)
|
||||
x = np.arange(
|
||||
config.getfloat("out", "left", fallback=0),
|
||||
np.sqrt((D**2).sum()) + config.getfloat("out", "right", fallback=0),
|
||||
config.getfloat("out", "step", fallback=1),
|
||||
)
|
||||
theta = np.angle(D.dot((1, 1j)))
|
||||
|
||||
coords = artha + (x * np.stack((np.cos(theta), np.sin(theta)))).T
|
||||
|
||||
log.info("Interpolating bathymetry in 1D")
|
||||
z = interpolate.griddata(bathy[:, :2], bathy[:, 2], coords)
|
||||
log.debug(f"z: {z}")
|
||||
|
||||
_hires = np.loadtxt(hires_inp)[::-1]
|
||||
bathy_hires = np.stack(
|
||||
(
|
||||
np.linspace(
|
||||
0,
|
||||
(_hires.size - 1) * config.getfloat("inp", "hires_step"),
|
||||
_hires.size,
|
||||
),
|
||||
_hires,
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
del _hires
|
||||
log.debug(f"Bathy hires: {bathy_hires}")
|
||||
|
||||
z_cr = 5
|
||||
hires_crossing = np.diff(np.signbit(bathy_hires[:, 1] - z_cr)).nonzero()[0][-1]
|
||||
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]
|
||||
)
|
||||
log.debug(f"Replacing range: [{x_min_hires},{x_max_hires}]")
|
||||
|
||||
flt_x = (x > x_min_hires) & (x < x_max_hires)
|
||||
hstru = np.zeros(z.shape)
|
||||
poro = np.zeros(z.shape)
|
||||
psize = np.zeros(z.shape)
|
||||
if config.getboolean("out", "no_breakwater", fallback=False):
|
||||
z[flt_x] = z[flt_x][-1]
|
||||
else:
|
||||
z[flt_x] = interpolate.griddata(
|
||||
(bathy_hires[:, 0],),
|
||||
bathy_hires[:, 1],
|
||||
(x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]),
|
||||
)
|
||||
|
||||
hstru_in = np.loadtxt(hstru_inp)[::-1]
|
||||
hstru[flt_x] = interpolate.griddata(
|
||||
(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],),
|
||||
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],),
|
||||
psize_in,
|
||||
(x[flt_x] - x[z_crossing] + bathy_hires[hires_crossing, 0]),
|
||||
)
|
||||
|
||||
np.savetxt(out_root.joinpath("bathy.dat"), z[::-1], newline=" ")
|
||||
np.savetxt(out_root.joinpath("hstru.dat"), hstru[::-1], newline=" ")
|
||||
np.savetxt(out_root.joinpath("poro.dat"), poro[::-1], newline=" ")
|
||||
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)
|
||||
plt.show(block=True)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:45448faf5475a6aac61efe9b3f69e20a7e44bdcb7e493d7e8d7c8d1cb7eac5fd
|
||||
size 4370
|
||||
|
|
|
@ -1,53 +1,3 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import numpy as np
|
||||
|
||||
parser = argparse.ArgumentParser(description="Pre-process bathymetry")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||||
log = logging.getLogger("bathy")
|
||||
|
||||
log.info("Starting bathymetry pre-processing")
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
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}")
|
||||
|
||||
domain = np.stack((artha, buoy))
|
||||
domain.sort(axis=0)
|
||||
log.debug(f"domain: {domain}")
|
||||
|
||||
domain[0] -= 0.002
|
||||
domain[1] += 0.002
|
||||
log.debug(f"domain: {domain}")
|
||||
|
||||
inp_root = pathlib.Path(config.get("inp", "root"))
|
||||
out_root = pathlib.Path(config.get("out", "root"))
|
||||
bathy_inp = inp_root.joinpath(config.get("inp", "base"))
|
||||
bathy_out = out_root.joinpath(config.get("out", "sub"))
|
||||
log.info(f"Reading bathymetry from '{bathy_inp}'")
|
||||
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
|
||||
)
|
||||
]
|
||||
del raw_bathy
|
||||
log.debug(f"Final size: {bathy.shape}")
|
||||
|
||||
log.info(f"Saving subdomain to 'bathy'")
|
||||
np.save(bathy_out, bathy)
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cee15595a8dac4e684da41c7b1cb9b80bd091a6879407ad516114d46addd0af0
|
||||
size 1435
|
||||
|
|
Reference in a new issue