import argparse import configparser import logging import pathlib import matplotlib.pyplot as plt import numpy as np parser = argparse.ArgumentParser(description="Pre-process time-series") 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("bathy") log.info("Starting time-series pre-processing") config = configparser.ConfigParser() config.read(args.config) inp_root = pathlib.Path(config.get("inp", "root")) out_root = pathlib.Path(config.get("out", "root")) inp_spec = inp_root.joinpath(config.get("inp", "raw_spec")) out_spec = out_root.joinpath("spec.dat") Sm = np.loadtxt( inp_spec, skiprows=3, max_rows=1, ) inp = np.loadtxt( inp_spec, dtype=[("f", float), ("S", float)], delimiter=",", skiprows=12, usecols=(0, 1), max_rows=64, ) with out_spec.open("w") as out: out.write("SPEC1D\n") np.savetxt(out, np.stack((inp["f"], inp["S"] * Sm), axis=1)) df = np.diff(inp['f']).min() log.info(f"Minimum frequency delta: {df:.4f}Hz") log.info(f"Maximum modelled time: {1/df:.0f}s") fig, ax = plt.subplots() ax.plot(inp["f"], inp["S"]*Sm, c="k", lw=1) ax.autoscale(True, "x", tight=True) ax.grid() ax.set(xlim=0, ylim=0, xlabel="f (Hz)", ylabel="S (m^2/Hz)") fig.savefig(out_root.joinpath("spec.pdf")) plt.show()