From 86acc6ff5bf95f355e9e9771c8219d1e3080af0a Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 2 Mar 2022 11:13:06 +0100 Subject: [PATCH] Bathymetry processing (combining low-res and high-res) --- swash/config.ini | 10 ++++++++ swash/processing/bathy.py | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 swash/config.ini create mode 100644 swash/processing/bathy.py diff --git a/swash/config.ini b/swash/config.ini new file mode 100644 index 0000000..75e53d3 --- /dev/null +++ b/swash/config.ini @@ -0,0 +1,10 @@ +[proc] +plot=True + +[data] +root=data +hires=bathyhires.dat +bathy=buoyarthabathy.dat +hstru=Hstru.dat +poro=Poro.dat +psize=Psize.dat diff --git a/swash/processing/bathy.py b/swash/processing/bathy.py new file mode 100644 index 0000000..908e778 --- /dev/null +++ b/swash/processing/bathy.py @@ -0,0 +1,51 @@ +import pathlib +import configparser +import logging +import sys + +import numpy as np +import pandas as pd + +try: + import matplotlib.pyplot as plt +except ImportError: + plt = None + + +logging.basicConfig(level="INFO") +log = logging.getLogger("bathy") + +config = configparser.ConfigParser() +config.read("config.ini") + +root = pathlib.Path(config.get("data", "root")) + +bathy_hires = np.loadtxt(root.joinpath(config.get("data", "hires"))) +bathy_lores = np.loadtxt(root.joinpath(config.get("data", "bathy"))) +hstru = np.loadtxt(root.joinpath(config.get("data", "hstru"))) + +x_hires = np.arange(-0.5 * bathy_hires.size, 0, 0.5) +x_lores = np.arange(-1 * bathy_lores.size, 0, 1) +#x_hstru = np.arange(-1 * hstru.size, 0, 1) + +bathy_hires_pd = pd.Series(bathy_hires.copy(), index=x_hires) +bathy_lores_pd = pd.Series(bathy_lores.copy(), index=x_lores) + +bathy = bathy_lores_pd +inter = bathy_lores_pd.index.intersection(bathy_hires_pd.index) +bathy[inter] = bathy_hires_pd[inter] + +if config.getboolean("proc", "plot", fallback=False): + if plt is None: + log.error("Could not import PyPlot") + sys.exit(1) + + fig, ax = plt.subplots() + ax.plot(x_hires, bathy_hires, label="High-res") + ax.plot(x_lores, bathy_lores, label="Low-res") + #ax.plot(x_hstru, hstru, label="H stru") + ax.plot(bathy.index, bathy, ls="-.", c="k", label="Combined") + + ax.grid() + ax.legend() + plt.show(block=True)