from WAVlib import *
from Processing_Visualization import *
from ParasiticFunsctions import *
import pandas as pd
import numpy as np
from scipy import stats
from multiprocessing import Pool
import matplotlib.pyplot as plt
from prettytable import PrettyTable
from IPython.display import set_matplotlib_formats
import scipy
from scipy.linalg import *
set_matplotlib_formats('retina')
%matplotlib notebook
# Imports file in Pandas
def worker(input_file, import_type):
#     print('Starting import of {} ...'.format(input_file))
    with STARS_DataMatrix(input_file, import_type=import_type) as a:
        df = a.data
        header = a.header
#         print(df)
#     print(df.head(10))
    return df#, print('Import Complete')

def file_sort(path):
    if __name__ == '__main__':
        files = get_bin_files(path)
        files.sort()
        sorted_files= {}
        RPMS=[]
        for file in files:
    #         print()
            try:
                rpm = int(os.path.split(file)[-1].replace('Cycle','').replace('Jogging','0').replace('.bin',''))
                sorted_files[rpm] = file
            except ValueError:
                pass
    #     print('sorted files type = {}'.format(type(sorted_files)))
        rpms = sorted(sorted_files)
    #     print('sorted files type = {}'.format(type(rpms)))
        files = []
        for rpm in rpms:
            files.append(sorted_files[rpm])
    #     files = sorted_files[]
    #     pprint(files)
    #     raise ValueError
        for file_name in files:
            pass
    #         print(file)
    #     for file in files:
    # #         print(i)
    #         print(file_name)
            bin_file = worker(file_name, 'BIN')
            RPMS.append(bin_file)
        return RPMS
#-----------------------------------------------------------------------
from glob import glob
import os
import time
start_time = time.time()
files_WOD = glob('C:/Users/olahurikar/Desktop/Project/Parasitic Measurement/Data/Without Driver/Specimen*/Sequence*')
# files_WD = glob('C:/Users/olahurikar/Desktop/Project/Parasitic Measurement/Data/With Driver/Specimen*/Sequence*')
def Specimen_Data(files, Specimen_Name, Sequence_Name):
    # Define Dictionary to store Specimen data
    specimen = {}
    for i in range(len(files)):
        specimen[str(Specimen_Name)+str(i+1)+str(Sequence_Name)] = file_sort(files[i])
    return specimen
# Each Specimen will have 11 files from 0 to 1000 RPM
Specimen_1_8_WOD = Specimen_Data(files_WOD, 'Spec', 'Seq1')
# Specimen_1_8_WD = Specimen_Data(files_WD, 'Spec', 'Seq2')
print("--- %s seconds ---" % (time.time() - start_time))

--- 86.33514523506165 seconds ---

Data and signals

df_900_RPM = Specimen_1_8_WOD['Spec1Seq1'][10]
df_900_RPM.head(10)
Dyno1 speed Dyno 1 Torque Dyno1 drive speed Dyno1 drive torque wheel force transducer torque Dyno torque - wheel torque unfiltered Dyno Torque
0 -889.250488 17.737873 959.031860 3.226530 11.700266 6.445602 18.991743
1 -888.683105 17.733179 958.385864 3.225435 14.437738 4.935912 16.904972
2 -888.695129 17.722290 955.962769 3.196758 17.308708 -0.581515 15.438001
3 -888.836182 17.702110 956.430115 3.197883 13.736007 -0.528152 15.383463
4 -889.939209 17.674143 956.357971 3.198759 11.706779 3.584946 15.193300
5 -890.331726 17.638441 956.472656 3.200927 8.192916 6.063719 15.694941
6 -890.151489 17.598421 956.438538 3.211077 11.632340 7.703534 16.094942
7 -893.423645 17.559196 956.472290 3.210341 13.038136 4.879140 18.208824
8 -892.510498 17.529020 956.471436 3.210299 12.716043 7.049273 19.516090
9 -891.925049 17.508802 957.001587 3.209094 12.109437 7.013510 19.281155

Angular Acceleration Calculations

def t(sig):
    t = np.linspace(0.0, 60.0, len(sig))
    return t
def ang_anccel(speed_sig):
    # 't' is in sec
    t = np.linspace(0.0, 60.0, len(speed_sig))
    dt = t[10]-t[9]
    print('dt', dt)
    # ang_vel in rad/sec
    ang_vel = (2*np.pi*speed_sig)/60
    diff_ang_vel = np.diff(ang_vel)
    ang_accn = diff_ang_vel/dt
    ang_accn = np.insert(ang_accn,len(diff_ang_vel),0)
    return ang_accn
df_1000_RPM = Specimen_1_8_WOD['Spec1Seq1'][11]
df_1000_RPM.head(10)
Dyno1 speed Dyno 1 Torque Dyno1 drive speed Dyno1 drive torque wheel force transducer torque Dyno torque - wheel torque unfiltered Dyno Torque
0 -987.141113 16.547644 1033.319946 2.956463 15.031361 1.925579 14.234682
1 -988.326721 16.531986 1031.193481 2.956336 16.247116 -4.223027 12.857836
2 -988.034546 16.502298 1030.613159 2.955147 12.018406 -1.764284 12.855092
3 -989.629822 16.464529 1029.805786 2.951604 8.014373 2.950235 14.794076
4 -991.072754 16.430140 1029.626709 2.952333 5.653624 10.590709 17.453135
5 -989.187378 16.406775 1029.688843 2.945945 11.417253 9.072496 19.213480
6 -989.670898 16.399082 1029.952759 2.931959 12.660310 8.101507 20.072456
7 -987.871216 16.400858 1029.940552 2.932886 14.973162 4.151575 17.657413
8 -987.804260 16.402300 1029.483765 2.931149 13.423263 1.941768 15.228246
9 -988.102600 16.392580 1029.874512 2.930932 15.681192 -1.236095 13.061012

1000 RPM

y3 = df_1000_RPM["Dyno1 speed"]*-1
y4 = ang_anccel(y3)
y5 = df_900_RPM["Dyno1 drive torque"]
plot_2_channels_dif_x(t(y3),y3, "Speed at 1000_RPM",t(y4),y4, "Angular Acceleration rad/sec^2 at 1000_RPM")
plot_2_channels_dif_x(t(y5),y5, "GIF-Wheel Trq Nm at 900_RPM",t(y5), y5, "Dyno1 drive torque Nm at 1000_RPM")
dt 0.001001652727



<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

Torque signal at GIF and Wheel Sensor


IG_IW = 0.4259313
y1 = df_900_RPM["unfiltered Dyno Torque"]
y2 = df_900_RPM["wheel force transducer torque"]
y3 = df_900_RPM["Dyno1 speed"]*-1
y4 = ang_anccel(y3)
y5 = df_900_RPM["Dyno torque - wheel torque"]
y7 = y4*IG_IW # Trq Acceleration
print('Acceleration Trq Mean', np.mean(y7))
print('Acceleration Trq Median', np.median(y7))
y8 = (2*np.pi*y3)/60 # Angular Velocity
y9 = np.diff(y8)
y10 = df_900_RPM["Dyno1 drive speed"]
y11 = df_900_RPM["Dyno1 drive torque"]
y12 = y1-y2
y13 = np.median(y7)# Meidan of Angular Acceleration
y6 = y5 - abs(y13*IG_IW) # Actual Torque
dt 0.00100153568806
Acceleration Trq Mean 0.00317954690564
Acceleration Trq Median 0.358802728075
plt.close('all')
gaussian_Histo(y6, 'Title', ax = None)
<IPython.core.display.Javascript object>

Title
Mean 2.93166187406
Median 2.31731893371
-------------------------------------
print("Dyno Trq median", np.median(y1))
print("Wheel Trq median",np.median(y2))
print("------------------------------")
plt.close('all')
plot_2_channels_dif_x(t(y1),y1, "unfiltered Dyno Torque Nm at 900_RPM",t(y2), y2, "wheel force transducer torque Nm at 900_RPM")
plot_2_channels_dif_x(t(y12),y12, "GIF-Wheel Trq Nm at 900_RPM",t(y11), y11, "Dyno1 drive torque Nm at 900_RPM")
plot_2_channels_dif_x(t(y8),y8, "Angular Velocity rad/sec at 900_RPM",t(y4),y4, "Angular Acceleration rad/sec^2 at 900_RPM")
plot_2_channels_dif_x(t(y3), y3, "Dyno speed RPM at 900_RPM",t(y7),y7, "Median Accn Torque Nm at 900_RPM")
plot_2_channels_dif_x(t(y5),y5, "GIF Wheel Torque Nm at 900_RPM",t(y6), y6, "Actual Torque Loss Nm at 900_RPM")


f, (ax1, ax2) = plt.subplots(1, 2, sharey=False, figsize=(12,8), dpi=80)
plot_FFT(y1, "unfiltered Dyno Torque Nm at 900_RPM", ax1)
plot_FFT(y2, "Wheel Torque Nm at 900_RPM", ax2)
f, (ax1, ax2) = plt.subplots(1, 2, sharey=False, figsize=(12,8), dpi=80)
plot_FFT(y3, "Dyno1 speed at 900_RPM", ax1)
plot_FFT(y4, "Angular Acceleration at 900_RPM", ax2)
Dyno Trq median 10.7766332626
Wheel Trq median 8.15559101105
------------------------------



<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

df_200_RPM = Specimen_1_8_WOD['Spec1Seq1'][4]

y1 = df_200_RPM["unfiltered Dyno Torque"]
y2 = df_200_RPM["wheel force transducer torque"]
y12 = y1-y2
y3 = df_200_RPM["Dyno1 speed"]*-1
y4 = ang_anccel(y3)
y5 = df_200_RPM["Dyno torque - wheel torque"]
y6 = y5 - y4*IG_IW # Actual Torque
y7 = y4*IG_IW # Trq Acceleration
print('Acceleration Trq Mean', np.mean(y7))
print('Acceleration Trq Median', np.median(y7))
y8 = (2*np.pi*y3)/60 # Angular Velocity
y9 = np.diff(y8)
y10 = df_200_RPM["Dyno1 drive speed"]
y11 = df_200_RPM["Dyno1 drive torque"]
dt 0.00100013335111
Acceleration Trq Mean 0.00919880323448
Acceleration Trq Median 1.71078568142
plt.close('all')
plot_2_channels_dif_x(t(y1),y1, "unfiltered Dyno Torque Nm at 200_RPM",t(y2), y2, "wheel force transducer torque Nm at 200_RPM")
plot_2_channels_dif_x(t(y12),y12, "GIF-Wheel Trq Nm at 200_RPM",t(y11), y11, "Dyno1 drive torque Nm at 200_RPM")
plot_2_channels_dif_x(t(y8),y8, "Angular Velocity rad/sec at 200_RPM",t(y4),y4, "Angular Acceleration rad/sec^2 at 200_RPM")
plot_2_channels_dif_x(t(y3), y3, "Dyno speed RPM at 200_RPM",t(y7),y7, "Accn Torque Nm at 200_RPM")
plot_2_channels_dif_x(t(y5),y5, "GIF Wheel Torque Nm at 200_RPM",t(y6), y6, "Actual Torque Loss Nm at 200_RPM")
<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>

<IPython.core.display.Javascript object>