def customizeFeatureLabel(strDataPath, 
                          lsFileNames,
                          lsDataAxisName,
                          dSamplingFreq,
                          dcLabel, 
                          nResponsePerData, 
                          nSegmentPerRespsonse, 
                          dVibrationDuration, 
                          dIntervalDuration,
                          dRestDuration, 
                          lsValidSegmentID,
                          dValidSegmentDuration,
                          lsAxis2Inspect = ['x0', 'y0', 'z0'] ):
    """
        Extract customized features and labels from give data set
        
        Parameters:
        ----
        strPath: 
                folder path of data
        lsFileNames: 
                    names of files to use
        dcLabel: 
            diction for mapping btw file name and label
        nResponsePerData: 
            number of responses in single data
        nSegmentPerRespsonse: 
            number of segments in single response
        dVibrationDuration: 
            duration of each vibration segment
        dIntervalDuration: 
            static duration btw segments
        dRestDuration: 
            static duration btw responses
        lsValidSegmentID: 
            list of segments to extract features
        dValidSegmentDuration: 
            duration of segment to extract features
        lsAxis2Inspect:
            axis to extract features, default is ['x0', 'y0', 'z0']
        
        Returns:
        ----
        dfFeatures: 
            a data frame of features
        lsLabels: 
            a list of corresponding labels
    """
    if (len(lsValidSegmentID) == 0 or 
        len(lsValidSegmentID) > nSegmentPerRespsonse or
        dValidSegmentDuration <= 0.0 or 
        dValidSegmentDuration > dVibrationDuration):
            raise ValueError()
        
    
    # load data
    lsData = md.loadDataEx(strDataPath, lsFileNames, lsDataAxisName)
    
    # extract features & labels
    lsDataFeatures = []
    lsLabels = []
    
    for strDataName, dfData in zip(lsFileNames, lsData):
        nLabel = dcLabel[strDataName[:2] ]
        
        lsAxisFeatures = []
        # extract features for each axis
        for strCol in lsAxis2Inspect:
            dcAxisFeatures = customizeAxisFeature(dfData,
                                                  strDataName,
                                                  strCol,
                                                  dSamplingFreq, 
                                                  nResponsePerData,
                                                  nSegmentPerRespsonse,
                                                  dVibrationDuration, 
                                                  dIntervalDuration,
                                                  dRestDuration,
                                                  lsValidSegmentID,
                                                  dValidSegmentDuration)
                                                
            if (len(dcAxisFeatures.keys() ) != nResponsePerData ):
                raise RuntimeError("the responses extracted "
                "does not equal to predefined")
                
            dfAxisFeatures = pd.DataFrame(dcAxisFeatures).T
            lsAxisFeatures.append(dfAxisFeatures)
                   
        # combine X, Y, Z horizontally
        dfDataFeatures = pd.concat(lsAxisFeatures, axis=1, 
                                   ignore_index=False)
        
        # save for furthur combination
        lsDataFeatures.append(dfDataFeatures)
        lsLabels.extend([nLabel]*dfDataFeatures.shape[0])

    # concatenate feature frames of all data together (vertically)
    dfFeatureLabel = pd.concat(lsDataFeatures, axis=0, ignore_index=False)
    dfFeatureLabel[LABEL] = pd.Series(lsLabels, index=dfFeatureLabel.index)
    
    return dfFeatureLabel
def extractFeatureLabel(strDataPath, 
                        lsFileNames, 
                        lsDataAxisName, 
                        dSamplingFreq, 
                        dcLabel, 
                        nResponsePerData, 
                        nSegmentPerRespsonse, 
                        dVibrationDuration, 
                        dIntervalDuration,
                        dRestDuration, 
                        lsAxis2Inspect = ['x0', 'y0', 'z0']):
    """
        Extract features and labels from give data set
        
        Parameters:
        ----
        strPath: 
            folder containing the data
        lsFileNames: 
            list of data file names
        dcLabel: 
            the diction of label mapping
        nResponsePerData: 
            number of responses in a data
        
        Returns:
        ----
        dfFeatureLabel: 
            a data frame of features & corresponding labels
    """
    # load data
    lsData = md.loadDataEx(strDataPath, lsFileNames, lsDataAxisName)
    
    # extract features & labels
    lsDataFeatures = []
    lsLabels = []
    for strDataName, dfData in zip(lsFileNames, lsData):
        nLabel = dcLabel[strDataName[:2] ]
        
        lsAxisFeatures = []
        # extract features for each axis
        for strCol in lsAxis2Inspect:
            dcAxisFeatures = extractAxisFeature(dfData, 
                                                strDataName,
                                                strCol,
                                                dSamplingFreq, 
                                                nResponsePerData,
                                                nSegmentPerRespsonse,
                                                dVibrationDuration, 
                                                dIntervalDuration,
                                                dRestDuration)
                                                
            if (len(dcAxisFeatures.keys() ) != nResponsePerData ):
                raise RuntimeError("the responses extracted does not "
                "equal to predefined")
                
            dfAxisFeatures = pd.DataFrame(dcAxisFeatures).T
            lsAxisFeatures.append(dfAxisFeatures)
                   
        # combine X, Y, Z horizontally, note the index is used!
        dfDataFeatures = pd.concat(lsAxisFeatures, axis=1, 
                                   ignore_index=False)
        
        # save for furthur combination
        lsDataFeatures.append(dfDataFeatures)
        lsLabels.extend([nLabel]*dfDataFeatures.shape[0])

    # concatenate feature frames of all data together (vertically)
    dfFeatureLabel = pd.concat(lsDataFeatures, axis=0, ignore_index=False)
    dfFeatureLabel[LABEL] = pd.Series(lsLabels, index=dfFeatureLabel.index)
    
    return dfFeatureLabel