diff --git a/wetb/wind/dir_mapping.py b/wetb/wind/dir_mapping.py index 4da160f48e346cfece5717bfdad19599ae81069d..b2e6afe15af48c0b2da42cf50095e8f56b2ae5f5 100644 --- a/wetb/wind/dir_mapping.py +++ b/wetb/wind/dir_mapping.py @@ -105,12 +105,16 @@ def xyz2uvw(x, y, z, left_handed=True): y *= -1 theta = deg(np.arctan2(np.mean(y), np.mean(x))) SV = cosd(theta) * y - sind(theta) * x - SUW = cosd(theta) * x + sind(theta) * y - #% rotation around y of tilt - tilt = deg(np.arctan2(np.mean(z), np.mean(SUW))) - SU = SUW * cosd(tilt) + z * sind(tilt); - SW = z * cosd(tilt) - SUW * sind(tilt); +# SUW = cosd(theta) * x + sind(theta) * y +# +# #% rotation around y of tilt +# tilt = deg(np.arctan2(np.mean(z), np.mean(SUW))) +# SU = SUW * cosd(tilt) + z * sind(tilt); +# SW = z * cosd(tilt) - SUW * sind(tilt); + + SU = cosd(theta) * x + sind(theta) * y + SW = z return np.array([SU, SV, SW]) @@ -212,3 +216,5 @@ def abvrel2xyz(alpha, beta, vrel): z[m] = sign_vsz[m] * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(beta[m])) ** 2 + 1 + (np.tan(alpha[m]) / np.tan(beta[m])) ** 2)) return np.array([x, y, z]).T + + diff --git a/wetb/wind/tests/test_mann_parameters.py b/wetb/wind/tests/test_mann_parameters.py index 8565607ffa2825129777102b7c943deaf2840d38..0b3f883620a53e583460e85d6d4e8777d7368ec2 100644 --- a/wetb/wind/tests/test_mann_parameters.py +++ b/wetb/wind/tests/test_mann_parameters.py @@ -8,7 +8,7 @@ from wetb import gtsdf from wetb.wind.dir_mapping import wsp_dir2uv from wetb.wind.turbulence.mann_parameters import fit_mann_model_spectra import numpy as np -from wetb.wind.turbulence.turbulence_spectra import spectra +from wetb.wind.turbulence.spectra import spectra import os tfp = os.path.join(os.path.dirname(__file__), "test_files/") + "/" diff --git a/wetb/wind/turbulence/mann_parameters.py b/wetb/wind/turbulence/mann_parameters.py index b0a94bc7c9dfa87895e986769c1f45013c030642..9a411fbb26ca4bd21fdfd623761cdb20e6fa6cd7 100644 --- a/wetb/wind/turbulence/mann_parameters.py +++ b/wetb/wind/turbulence/mann_parameters.py @@ -10,7 +10,7 @@ import os from scipy.interpolate import RectBivariateSpline import numpy as np -from wetb.wind.turbulence.turbulence_spectra import spectra, logbin_spectra, \ +from wetb.wind.turbulence.spectra import spectra, logbin_spectra, \ plot_spectrum @@ -151,8 +151,8 @@ def fit_mann_model_spectra(k1, uu, vv=None, ww=None, uw=None, log10_bin_size=.2, _plot_spectra(k1, uu, vv, ww, uw, plt=plt) plot_mann_spectra(*x, plt=plt) plt.title('ae:%.3f, L:%.1f, G:%.2f' % tuple(x)) - plt.xlabel = ('Wavenumber, k1 [m$^{-1}$]') - plt.xlabel = ('Spectral density, $k_1F(k1) [m^2/s^2]$') + plt.xlabel('Wavenumber $k_{1}$ [$m^{-1}$]') + plt.ylabel(r'Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$') plt.legend() plt.show() return x @@ -248,8 +248,8 @@ def fit_ae(sf, u, L, G, min_bin_count=None, plt=False): muu = get_mann_model_spectra(ae, L, G, k1)[0] plt.semilogx(k1, k1 * muu, 'g', label='ae:%.3f, L:%.1f, G:%.2f' % (ae, L, G)) plt.legend() - plt.xlabel = ('Wavenumber, k1 [m$^{-1}$]') - plt.xlabel = ('Spectral density, $k_1F(k1) [m^2/s^2]$') + plt.xlabel('Wavenumber $k_{1}$ [$m^{-1}$]') + plt.ylabel(r'Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$') plt.show() return ae @@ -267,6 +267,8 @@ def _plot_spectra(k1, uu, vv=None, ww=None, uw=None, mean_u=1, log10_bin_size=.2 def plot(xx, label, color, plt): plt.semilogx(bk1, bk1 * xx * 10 ** 0 / mean_u ** 2 , '.' + color, label=label) plot(buu, 'uu', 'r', plt) + plt.xlabel('Wavenumber $k_{1}$ [$m^{-1}$]') + plt.ylabel(r'Spectral density $k_{1} F(k_{1})/U^{2} [m^2/s^2]$') if (bvv) is not None: plot(bvv, 'vv', 'g', plt) if bww is not None: @@ -289,9 +291,10 @@ def plot_mann_spectra(ae, L, G, style='-', u_ref=1, plt=None, spectra=['uu', 'vv if __name__ == "__main__": from wetb import gtsdf from wetb.wind.dir_mapping import wsp_dir2uv - - """Example of fitting Mann parameters to a time series""" from wetb import wind + import matplotlib.pyplot as plt + + """Example of fitting Mann parameters to a time series""" ds = gtsdf.Dataset(os.path.dirname(wind.__file__)+"/tests/test_files/WspDataset.hdf5")#'unit_test/test_files/wspdataset.hdf5') f = 35 u, v = wsp_dir2uv(ds.Vhub_85m, ds.Dir_hub_) @@ -300,7 +303,6 @@ if __name__ == "__main__": u -= u_ref sf = f / u_ref - import matplotlib.pyplot as plt ae, L, G = fit_mann_model_spectra(*spectra(sf, u, v), plt = plt) print (ae, L, G) diff --git a/wetb/wind/turbulence/turbulence_spectra.py b/wetb/wind/turbulence/spectra.py similarity index 97% rename from wetb/wind/turbulence/turbulence_spectra.py rename to wetb/wind/turbulence/spectra.py index 5dc626e3303d9a31c7e88d97021ced7e639a7b39..40aa0ac3f0d3db47521098ebd2f0825adcae6051 100644 --- a/wetb/wind/turbulence/turbulence_spectra.py +++ b/wetb/wind/turbulence/spectra.py @@ -87,6 +87,10 @@ def spectra(spacial_frq, u, v=None, w=None, detrend=True): if np.mean(u) > 1: k /= np.mean(u) u = u - np.mean(u, 0) + if v is not None: + v = v - np.mean(v, 0) + if w is not None: + w = w - np.mean(w, 0) if detrend: u, v, w = detrend_wsp(u, v, w)