import os import numpy #Establish file path for directory containing OpenPIV output, count files in directory pivOutputPath = r'/run/user/1000/gvfs/sftp:host=isoptera.lcsc.edu,user=jamcdonald/home/jamcdonald/reu/OpenPIV_Out' fileCount = 0 fileList = os.listdir(pivOutputPath) for fileName in fileList: fileCount = fileCount + 1 #Create array to hold average velocity values videoAvgVelocity = [] #Begin loop to loop through file directory for i in range(0, fileCount - 1): #Find and open file filePath = pivOutputPath + "\\piv%4d.txt" % i file = open(filePath) #Read through file to obtain line count, then return to beginning lineCount = len(file.readlines()) print(str(lineCount) + " lines in file.") file.seek(0, 0) #Create array to hold all velocity values in the file velocityList = [] #Read the file data line by line for j in range(0, lineCount - 1): line = file.readline() lineInfo = line.split("\t") x = float(lineInfo[0]) y = float(lineInfo[1]) u = float(lineInfo[2]) v = float(lineInfo[3]) #Calculate speed for each line and append to array speed = ((u**2)+(v**2))**0.5 print("The speed at point (" + str(x) + ", " + str(y) + ") is " + str(speed) + " pixels per second.") velocityList.append(speed) print("Vector " + str(j + 1) + " of " + str(lineCount) + " appended.") listLength = len(velocityList) print(str(listLength) + " velocity vectors.") #Find the average velocity, standard deviation, and median avgVelocity = numpy.mean(velocityList) stdDev = numpy.std(velocityList) medVelocity = numpy.median(velocityList) print("Average velocity is " + str(avgVelocity) + " pixels per second.") #Add file average to overall average array videoAvgVelocity.append(avgVelocity) #Close file file.close() #Find the average overall velocity of the waves. listLength = len(videoAvgVelocity) total = sum(videoAvgVelocity) avgOverallVelocity = total / listLength print("Average velocity over " + str(listLength) + " frames is " + str(avgOverallVelocity) + " pixels per second.")