def exceedence(file, content, plot=False): #takes in the raw data file as input #content : string : the signal for which exceedence is needed #plot : string : Boolean. if true, plot is also displayed #outputs the exceedence curve : array #outputs the array for which the exceedence is calculated : array df, _ = access_file(file) mean = df.mean(axis=0) maxima = df.max(axis=0) / mean #needed to define the upper limit of array minima = df.min( axis=0) / mean #defines lower limit for which exceedence is calculated mean_array = np.linspace(minima[content], maxima[content], 100) exceedence = [] for i in range(len(mean_array)): d = df[content] / mean[content] < mean_array[ i] #checks which value is above or below the value in the array x = 1 - sum(d) / len( df ) #first fins total number of values in the df which exceed the stated value in the array. then finds the probability of the true values. then subtracts from 1 to find the exceedence exceedence.append(x) #push it into the array which is then returned if plot == True: #fig = plt.figure(figsize = (20,10)) plt.semilogy(mean_array, exceedence) plt.xlabel(r'X/$\bar{X}$') plt.ylabel('Exceedence Probability') plt.grid('both') plt.title(content) return mean_array, exceedence
#creaet a data frame with average of the thrust and RPM from the data files force_df = pd.DataFrame({'Original Name':dfs['Original'], 'Force Name':dfs['Force File Name'], \ 'RPM' : None, 'Thrust_mean' : None, 'Torque_mean' : None, \ 'Thrust sigma' : None, 'Torque sigma' : None, 'Cp mean' : None, \ 'Cp sigma' : None, 'Ct mean' : None, 'Ct sigma' : None, 'My1 Mean' : None, 'My1 sigma' : None}) #Cp curve #Eq: Cp = Torque x RPM / 0.5 x rho x A x u^3_mean rho = 1000 #water density in kg/m3 rotor_dia = 0.724 rotor_area = math.pi * rotor_dia**2 / 4 for file in force_files: #reading the entire data file can slow down the process #in future, this functionality can be adjusted #units are being returned as well which we will be dumping df, _ = access_file(path_data_files + file) rpm_mean = np.mean(df['RPM']) thrust_mean = np.mean(df['Force']) torque_mean = np.mean(df['Couple']) thrust_std = np.std(df['Force']) torque_std = np.std(df['Couple']) My1_mean = np.mean(df['My1']) My1_std = np.std(df['My1']) My2_mean = np.mean(df['My2']) My2_std = np.std(df['My2']) My3_mean = np.mean(df['My3']) My3_std = np.std(df['My3']) force_df.at[force_df[force_df['Force Name'] == file[:-4]].index[0], 'RPM'] = rpm_mean force_df.at[force_df[force_df['Force Name'] == file[:-4]].index[0], 'Thrust_mean'] = thrust_mean
#for binned and normalised. out_direc_bin_norm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Binned_normalised_azimuthal/' #binned and non-normalised out_direc_bin_nnorm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Binned_nonnormalised_azimuthal/' #spline and normalised out_direc_spl_norm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Spline_normalised_azimuthal/' #spline and non-normalised out_direc_spl_nnorm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Spline_nonnormalised_azimuthal/' for r,d in zip(runs,dist): df2, units = access_file(direc + r) for col in df2.columns[1:]: if not os.path.isdir(out_direc_bin_norm+col): os.makedirs(out_direc_bin_norm + col) new_dir = out_direc_bin_norm + col polar_chart_binning(df2, col, True) plt.title('Distance = {} mm, TSR = 4, Vel = 1.0 m/s'.format(d)) plt.savefig(new_dir +'/' + str(d) + '.png', dpi = 300) plt.close() for col in df2.columns[1:]: if not os.path.isdir(out_direc_bin_nnorm+col): os.makedirs(out_direc_bin_nnorm + col)
# -*- coding: utf-8 -*- """ Created on Tue Jul 6 19:23:47 2021 @author: goharshoukat This sript analyses the dry tests to identify the cause of the noise in the fft signal """ import numpy as np import pandas as pd from Dashboard.data_import_func import access_file, spectral_analysis, rotor_freq import matplotlib.pyplot as plt direc = 'Dry_tests/run005.txt' df, units = access_file(direc) column = ['Fx1', 'Thrust', 'Torque', 'My1'] for col in column: fig = plt.figure(figsize=(60, 60)) ax = fig.add_subplot(111) spec_s, f_s = spectral_analysis(df, col, bins='Default') rfreq = rotor_freq(df['#RPM']) freq_s = f_s / rfreq ax.loglog(freq_s, spec_s[1:], linewidth=0.8) ax.minorticks_on() ax.grid(which='minor', linestyle='--') ax.grid(which='major', linestyle='-') #plt.title('{}, TSR = 4.0, Dry Test'.format(col)) ax.set_xlabel(r'$\frac{F}{f_0}$ [Hz/Hz]') ax.set_ylabel('Magnitude ({})'.format(units[col])) plt.savefig('Results/fft/Dry_tests/' + col + '.pdf')
# %% #for binned and normalised. out_direc_bin_norm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Binned_normalised_azimuthal/' #binned and non-normalised out_direc_bin_nnorm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Binned_nonnormalised_azimuthal/' #spline and normalised out_direc_spl_norm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Spline_normalised_azimuthal/' #spline and non-normalised out_direc_spl_nnorm = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/Angular_Variation/Spline_nonnormalised_azimuthal/' for r, d in zip(runs, dist): df2, units = access_file(direc + r) for col in df2.columns[1:]: if not os.path.isdir(out_direc_bin_norm + col): os.makedirs(out_direc_bin_norm + col) new_dir = out_direc_bin_norm + col polar_chart_binning(df2, col, True) plt.title('Distance = {} mm, TSR = 4, Vel = 1.0 m/s'.format(d)) plt.savefig(new_dir + '/' + str(d) + '.png', dpi=300) plt.close() for col in df2.columns[1:]: if not os.path.isdir(out_direc_bin_nnorm + col): os.makedirs(out_direc_bin_nnorm + col)
# %% For loop out_direc = '/Users/goharshoukat/Documents/GitHub/Thesis_Tidal_Turbine/Results/fft/' column = ['Fx1', 'Force', 'Couple', 'My1'] list_files = np.array_split(runs, 5)[:3] list_dist = np.array_split(dist, 5)[:3] for col in column: fig, ax = plt.subplots(3, 1, figsize=(60, 60), sharex=True) for i in range(len(ax)): for r, d in zip(list_files[i], list_dist[i]): df, units = access_file(direc + r) spec_s, f_s = spectral_analysis(df, col, bins='Default') rfreq = rotor_freq(df['RPM']) freq_s = f_s / rfreq ax[i].loglog(freq_s, spec_s[1:], linewidth=0.8, label='{} mnm'.format(d)) ax[i].minorticks_on() ax[i].grid(which='minor', linestyle='--') ax[i].grid(which='major', linestyle='-') ax[i].legend() ax[i].set_ylabel('Magnitude ({})'.format(units[col])) ax[2].set_xlabel(r'$\frac{F}{f_0}$ [Hz/Hz]') plt.savefig(out_direc + col + '_1.pdf')