1
Fork 0
internship/olaflow/processing/sws_wavedict_irregular.py

55 lines
1.5 KiB
Python
Raw Normal View History

2022-04-08 13:18:55 +02:00
import argparse
import configparser
import logging
import pathlib
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
from scipy import fft
from .olaflow import OFModel
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()
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
log = logging.getLogger("sws_ola")
log.info("Starting sws -> olaFlow converter")
log.warning("This does not provide the correct boundary condition")
2022-04-08 13:18:55 +02:00
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("x")
t = data("t")[-100:]
2022-04-08 13:18:55 +02:00
watl = data("watl")
2022-04-08 13:41:14 +02:00
arg_x0 = np.argmin(np.abs(x + 1250))
2022-04-08 13:18:55 +02:00
wl = watl[-100:, arg_x0]
2022-04-08 13:18:55 +02:00
2022-04-08 13:41:14 +02:00
f = fft.rfftfreq(t.size, np.diff(t).mean())[1:]
w_fft = fft.rfft(wl, norm="forward")[1:]
2022-04-08 13:18:55 +02:00
amp = np.abs(w_fft)
phi = np.angle(w_fft)
2022-04-08 13:41:14 +02:00
olaflow_root = pathlib.Path(config.get("olaflow", "root"))
org = olaflow_root.joinpath("constant", "waveDict_irregular.org").read_text()
org = org.replace("{n}", str(f.size))
2022-04-08 13:41:14 +02:00
org = org.replace("{wh}", "\n".join(amp.astype(np.str_)))
org = org.replace("{wph}", "\n".join(phi.astype(np.str_)))
org = org.replace("{wper}", "\n".join((1 / f).astype(np.str_)))
olaflow_root.joinpath("constant", "waveDict").write_text(org)
2022-04-08 13:18:55 +02:00
print(f, amp, phi, sep="\n")