def check_PSD(device="Sr20R21", alpha='0', phi='0', z='10', p=(-0.1, 0.1), component='vx', plot_name='test_psd.png', sampling=10000, NFFT=256): from time_series_functions import get_spectral_power_density #,\ #butter_lowpass_filter from matplotlib import pyplot as plt import seaborn as sns sns.__version__ time_series = load_time_series(device=device, alpha=alpha, phi=phi, z=z, p=p) #time_series.vx = butter_lowpass_filter(time_series.vx,cutoff=2000,fs=10000) #time_series.vy = butter_lowpass_filter(time_series.vy,cutoff=2000,fs=10000) #time_series.vz = butter_lowpass_filter(time_series.vz,cutoff=2000,fs=10000) Pxx, freqs = get_spectral_power_density(time_series.vx, NFFT=NFFT, sampling=sampling) Pyy, freqs = get_spectral_power_density(time_series.vy, NFFT=NFFT, sampling=sampling) #Pzz,freqs = get_spectral_power_density(time_series.vz, # NFFT=NFFT,sampling=sampling) if plot_name: fig = plt.figure() plt.plot(freqs, Pxx, label='$u$', alpha=0.6) plt.plot(freqs, Pyy, label='$v$', alpha=0.6) #plt.plot(freqs, Pzz, label='$z$', alpha=0.6) plt.ylabel("Power spectral density [p$^2/$Hz]") plt.xlabel("Frequency [Hz]") plt.yscale('log') plt.xscale('log') plt.xlim(xmin=50, xmax=5000) #plt.ylim(ymin=10e-4) plt.legend(loc='upper right') plt.savefig(plot_name) fig.clear() return [Pxx, Pyy, freqs]
def check_PSD( device="Sr20R21", alpha="0", phi="0", z="10", p=(-0.1, 0.1), component="vx", plot_name="test_psd.png", sampling=10000, NFFT=256, ): from time_series_functions import get_spectral_power_density # ,\ # butter_lowpass_filter from matplotlib import pyplot as plt import seaborn as sns sns.__version__ time_series = load_time_series(device=device, alpha=alpha, phi=phi, z=z, p=p) # time_series.vx = butter_lowpass_filter(time_series.vx,cutoff=2000,fs=10000) # time_series.vy = butter_lowpass_filter(time_series.vy,cutoff=2000,fs=10000) # time_series.vz = butter_lowpass_filter(time_series.vz,cutoff=2000,fs=10000) Pxx, freqs = get_spectral_power_density(time_series.vx, NFFT=NFFT, sampling=sampling) Pyy, freqs = get_spectral_power_density(time_series.vy, NFFT=NFFT, sampling=sampling) # Pzz,freqs = get_spectral_power_density(time_series.vz, # NFFT=NFFT,sampling=sampling) if plot_name: fig = plt.figure() plt.plot(freqs, Pxx, label="$u$", alpha=0.6) plt.plot(freqs, Pyy, label="$v$", alpha=0.6) # plt.plot(freqs, Pzz, label='$z$', alpha=0.6) plt.ylabel("Power spectral density [p$^2/$Hz]") plt.xlabel("Frequency [Hz]") plt.yscale("log") plt.xscale("log") plt.xlim(xmin=50, xmax=5000) # plt.ylim(ymin=10e-4) plt.legend(loc="upper right") plt.savefig(plot_name) fig.clear() return [Pxx, Pyy, freqs]
def compare_SPD(device="Sr20R21",alpha=0,phi=0,z=10): """ Gets the spectral power density for the 'popular' points in the root folder (defined in the function) """ from os import listdir from os.path import join import pandas as pd from numpy import argmin,linspace,log10 import time_series_functions as tdf from re import findall import matplotlib.pyplot as plt import seaborn as sns sns.__version__ all_data_points = sorted( [f for f in listdir(data_root) \ if f.endswith('.p')\ and "a{0}".format(alpha) in f\ and "p{0}".format(phi) in f\ and "z{0:02d}".format(z) in f\ and device in f ] ) px,py = art2fnc.popular_points() data_points = art2fnc.check_quick_point_existence( all_data_points, root, data_root ) fig,ax = plt.subplots(len(py),1,sharey=True,figsize=(5,10)) for data in data_points: df = pd.read_pickle(join(data_root,data)) spd_x,freq = tdf.get_spectral_power_density(df.vx) spd_y,freq = tdf.get_spectral_power_density(df.vy) x = float(findall('px[0-9]+.[0-9]+',data)[0].replace('px','')) y = float(findall('py[0-9]+.[0-9]+',data)[0].replace('py','')) y_ix = len(py)-1-argmin(map(abs,py-[y]*len(py))) St = freq*delta/Uinf slope_x = linspace(0.2,1,100) slope_y = 10*log10(slope_x**(-5/3.))-40 spd = 10*log10(spd_x+spd_y) if x == px[0]: ax[y_ix].plot(slope_x,slope_y,color='k',lw=1) ax[y_ix].text(0.6,-35,"$\\mathrm{St}^{-5/3}$") ax[y_ix].text(-0.25,0.5, "$y/\\delta = {0:.2f}$".format(y*4/1.5), transform=ax[y_ix].transAxes, ha='center', va='center', rotation=90 ) ax[y_ix].plot(St,spd,label="$x/2h=${0}".format(x)) ax[y_ix].set_xscale('log') ax[y_ix].set_xlim( 5e-2 , 2 ) ax[y_ix].set_ylim( -55,-20 ) if not y_ix == len(ax)-1: plt.setp( ax[y_ix].get_xticklabels(), visible=False ) else: ax[y_ix].set_xlabel('$\\mathrm{St} = f\\delta/U_\\infty$') ax[y_ix].set_ylabel( '$10\\,\\mathrm{log}_{10}(\\Phi_x+\\Phi_y)$ \n[dB]' ) ax[0].legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) fig.tight_layout() fig.savefig( "images/SPD_{0}_a{1}_p{2}_z{3}.png".format( device,alpha,phi,z), bbox_inches='tight' ) fig.clear()