Merge branch 'master' of ssh://git.edgarpierre.fr:39529/m2cce/internship
This commit is contained in:
commit
166331cd31
6 changed files with 98 additions and 260 deletions
36
swash/README.md
Normal file
36
swash/README.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
# SWASH
|
||||
|
||||
Ce dossier regroupe l'ensemble des scripts nécessaires à l'éxécution du modèle SWASH ainsi qu'au post-traitement des
|
||||
données.
|
||||
|
||||
## Scripts
|
||||
|
||||
### Animate
|
||||
|
||||
`animate.py` permet d'obtenir une animation des résultats de SWASH.
|
||||
|
||||
```python -m processing.animate [-c CONFIG]```
|
||||
|
||||
* `-c CONFIG` : choix du fichier de configuration
|
||||
|
||||
```
|
||||
[post]
|
||||
inp : dossier contenant les données d'entrée
|
||||
out : dossier de sortie
|
||||
```
|
||||
|
||||
### Mat Npz
|
||||
|
||||
`mat_npz` permet de convertir les données de sortie de SWASH en données Numpy plus facile à exploiter en Python.
|
||||
|
||||
```python -m processing.mat_npz [-c CONFIG]```
|
||||
|
||||
* `-c CONFIG` : choix du fichier de configuration
|
||||
|
||||
```
|
||||
[swash]
|
||||
out : dossier de sortie de swash
|
||||
|
||||
[post]
|
||||
inp : dossier de sortie pour les données numpy
|
||||
```
|
|
@ -20,7 +20,6 @@ config = configparser.ConfigParser()
|
|||
config.read(args.config)
|
||||
|
||||
inp = pathlib.Path(config.get("post", "inp"))
|
||||
root = pathlib.Path(config.get("swash", "out"))
|
||||
out = pathlib.Path(config.get("post", "out"))
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
import argparse
|
||||
import configparser
|
||||
import logging
|
||||
import pathlib
|
||||
|
||||
import matplotlib.animation as animation
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
parser = argparse.ArgumentParser(description="Animate swash output")
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
parser.add_argument("-c", "--config", default="config.ini")
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
|
||||
log = logging.getLogger("post")
|
||||
|
||||
log.info("Starting post-processing")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(args.config)
|
||||
|
||||
inp = pathlib.Path(config.get("post", "inp"))
|
||||
root = pathlib.Path(config.get("swash", "out"))
|
||||
out = pathlib.Path(config.get("post", "out"))
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def data(var):
|
||||
return np.load(inp.joinpath(f"{var}.npy"))
|
||||
|
||||
|
||||
x = data("xp")
|
||||
t = data("tsec")
|
||||
|
||||
watl = data("watl")
|
||||
botl = data("botl")
|
||||
zk = data("zk")
|
||||
velk = data("velk")
|
||||
vz = data("vz")
|
||||
|
||||
wl = np.maximum(watl, -botl)
|
||||
# print(x.size, -np.arange(0, 1 * bathy.hstru.size, 1)[::-1].size)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
# ax.plot(x, -botl, c="k")
|
||||
# ax.fill_between(
|
||||
# x, -botl, -data["botl"] + bathy.hstru, color="k", alpha=0.2
|
||||
# )
|
||||
|
||||
n = 0
|
||||
vk = np.sqrt((velk[n] ** 2).sum(axis=1))
|
||||
# print(vk.shape)
|
||||
# plt.imshow(vk)
|
||||
# plt.colorbar()
|
||||
|
||||
lines = ax.plot(x, zk[n].T, c="#0066cc")
|
||||
quiv = []
|
||||
for i in range(len(lines) - 1):
|
||||
quiv.append(
|
||||
ax.quiver(
|
||||
x[::50],
|
||||
(zk[n, i, ::50] + zk[n, i + 1, ::50]) / 2,
|
||||
velk[n, i, 0, ::50],
|
||||
vz[n, i, ::50],
|
||||
units="dots",
|
||||
width=2,
|
||||
scale=0.05,
|
||||
)
|
||||
)
|
||||
|
||||
ax.autoscale(True, "w", True)
|
||||
ax.set_ylim(top=15)
|
||||
|
||||
|
||||
def animate(k):
|
||||
for i, q in enumerate(quiv):
|
||||
q.set_UVC(
|
||||
velk[k, i, 0, ::50],
|
||||
vz[k, i, ::50],
|
||||
)
|
||||
for i, l in enumerate(lines):
|
||||
l.set_ydata(zk[k, i])
|
||||
return *quiv, *lines
|
||||
|
||||
|
||||
ani = animation.FuncAnimation(
|
||||
fig, animate, frames=wl[:, 0].size, interval=20, blit=True
|
||||
)
|
||||
|
||||
ani.save(out.joinpath("layers.mp4"))
|
Reference in a new issue