-
-
Save rcreighton/4aad62c4c27b33ea51dd64041666dcc0 to your computer and use it in GitHub Desktop.
BBBW Road Test Data Analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Spyder Editor | |
""" | |
import matplotlib.pyplot as plt | |
import csv | |
import numpy as np | |
from scipy import stats | |
def fftSmooth(data): | |
a = np.fft.rfft(data) | |
a[20:] = 0 | |
b = np.fft.irfft(a) | |
return b | |
def deriv(data): | |
der = [] | |
for i in range(len(data) -3): | |
der.append(float(data[i+3]) - float(data[i])) | |
return der | |
def diff(data1, data2): | |
dif = [] | |
for i in range(len(data1)): | |
dif.append(float(data1[i]) - float(data2[i])) | |
return dif | |
def reg(data): | |
x = [] | |
for i in range(len(data)): | |
x.append(i * 5) | |
ret = [] | |
for i in range(len(data) - 10): | |
slope, intercept, r_value, p_value, std_err = stats.linregress(x[i:i+10],data[i:i+10]) | |
ret.append(slope) | |
return ret | |
def crunch(path): | |
f = open(path) | |
reader = csv.reader(f) | |
inTemp = [] | |
outTemp = [] | |
inRelH = [] | |
outRelH = [] | |
inAbsH = [] | |
outAbsH = [] | |
for i in reader: | |
inTemp.append(float(i[2])) | |
outTemp.append(float(i[3])) | |
inRelH.append(float(i[4])) | |
outRelH.append(float(i[5])) | |
inAbsH.append(float(i[6])) | |
outAbsH.append(float(i[7])) | |
a = fftSmooth(inTemp) | |
b = fftSmooth(outTemp) | |
c = fftSmooth(inRelH) | |
d = fftSmooth(outRelH) | |
e = fftSmooth(inAbsH) | |
f = fftSmooth(outAbsH) | |
plt.plot(inTemp) | |
plt.plot(outTemp) | |
plt.show() | |
plt.plot(inRelH) | |
plt.plot(outRelH) | |
plt.show() | |
plt.plot(inAbsH) | |
plt.plot(outAbsH) | |
plt.show() | |
smoothIn = inTemp | |
smoothOut = outTemp | |
der = deriv(smoothIn) | |
dif = diff(smoothIn, smoothOut) | |
x = [] | |
y = [] | |
for i in range(len(der)): | |
if dif[i] > 0: | |
x.append(dif[i]) | |
y.append(der[i]) | |
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y) | |
x1 = [] | |
y1 = [] | |
for i in range(len(x)): | |
x1.append(x[i]) | |
y1.append(x[i] * slope + intercept) | |
''' | |
plt.plot(x, y) | |
#plt.plot(x1, y1) | |
#print(slope, r_value) | |
plt.show() | |
''' | |
#print(slope, r_value) | |
''' | |
plt.plot(a) | |
plt.plot(b) | |
#slopeT, interceptT, r_valueT, p_valueT, std_errT = stats.linregress(a, b) | |
plt.show() | |
plt.plot(c) | |
plt.plot(d) | |
#slopeRH, interceptRH, r_valueRH, p_valueRH, std_errRH = stats.linregress(c, d) | |
plt.show() | |
plt.plot(e) | |
plt.plot(f) | |
#slopeAH, interceptAH, r_valueAH, p_valueAH, std_errAH = stats.linregress(e, f) | |
plt.show() | |
#print(slopeT, slopeRH, slopeAH) | |
''' | |
efDiff = diff(e, f) | |
avDiff = np.average(efDiff) | |
print(avDiff) | |
print('Window closed') | |
print('Slope', 'R squared') | |
crunch('c:/Users/rcrei/Desktop/data_15.csv') | |
crunch('c:/Users/rcrei/Desktop/data_09.csv') | |
crunch('c:/Users/rcrei/Desktop/data_08.csv') | |
print() | |
print('Window open') | |
print('Slope', 'R squared') | |
crunch('c:/Users/rcrei/Desktop/data_20.csv') | |
crunch('c:/Users/rcrei/Desktop/data_19.csv') | |
crunch('c:/Users/rcrei/Desktop/data_17.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment