示例#1
0
def readODMData(dataFilePath,progressReporter=_StdOutProgressReporter()):
    """
    Reads a data.csv file that has been written by a LabVIEW ODM Measurement and returns
    it as a dataframe. It also determines the cyclenumber and direction.
    
    The data is read from the source file in chunks of 2005 lines. This ensures that also extremely large
    files can be read without memory problems.
    
    Parameters
    ----------

    dataFilePath : string
        Path string to the data.csv file that contains the raw odm data or a stream object.
    progressReporter : ODMAnalysisGui.ProgressReporter
        The ProgressReporter to use. If None (default) a StdOutProgressReporter is used.

    
    Returns
    -------
    dataframe: pandas.DataFrame,
        A pandas dataframe with the data in data.csv. The index is set to the timestamp. The columns 
        'cycleNumber' and 'direction' have been determined from the 'actuatorVoltage' column.
    """
    
    progressReporter.message('loading data from %s ...' % dataFilePath)
    reader = getODMDataReader(dataFilePath)
        
    
    chunks=[]
    for chunk in reader:
        chunks.append(chunk)
        print "%s - %s" % (chunk.index.min(),chunk.index.max())
    
    df = _pd.concat(chunks)
    
    df = df[df.intensityProfile.map(len) != 0]
    
    getActuationDirectionAndCycle(df)

    progressReporter.done()
    
    return df
示例#2
0
def calculatePeakDisplacements(intensityProfiles, peakFitSettings, progressReporter = None, pInitial = None, **curveFitKwargs):
    """
    Fits an ODM FitFunction to the target Series of intensity profiles.
    
    Parameters
    ----------
    
    intensityProfiles : pandas.Series of 1D numpy.ndarray
        A series of intensityProfiles that will be curve fit
    peakFitSettings : ODAFitSettings instance
        The curve fit settings to use for curve fitting
    progressReporter : ProgressReporter instance
        The ProgressReporter to use for displaying progress information. 
        A StdOutProgressReporter is used by default.
    curveFitKwargs : Keyword arguments that will be passed to the curve_fit
        function (scipy.optimization).
    
    
    Returns
    -------

    A dataframe with the calculated displacements that has the same index as the input
    intensity profile Series.
    """
    
    if not progressReporter:
        progressReporter = _StdOutProgressReporter()
    
    fitFunction = peakFitSettings.fitFunction
    index=intensityProfiles.index
    
    if pInitial is not None:        
        p0 = pInitial
    else:
        templateProfile = peakFitSettings.referenceIntensityProfile if peakFitSettings.referenceIntensityProfile is not None else intensityProfiles.iloc[0]
        estimatesDict = fitFunction.estimateInitialParameters(templateProfile, **peakFitSettings.estimatorValuesDict)
        p0 = estimatesDict.values()
        
    xmin = peakFitSettings.xminBound
    xmax = peakFitSettings.xmaxBound
    xdata = _np.arange(len(intensityProfiles.iloc[0]))[xmin:xmax]
    
    progress = 0.0
    total = len(index)
    curveFitResults = total*[None]
    for i in range(total):
         ydata = intensityProfiles.iloc[i][xmin:xmax]
         popt,pcov = _curve_fit(fitFunction,\
                  xdata = xdata,\
                  ydata = ydata,\
                  p0 = p0,**curveFitKwargs)
         p0 = popt
         
         curveFitResult = {}       

         curveFitResult['popt'] = popt
         curveFitResult['pcov'] = pcov         
         curveFitResult['chiSquare'] = _chisquare(ydata,fitFunction(xdata,*popt))[0]
         curveFitResult['curveFitResult'] = attrdict.AttrDict(curveFitResult)
         curveFitResult['displacement'] = fitFunction.getDisplacement(*popt)
         
         curveFitResults[i] = curveFitResult
         
         progress += 1
         progressReporter.progress(progress / total * 100)
    
    df = _pd.DataFrame(index=index,data=curveFitResults)
    
    progressReporter.done()
    
    return df