Exemplo n.º 1
0
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'
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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()