#!/usr/bin/env python3 """Statistics of the LBM wake probes (probes_y0.csv): mean and standard deviation of u, and the frequency of the largest spectral peak of u between FMIN and FMAX Hz (averaged periodogram, Hann window, half-overlapping segments of SEG s), with the Strouhal number f H / U (H: body height 1.418 m from the STL, U: inflow 16 m/s). probe_stats.py [probes_y0.csv] """ import sys, os import numpy as np f = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), "probes_y0.csv") H, U, SEG, FMIN, FMAX = 1.418, 16.0, 1.6, 0.5, 40.0 head = open(f).readline() pts = [p.strip() for p in head.split(":", 1)[1].split(";")] d = np.genfromtxt(f, delimiter=",", names=True, skip_header=1) t = d["t_s"] dt = t[1] - t[0] n = int(round(SEG/dt)) print("record %.3f s, dt %.2e s, segment %d samples (%.2f s), df %.2f Hz" % (t[-1] - t[0], dt, n, n*dt, 1/(n*dt))) for k, p in enumerate(pts): u = d["ux%d_ms" % k] w = np.hanning(n) segs = [u[i:i+n] for i in range(0, len(u) - n + 1, n//2)] psd = np.mean([np.abs(np.fft.rfft((s - s.mean())*w))**2 for s in segs], axis=0) fr = np.fft.rfftfreq(n, dt) m = (fr >= FMIN) & (fr <= FMAX) fp = fr[m][np.argmax(psd[m])] print("probe %d (%s): mean u %.2f m/s, std %.2f m/s, peak %.2f Hz, St %.3f (%d segments)" % (k + 1, p, u.mean(), u.std(), fp, fp*H/U, len(segs)))