import matplotlib.pyplot as plt import numpy as np datafile = 'src/data/shield1/082altdata.txt' filters = [0,5,10,15] ymin = -100 #0-22.5 ymax = 100 #22.5 def readData(): for line in open(datafile, 'r'): lines = [i for i in line.split()] tmp = float(lines[1]) #- 9.3090 x.append(float(lines[0])) if tmp < ymin : y.append(ymin) elif ymax < tmp: y.append(ymax) else : y.append(tmp) yfilter.append(tmp) def countEl(): sum = 0 cnt = 0 for i in y: cnt = cnt+1 sum = sum + i return sum,cnt x = [] y = [] yfilter = [] readData() cnt,sum = countEl() def filter(lgt): indx = lgt while indx < 3071: loc = 0 sum=0 while loc < lgt: sum = sum + y[indx-loc] loc = loc+1 yfilter[indx] = sum/lgt indx = indx+1 def meann (data,start,stop): sum=0 nr = stop-start i = 0 while i < nr: sum = sum+data[i+start] i = i+1 return sum/nr n=0 for i in y : n = n+1 sum = sum + i*0.04 #9.3099 #y =[a-mean for a in y] #y = y[541:620] #x = x[541:620] #print(y) def printHeader(): print("\nLift travel distance C2 - C-1\n") print("dataset ",datafile) print("no of elements ",n) print("time(sec) ",n*0.04) print("100 samples =", 100*0.04,"sec\n") print("filter length if 1 == no averaging - just raw\n") fsize = 5 # filter printHeader() def doIt(pl,flt,pkta1,pkta2,pktb1,pktb2,pktc1,pktc2,txt): print(txt," pin(s):",flt) filter(flt) pl.plot(x,yfilter) l1 = meann(yfilter,pkta1,pkta2) h1 = meann(yfilter,pktb1,pktb2) h2 = meann(yfilter,pktc1,pktc2) print("h1 ",l1) print("l1 ",h1 ) print("h2 ",h2 ) print("height ",l1-h1,"\n") return l1-h1 def runit(): fig,(ax1,ax2,ax3,ax4)=plt.subplots(4) #plt.title("altiude [m] from press sensor") h1=doIt(ax1,1,0,500,1000,2000,2300,3000,"f1") h2=doIt(ax2,5,0,500,1000,2000,2300,3000,"f5") h3=doIt(ax3,10,0,500,1000,2000,2300,3000,"f10") h4=doIt(ax4,100,0,500,1000,2000,2300,3000,"f100") plt.show() def main(): runit() if __name__ == "__main__": main()