def separateData(rawFileName, indexFileName, prefix): rawFile = open(rawFileName,'r') '''raw stuff''' # read header, rip into dictionary rawHeaderDict = getHeader(rawFile) # grab data # convert according to rx.cantilever and sign conventions data = rx.readDataFileArray(rawFile) # need to get cantilever values, micron conversion, and polarity stuff cantileverDict = rx.getCantileverData(rawHeaderDict['cantilever']) data = convertData(data,cantileverDict) '''index stuff''' # open index file indexFile = open(indexFileName,'r') # use matrix open from roxanne # create dictionary from index entries indexDict = rx.readDataFileArray(indexFile) # converting string to float facilitates later formatting indexDict['pulloffAngle'] = map(float,indexDict['pulloffAngle']) #print dict to stdout #print indexDict # todo:check if file name exists (to deal with multiple trials) for i in range(len(indexDict['pulloffAngle'])): # construct file name fileOutName = prefix fileOutName += 'a%02d.data' % indexDict['pulloffAngle'][i] print fileOutName, print 'opening', fileOut = open(fileOutName,'w') print 'writing', outputDictAsText(rawHeaderDict, fileOut) outputDictAsTextByIndex(indexDict, i, fileOut) fileOut.write('<data>\n') # output header # output data list startIndex = int(indexDict['startIndex'][i]) endIndex = int(indexDict['endIndex'][i]) keys = data.keys() keys.sort() colWidth = max(map(len, keys)) + 1 for key in keys: fileOut.write(key.ljust(colWidth)) fileOut.write('\n') # get starting time startTime = data['time'][startIndex] for j in range(startIndex, endIndex + 1): for key in keys: if key == 'time': fileOut.write(str(data[key][j]-startTime).ljust(colWidth)) else: fileOut.write(str(data[key][j]).ljust(colWidth)) fileOut.write('\n') print 'finishing'
def main(): fileName = 'analyzed.data' fileIn = open(fileName,'r') columnDict = roxanne.readDataFileArray(fileIn) shearForce = columnDict['forceMaxShear'] normalForce = columnDict['forceMaxAdhesion'] shearForce = np.array(shearForce) normalForce = np.array(normalForce) # import matplotlib # params = {'font.family': 'serif', # 'font.serif' : 'Computer Modern Roman', # 'text.usetex': True} # matplotlib.rcParams.update(params) import matplotlib.pyplot import matplotlib.axis matplotlib.pyplot.plot(shearForce,normalForce, linestyle = 'None', marker = 'o', markerfacecolor = 'w', markeredgecolor = 'g') matplotlib.pyplot.xlabel('Shear Force (microNewtons)') matplotlib.pyplot.ylabel('Adhesion Force (microNewtons)') matplotlib.pyplot.title('sws10 - 529b02 - Limit Surface - 20090522') matplotlib.pyplot.grid(True) matplotlib.pyplot.axis([0, 10, -5, 0]) matplotlib.pyplot.savefig('mplLimitSurface.pdf',transparent=True) # matplotlib.pyplot.show() import os os.system('open mplLimitSurface.pdf')
def plotLimitSurface(fileName): fileIn = open(fileName,'r') columnDict = rx.readDataFileArray(fileIn) shearForce = map(float,columnDict['forceMaxShear']) normalForce = map(float,columnDict['forceMaxAdhesion']) preload = map(float,columnDict['forcePreload']) pulloffAngle = map(float,columnDict['pulloffAngle']) shearForce = np.array(shearForce) normalForce = np.array(normalForce) factor = 10 preload = np.array(preload) * factor pulloffAngle = np.array(pulloffAngle) import matplotlib.pyplot as plt plt.scatter(shearForce, normalForce, marker = 'o', c=pulloffAngle, s=preload, alpha=0.5) plt.xlabel('Shear Force (microNewtons)') plt.ylabel('Adhesion Force (microNewtons)') plt.title('SPS 06 Limit Surface') plt.grid(True) colorbar = plt.colorbar() colorbar.set_label('angle of pulloff (90 is vertical)') plt.savefig('coloredLimitSurface.pdf',transparent=True)
def getData(self,fileName): fileIn = open(fileName,'r') columnDict = rx.readDataFileArray(fileIn) shearForce = columnDict['forceMaxShear'] normalForce = columnDict['forceMaxAdhesion'] shearForce = array(shearForce,dtype=float) normalForce = array(normalForce,dtype=float) self.x = shearForce self.y = normalForce
def plotTime(fileIn): rx.readDataFileHeader(fileIn) data = rx.readDataFileArray(fileIn) timeStrings = data['time'] timeSeconds = [float(ts[0:2])*3600+float(ts[3:5])*60+float(ts[6:]) for ts in timeStrings] import numpy as np timeSeconds = np.array(timeSeconds) timeSeconds = timeSeconds - timeSeconds[0] #print timeSeconds plt.plot(timeSeconds,'o')
def plotLimitSurface(fileName): import os fileDirectory = os.path.split(fileName)[0] plotFileName = os.path.join(fileDirectory, 'limitSurfaceTest.pdf') fileIn = open(fileName,'r') columnDict = roxanne.readDataFileArray(fileIn) shearForce = columnDict['forceMaxShear'] normalForce = columnDict['forceMaxAdhesion'] shearForce = np.array(shearForce) normalForce = np.array(normalForce) # import matplotlib # params = {'font.family': 'serif', # 'font.serif' : 'Computer Modern Roman', # 'text.usetex': True} # matplotlib.rcParams.update(params) import matplotlib.pyplot import matplotlib.axis matplotlib.pyplot.plot(shearForce,normalForce, linestyle = 'None', marker = 'o', markerfacecolor = 'w', markeredgecolor = 'g') matplotlib.pyplot.xlabel('Shear Force (microNewtons)') matplotlib.pyplot.ylabel('Adhesion Force (microNewtons)') matplotlib.pyplot.title('Limit Surface') matplotlib.pyplot.grid(True) # matplotlib.pyplot.axis([0, 5, -3, 3]) matplotlib.pyplot.savefig(plotFileName,transparent=True) # matplotlib.pyplot.show() import os os.system('open '+plotFileName)
keepReading = 1 while keepReading == 1: tempLine = fileIn.readline() tempLine = tempLine.strip() header.append(tempLine) if tempLine.find('<data>') != -1: keepReading = 0 return header fileIn = open('ls_sws10_20090522_162401.data') fileIndex = open('indexFile.index') header = getHeader(fileIn) #print header # read in dictionary data = rx.readDataFileArray(fileIn) convertTime(data) # zip into list of tuples data = zip(data['time'], data['voltageForceLateral'], data['voltageForceNormal'], data['voltagePositionX'], data['voltagePositionY']) index = rx.readDataFileArray(fileIndex) index['angle'] = [str(round(float(a),0)) for a in index['angle']] index = zip(map(int,(index['startIndex'])), map(int,(index['endIndex'])), index['angle'])
def main(): import sys sys.path.append('../roxanne') sys.path.append('../../roxanne') import roxanne import glob import os.path import numpy parseFileIn = open('testOut.dat','r') parseDict = roxanne.readDataFileArray(parseFileIn) print parseDict.keys() fOut = open('analyzed.data','w') fileNameList = glob.glob('a*.0.data') outputList = ['fileName', 'anglePitch', 'forceMaxAdhesion', 'forceMaxShear'] # removed angle pulloff from output list sep = '\t' headerString = sep.join(outputList) fOut.write(headerString) fOut.write('\n') for fileName in fileNameList: print 'processing file : ' + fileName # TODO - pulloff angle from trajectory file name fileIn = open(fileName) headerDict = roxanne.readDataFileHeader(fileIn) dataDict = roxanne.readDataFileArray(fileIn) voltageLateral = map(float,dataDict['voltageForceLateral']) voltageNormal = map(float,dataDict['voltageForceNormal']) positionNormalMicron = map(float,dataDict['voltagePositionX']) * 10 positionLateralMicron = map(float,dataDict['voltagePositionY']) * 10 voltageLateral = -numpy.array(voltageLateral) voltageNormal = numpy.array(voltageNormal) positionNormalMicron = numpy.array(positionNormalMicron) * 10 positionLateralMicron = numpy.array(positionLateralMicron) * 10 cantileverDict = roxanne.getCantileverData(headerDict['cantilever']) normalStiffness = cantileverDict['normalStiffness'] lateralStiffness = cantileverDict['lateralStiffness'] normalDisplacement = cantileverDict['normalDisplacement'] lateralDisplacement = cantileverDict['lateralDisplacement'] lateralAmplification = float(headerDict['latAmp']) normalAmplification = float(headerDict['norAmp']) rollAngle = float(headerDict['rollAngle']) pitchAngle = float(headerDict['pitchAngle']) # anglePulloff = float(headerDict['anglePulloff']) defaultAmplification = 100 lateralDisplacement = (lateralDisplacement * lateralAmplification / defaultAmplification) normalDisplacement = (normalDisplacement * normalAmplification / defaultAmplification) # use cantilever values to convert voltages to forces lateralForceMuN = (voltageLateral * lateralStiffness / lateralDisplacement) normalForceMuN = (voltageNormal * normalStiffness / normalDisplacement) # get location of filename in parseDict # and pull data from same index in the other arrays #fileName = os.path.splitext(fileName) #fileName = fileName[0] fileNames = parseDict['dataFileName'] indexFileName = fileNames.index(fileName) indexContact = parseDict['indexContact'][indexFileName] indexPreload = parseDict['indexMaxPreload'][indexFileName] indexMaxAdhesion = parseDict['indexMaxAdhesion'][indexFileName] indexContact = int(indexContact) indexPreload = int(indexPreload) indexMaxAdhesion = int(indexMaxAdhesion) # get forces at contact, preload, pulloff normalForceContactMuN = normalForceMuN[indexContact] normalForcePreloadMuN = normalForceMuN[indexPreload] normalForcePulloffMuN = normalForceMuN[indexMaxAdhesion] shearForceContactMuN = lateralForceMuN[indexContact] shearForcePreloadMuN = lateralForceMuN[indexPreload] shearForcePulloffMuN = lateralForceMuN[indexMaxAdhesion] normalCantileverVoltageContact = voltageNormal[indexContact] normalCantileverVoltagePreload = voltageNormal[indexPreload] normalCantileverVoltageMaxAdhesion = voltageNormal[indexMaxAdhesion] normalStagePositionContact = positionNormalMicron[indexContact] normalStagePositionPreload = positionNormalMicron[indexPreload] normalStagePositionMaxAdhesion = positionNormalMicron[indexMaxAdhesion] # calculate effective stage preload normalStagePreload = (normalStagePositionMaxAdhesion - normalStagePositionContact) # calculate effective cantilever deflection normalCantileverDeflection = ((normalCantileverVoltageContact - normalCantileverVoltageMaxAdhesion)/ normalDisplacement) # calculate effective microwedge deflection (effective preload) effectivePreload = normalCantileverDeflection + normalStagePreload # adhesion force = maxAdhesion - force at contact maxAdhesionMuN = (normalForcePulloffMuN - normalForceContactMuN) # shear force = maxShear - force at contact maxShearMuN = (shearForcePulloffMuN - shearForceContactMuN) # calculate effective stiffness of structure # force at preload - force at contact = force of preload forcePreload = normalForcePreloadMuN - normalForceContactMuN stageMovement = normalStagePositionPreload - normalStagePositionContact normalCantileverDeflection = ((normalCantileverVoltageContact - normalCantileverVoltagePreload)/ normalDisplacement) # stage movement between contact and preload - cantilever deflection effectiveStiffness = forcePreload/(stageMovement-normalCantileverDeflection) # print indexContact # input() fOut.write(fileName + '\t') fOut.write('% 5.1f\t' % pitchAngle ) # fOut.write('% 5.3f\t' % effectivePreload) fOut.write('% 5.3f\t' % maxAdhesionMuN) fOut.write('% 5.3f\t' % maxShearMuN) # fOut.write('% 5.3f\t' % normalStagePositionPreload) # fOut.write('% 5.3f\t' % normalStagePositionContact) # fOut.write('% 5.3f\t' % forcePreload) # fOut.write('% 5.3f\t' % stageMovement) # fOut.write('% 5.3f\t' % effectiveStiffness) fOut.write('\n') fOut.close()
def main(): #dataDirectory = '../031-20100111-sws16-ls/data/separated/' dataDirectory = '../033-20100302-sws17-ls/data/separated/' parsedFileName = dataDirectory + '033-analyzedAngle.data' parsedFileName = dataDirectory + '033-parsed.dat' parseFileIn = open(parsedFileName) parseDict = rx.readDataFileArray(parseFileIn) angle = convertToFloatArray(parseDict['angle']) fileNameList = parseDict['dataFileName'] for i,fileName in enumerate(fileNameList): fullFileName = dataDirectory + fileName print('processing file : ', fullFileName) fileIn = open(fullFileName) headerDict = rx.readDataFileHeader(fileIn) dataD = rx.readDataFileArray(fileIn) # convert lists to arrays of floats voltageLateral = convertToFloatArray(dataD['voltageForceLateral']) voltageNormal = convertToFloatArray(dataD['voltageForceNormal']) positionNormalMicron = convertToFloatArray(dataD['voltagePositionX']) positionLateralMicron = convertToFloatArray(dataD['voltagePositionY']) # make conversions voltageLateral = -voltageLateral voltageNormal = voltageNormal positionLateralMicron = positionLateralMicron * 10.0 positionNormalMicron = positionNormalMicron * 10.0 cantileverDict = rx.getCantileverData(headerDict['cantilever']) normalStiffness = cantileverDict['normalStiffness'] lateralStiffness = cantileverDict['lateralStiffness'] normalDisplacement = cantileverDict['normalDisplacement'] lateralDisplacement = cantileverDict['lateralDisplacement'] lateralAmplification = float(headerDict['latAmp']) normalAmplification = float(headerDict['norAmp']) defaultAmplification = 100 lateralDisplacement = (lateralDisplacement * lateralAmplification / defaultAmplification) normalDisplacement = (normalDisplacement * normalAmplification / defaultAmplification) # use cantilever values to convert voltages to forces lateralForceMuN = (voltageLateral * lateralStiffness / lateralDisplacement) normalForceMuN = (voltageNormal * normalStiffness / normalDisplacement) # get location of filename in parseDict # and pull data from same index in the other arrays #fileName = os.path.splitext(fileName) #fileName = fileName[0] #fileNames = parseDict['dataFileName'] #fileNameNoPath = os.path.split(fileName)[1] #indexFileName = fileNames.index(fileNameNoPath) # get indices for events in force trace indexContact = parseDict['indexContact'][i] indexPreload = parseDict['indexMaxPreload'][i] indexMaxAdhesion = parseDict['indexMaxAdhesion'][i] indexContact = int(indexContact) indexPreload = int(indexPreload) indexMaxAdhesion = int(indexMaxAdhesion) # get forces at contact, preload, pulloff normalForceContactMuN = normalForceMuN[indexContact] normalForcePreloadMuN = normalForceMuN[indexPreload] normalForcePulloffMuN = normalForceMuN[indexMaxAdhesion] shearForceContactMuN = lateralForceMuN[indexContact] shearForcePreloadMuN = lateralForceMuN[indexPreload] shearForcePulloffMuN = lateralForceMuN[indexMaxAdhesion] lateralForceMuN = lateralForceMuN[0:indexMaxAdhesion] normalForceMuN = normalForceMuN[0:indexMaxAdhesion] # subtract off forces at contact? # slice forces [0:indexMaxAdhesion] lateralForceMuN -= shearForceContactMuN normalForceMuN -= normalForceContactMuN x = angle[i]/90.0 myColor = (x,0,1-x) #print(myColor) plt.grid() plt.plot(lateralForceMuN, normalForceMuN, color = mpl.cm.get_cmap('jet')(x), label = str(i), linewidth = 0.1, alpha = 0.5) plt.title('force space') # plot forces on plot thang #plt.legend() #plt.colorbar() #plt.show() plt.savefig(dataDirectory+'forceSpace.pdf') return
#!/usr/bin/env python # plotting script that expects a header line with labels for # each column of data # these columns of data will be assigned to a dictionary # returned values are all strings import sys sys.path.append("/Users/dsoto/current/swDataFlat/code") import roxanne import numpy as np fileName = "analyzed.data" fileIn = open(fileName, "r") columnDict = roxanne.readDataFileArray(fileIn) shearForce = columnDict["forceMaxShear"] normalForce = columnDict["forceMaxAdhesion"] pitchAngle = columnDict["anglePitch"] shearForce = np.array(shearForce, dtype=float) normalForce = np.array(normalForce, dtype=float) dataDict = {} for i, a in enumerate(pitchAngle): forcePair = [shearForce[i], normalForce[i]] if a not in dataDict.keys(): dataDict[a] = [forcePair] else: dataDict[a].append(forcePair)
#!/usr/bin/env python import sys sys.path.append('/Users/dsoto/current/swDataFlat/code') import roxanne as rx parsedFileDirectory = '../035-sws17-length/data/' parsedFileName = parsedFileDirectory + 'parsed.dat' parsedFileObject = open(parsedFileName) parsedDict = rx.readDataFileArray(parsedFileObject) for i, fileName in enumerate(parsedDict['dataFileName']): indexContact = int(parsedDict['indexContact'][i]) indexMaxPreload = int(parsedDict['indexMaxPreload'][i]) indexFailure = int(parsedDict['indexMaxAdhesion'][i]) fileName = parsedFileDirectory + 'separated/' + fileName print fileName, indexContact rx.plotDataFileAnnotated(fileName, indexContact, indexMaxPreload, indexFailure)
#!/usr/bin/env python import sys sys.path.append('/Users/dsoto/current/swDataFlat/roxanne') import roxanne as rx import numpy as np fileNames = ['front','back'] for thisFileName in fileNames: fileName = thisFileName + '.data' fileIn = open(fileName, 'r') headDict = rx.readDataFileHeader(fileIn) dataDict = rx.readDataFileArray(fileIn) #print dataDict.keys() timeStrings = dataDict['time'] timeSeconds = [float(ts[0:2])*3600+float(ts[3:5])*60+float(ts[6:]) for ts in timeStrings] import numpy as np timeSeconds = np.array(timeSeconds) timeSeconds = timeSeconds - timeSeconds[0] dataDict['time'] = map(str,timeSeconds) dataDict['time'] = timeSeconds voltageLateral = map(float,dataDict['voltageForceLateral']) voltageNormal = map(float,dataDict['voltageForceNormal'])
import sys sys.path.append('/Users/dsoto/current/swDataFlat/code') import roxanne as rx dataFile = open('../data/separated/039-converted.data','r') rx.getHeader(dataFile) data = rx.readDataFileArray(dataFile) position = data['positionLateralMicron'] force = data['forceLateralMicroNewton'] position = map(float,position) force = map(float,force) import matplotlib.pyplot as plt plt.plot(position,force) plt.title('039 - SWS 12 Shear Bending') plt.xlabel('Position (microns)') plt.ylabel('Force (microNewtons)') plt.grid() plt.show() plt.savefig('039-shearBending.pdf')
def main(): import sys sys.path.append('../roxanne') import roxanne import glob import os.path import numpy parseFileIn = open('parsed.data','r') parseDict = roxanne.readDataFileArray(parseFileIn) print parseDict.keys() print parseDict fOut = open('analyzed.data','w') fileNameList = glob.glob('./data/*sws*.data') outputList = ['fileName', 'cantileverDeflection', 'stagePreload', 'maxPreload', 'microwedgeDeflection', 'lateralSpringConstant'] sep = '\t' headerString = sep.join(outputList) fOut.write(headerString) for fileName in fileNameList: print 'processing file : ' + fileName fileIn = open(fileName) headerDict = roxanne.readDataFileHeader(fileIn) dataDict = roxanne.readDataFileArray(fileIn) fullFileName = os.path.abspath(fileName) shortFileName = os.path.split(fullFileName)[1] #shortFileName = os.path.splitext(shortFileName)[0] voltageLateral = map(float,dataDict['voltageForceLateral']) voltageNormal = map(float,dataDict['voltageForceNormal']) positionNormalMicron = map(float,dataDict['voltagePositionX']) * 10 positionLateralMicron = map(float,dataDict['voltagePositionY']) * 10 voltageLateral = -numpy.array(voltageLateral) voltageNormal = numpy.array(voltageNormal) positionNormalMicron = numpy.array(positionNormalMicron) * 10 positionLateralMicron = numpy.array(positionLateralMicron) * 10 cantileverDict = roxanne.getCantileverData(headerDict['cantilever']) normalStiffness = cantileverDict['normalStiffness'] lateralStiffness = cantileverDict['lateralStiffness'] normalDisplacement = cantileverDict['normalDisplacement'] lateralDisplacement = cantileverDict['lateralDisplacement'] lateralAmplification = float(headerDict['latAmp']) normalAmplification = float(headerDict['norAmp']) rollAngle = float(headerDict['rollAngle']) pitchAngle = float(headerDict['pitchAngle']) defaultAmplification = 100 lateralDisplacement = (lateralDisplacement * lateralAmplification / defaultAmplification) normalDisplacement = (normalDisplacement * normalAmplification / defaultAmplification) # use cantilever values to convert voltages to forces lateralForceMuN = (voltageLateral * lateralStiffness / lateralDisplacement) normalForceMuN = (voltageNormal * normalStiffness / normalDisplacement) # get location of filename in parseDict # and pull data from same index in the other arrays fileName = os.path.splitext(fileName) fileName = fileName[0] fileNames = parseDict['dataFileName'] indexFileName = fileNames.index(shortFileName) indexContact = parseDict['indexContact'][indexFileName] indexPreload = parseDict['indexMaxPreload'][indexFileName] indexMaxAdhesion = parseDict['indexMaxAdhesion'][indexFileName] indexContact = int(indexContact) indexPreload = int(indexPreload) indexMaxAdhesion = int(indexMaxAdhesion) # get forces at contact, preload, pulloff normalForceContactMuN = normalForceMuN[indexContact] normalForcePreloadMuN = normalForceMuN[indexPreload] normalForcePulloffMuN = normalForceMuN[indexMaxAdhesion] shearForceContactMuN = lateralForceMuN[indexContact] shearForcePreloadMuN = lateralForceMuN[indexPreload] shearForcePulloffMuN = lateralForceMuN[indexMaxAdhesion] normalCantileverVoltageContact = voltageNormal[indexContact] normalCantileverVoltagePreload = voltageNormal[indexPreload] normalCantileverVoltageMaxAdhesion = voltageNormal[indexMaxAdhesion] shearCantileverVoltageContact = voltageLateral[indexContact] shearCantileverVoltagePreload = voltageLateral[indexPreload] shearCantileverVoltageMaxAdhesion = voltageLateral[indexMaxAdhesion] normalStagePositionContact = positionNormalMicron[indexContact] normalStagePositionPreload = positionNormalMicron[indexPreload] normalStagePositionMaxAdhesion = positionNormalMicron[indexMaxAdhesion] shearStagePositionContact = positionLateralMicron[indexContact] shearStagePositionPreload = positionLateralMicron[indexPreload] shearStagePositionMaxAdhesion = positionLateralMicron[indexMaxAdhesion] # calculate preload # in the shear bending test, this is from the shear trace stagePreload = shearStagePositionPreload - shearStagePositionContact # calculate deflection cantileverDeflection = ((shearCantileverVoltagePreload - shearCantileverVoltageContact) / lateralDisplacement) # calculate effective microwedge deflection (effective preload) microwedgeDeflection = stagePreload + cantileverDeflection # preload force maxPreload = (normalForcePreloadMuN - normalForceContactMuN) fOut.write(fileName + '\t') fOut.write('% 5.1f\t' % cantileverDeflection) fOut.write('% 5.3f\t' % stagePreload) fOut.write('% 5.3f\t' % maxPreload) fOut.write('% 5.3f\t' % microwedgeDeflection) fOut.write('% 5.3f\t' % lateralSpringConstant) fOut.write('\n') fOut.close()
def __init__(self, fileName, fOut): super(plotBox, self).__init__() self.isAccepted = True self.fOut = fOut self.message = 'Analysis Acceptable?' self.vPlot = VPlotContainer(padding = 10) self.vPlot.stack_order = 'top_to_bottom' topPlot = OverlayPlotContainer(padding = 10) self.vPlot.add(topPlot) bottomPlot = OverlayPlotContainer(padding = 10) self.vPlot.add(bottomPlot) # def parseFileName(): self.fileName = fileName # get complete path of data file fullFileName = os.path.abspath(fileName) self.fileName = os.path.split(fullFileName)[1] self.shortFileName = os.path.splitext(self.fileName)[1] self.plotTitle = self.shortFileName # def readData(): fileIn = open(fileName,'r') hD = rx.readDataFileHeader(fileIn) dD = rx.readDataFileArray(fileIn) self.normal = numpy.array(map(float,dD['voltageForceNormal'])) self.shear = numpy.array(map(float,dD['voltageForceLateral'])) self.index = numpy.arange(len(self.normal)) # index dictionary iD = rx.parseForceTrace(hD,dD) self.pointX[0] = iD['indexContact'] self.pointY[0] = self.normal[iD['indexContact']] self.pointX[1] = iD['indexMaxPreload'] self.pointY[1] = self.normal[iD['indexMaxPreload']] self.pointX[2] = iD['indexMaxAdhesion'] self.pointY[2] = self.normal[iD['indexMaxAdhesion']] # def constructPlots(): self.plotdata = ArrayPlotData(index = self.index, normal = self.normal, shear = self.shear, pointX = self.pointX, pointY = self.pointY) self.normalPlot = Plot(self.plotdata) self.normalPlot.plot(('index','normal'), type = 'line', color = 'blue') self.normalPlot.plot(('pointX','pointY'), type = 'scatter', marker = 'diamond', marker_size = 5, color = (0.0,0.0,1.0,0.5), outline_color = 'none') self.normalPlot.value_range.set_bounds(-1,1) self.shearPlot = Plot(self.plotdata) self.shearPlot.plot(('index','shear'),type='line',color='green') self.normalPlot.overlays.append(customTool(plotBox = self, component = self.normalPlot, axis = 'index_x', inspect_mode = 'indexed', write_metadata = True, color = 'black', is_listener = False)) self.normalPlot.tools.append(rx.SimpleZoom(self.normalPlot)) self.normalPlot.tools.append(PanTool(self.normalPlot,drag_button = 'right')) self.normalPlot.title = 'Normal Force Trace' self.shearPlot.title = 'Shear Force Trace' topPlot.add(self.shearPlot) bottomPlot.add(self.normalPlot) self.shearPlot.index_range = self.normalPlot.index_range
def __init__(self, fileName, fOut): super(plotBox, self).__init__() self.isAccepted = True self.fOut = fOut self.message = "Analysis Acceptable?" self.vPlot = VPlotContainer(padding=10) self.vPlot.stack_order = "top_to_bottom" topPlot = OverlayPlotContainer(padding=10) self.vPlot.add(topPlot) bottomPlot = OverlayPlotContainer(padding=10) self.vPlot.add(bottomPlot) # def parseFileName(): self.fileName = fileName # get complete path of data file fullFileName = os.path.abspath(fileName) self.fileName = os.path.split(fullFileName)[1] self.shortFileName = os.path.splitext(self.fileName)[1] self.plotTitle = self.shortFileName # def readData(): fileIn = open(fileName, "r") hD = rx.readDataFileHeader(fileIn) dD = rx.readDataFileArray(fileIn) self.normal = numpy.array(map(float, dD["voltageForceNormal"])) self.shear = numpy.array(map(float, dD["voltageForceLateral"])) self.index = numpy.arange(len(self.normal)) # index dictionary iD = rx.parseForceTrace(hD, dD) self.pointX[0] = iD["indexContact"] self.pointY[0] = self.normal[iD["indexContact"]] self.pointX[1] = iD["indexMaxPreload"] self.pointY[1] = self.normal[iD["indexMaxPreload"]] self.pointX[2] = iD["indexMaxAdhesion"] self.pointY[2] = self.normal[iD["indexMaxAdhesion"]] # def constructPlots(): self.plotdata = ArrayPlotData( index=self.index, normal=self.normal, shear=self.shear, pointX=self.pointX, pointY=self.pointY ) self.normalPlot = Plot(self.plotdata) self.normalPlot.plot(("index", "normal"), type="line", color="blue") self.normalPlot.plot( ("pointX", "pointY"), type="scatter", marker="diamond", marker_size=5, color=(0.0, 0.0, 1.0, 0.5), outline_color="none", ) # set range of plot self.normalPlot.value_range.set_bounds(-1.5, 1.5) self.shearPlot = Plot(self.plotdata) self.shearPlot.plot(("index", "shear"), type="line", color="green") self.normalPlot.overlays.append( customTool( plotBox=self, component=self.normalPlot, axis="index_x", inspect_mode="indexed", write_metadata=True, color="black", is_listener=False, ) ) self.normalPlot.tools.append(rx.SimpleZoom(self.normalPlot)) self.normalPlot.tools.append(PanTool(self.normalPlot, drag_button="right")) self.normalPlot.title = "Normal Force Trace" self.shearPlot.title = "Shear Force Trace" topPlot.add(self.shearPlot) bottomPlot.add(self.normalPlot) self.shearPlot.index_range = self.normalPlot.index_range
def main(): import sys sys.path.append('/Users/dsoto/current/swDataFlat/roxanne') import roxanne import glob import os.path import numpy parseFileIn = open('../037-sps06-ls/data/parsed.dat', 'r') parseDict = roxanne.readDataFileArray(parseFileIn) #print parseDict.keys() fOut = open('analyzed.data','w') fileNameList = glob.glob('../037-sps06-ls/data/separated/*.data') outputList = ['fileName', 'pulloffAngle', 'forceMaxAdhesion', 'forceMaxShear', 'forcePreload'] # removed angle pulloff from output list sep = '\t' headerString = sep.join(outputList) fOut.write(headerString) fOut.write('\n') for dataFileName in fileNameList: print 'processing file : ' + dataFileName # read in data file fileIn = open(dataFileName) headerDict = roxanne.getHeader(fileIn) dataDict = roxanne.readDataFileArray(fileIn) # this dataDict needs to be converted to floats for key in dataDict.keys(): dataDict[key] = map(float, dataDict[key]) # angle value should be in headerDict pulloffAngle = float(headerDict['pulloffAngle']) # get indices from the parsed.data file # get location of filename in parseDict # and pull data from same index in the other arrays parsedFileNames = parseDict['dataFileName'] dataFileNameNoPath = os.path.split(dataFileName)[1] #fileNameNoPath = fileNames indexFileName = parsedFileNames.index(dataFileNameNoPath) indexContact = parseDict['indexContact'][indexFileName] indexPreload = parseDict['indexMaxPreload'][indexFileName] indexMaxAdhesion = parseDict['indexMaxAdhesion'][indexFileName] indexContact = int(indexContact) indexPreload = int(indexPreload) indexMaxAdhesion = int(indexMaxAdhesion) # pull force values at those indices # data will be in dataDict normalForceContactMuN = dataDict['forceNormalMicroNewton'][indexContact] normalForcePreloadMuN = dataDict['forceNormalMicroNewton'][indexPreload] normalForcePulloffMuN = dataDict['forceNormalMicroNewton'][indexMaxAdhesion] shearForceContactMuN = dataDict['forceLateralMicroNewton'][indexContact] shearForcePreloadMuN = dataDict['forceLateralMicroNewton'][indexPreload] shearForcePulloffMuN = dataDict['forceLateralMicroNewton'][indexMaxAdhesion] # correct for force at contact # adhesion force = maxAdhesion - force at contact maxAdhesionMuN = (normalForcePulloffMuN - normalForceContactMuN) # shear force = maxShear - force at contact maxShearMuN = (shearForcePulloffMuN - shearForceContactMuN) # force at preload - force at contact = force of preload forcePreload = normalForcePreloadMuN - normalForceContactMuN fOut.write(dataFileNameNoPath + '\t') fOut.write('% 5.1f\t' % pulloffAngle ) fOut.write('% 5.3f\t' % maxAdhesionMuN) fOut.write('% 5.3f\t' % maxShearMuN) fOut.write('% 5.3f\t' % forcePreload) fOut.write('\n') fOut.close()