def classify(classifierList): ''' This function wraps other functions in order to load, classify, and return the label for each 5 second epoch of Q sensor data. INPUT: classifierList: list of strings, either "Binary" or "Multiclass" OUTPUT: featureLabels: Series, index is a list of timestamps for each 5 seconds, values of -1, 0, or 1 for artifact, questionable, or clean data: DataFrame, only output if fullFeatureOutput=1, index is a list of timestamps at 8Hz, columns include AccelZ, AccelY, AccelX, Temp, EDA, filtered_eda ''' # Constants oneHour = 8 * 60 * 60 # 8(samp/s)*60(s/min)*60(min/hour) = samp/hour fiveSec = 8 * 5 # Load data data, _ = getInputLoadFile() # Get pickle List and featureNames list featureNameList = [[]] * len(classifierList) for i in range(len(classifierList)): featureNames = getSVMFeatures(classifierList[i]) featureNameList[i] = featureNames # Get the number of data points, hours, and labels rows = len(data) num_labels = int(np.ceil(float(rows) / fiveSec)) hours = int(np.ceil(float(rows) / oneHour)) # Initialize labels array labels = -1 * np.ones((num_labels, len(classifierList))) for h in range(hours): # Get a data slice that is at most 1 hour long start = h * oneHour end = min((h + 1) * oneHour, rows) cur_data = data[start:end] features = createFeatureDF(cur_data) for i in range(len(classifierList)): # Get correct feature names for classifier classifierName = classifierList[i] featureNames = featureNameList[i] # Label each 5 second epoch temp_labels = classifyEpochs(features, featureNames, classifierName) labels[(h * 12 * 60):(h * 12 * 60 + temp_labels.shape[0]), i] = temp_labels return labels, data
if x_seconds: plt.xlabel('Time (s)') else: plt.xlabel('Time (min)') plt.show() def chooseValueOrDefault(str_input, default): if str_input == "": return default else: return float(str_input) if __name__ == "__main__": data, filepath_confirm = getInputLoadFile() fullOutputPath = getOutputPath() print("") print("Please choose settings for the peak detection algorithm. For default values press return") thresh_str = get_user_input('\tMinimum peak amplitude (default = .02):') thresh = chooseValueOrDefault(thresh_str,.02) offset_str = get_user_input('\tOffset (default = 1): ') offset = chooseValueOrDefault(offset_str,1) start_WT_str = get_user_input('\tMax rise time (s) (default = 4): ') start_WT = chooseValueOrDefault(start_WT_str,4) end_WT_str = get_user_input('\tMax decay time (s) (default = 4): ') end_WT = chooseValueOrDefault(end_WT_str,4) settings_dict = {'threshold':thresh,
plt.xlim([0,time_m[-1]]) plt.ylim([data_min-.1,data_max+.1]) plt.title('Motion with Detected "Steps" marked') plt.ylabel('g') if x_seconds: plt.xlabel('Time (s)') else: plt.xlabel('Time (min)') plt.show() if __name__ == "__main__": print "This script will extract features related to accelerometer data." data, filepath_confirm = getInputLoadFile() output_path = getOutputPath() time_frames = inputTimeFrames() features, steps, motion = computeAllAccelerometerFeatures(data, time_frames) data["steps"] = steps data["motion"] = motion saveFeaturesToFile(features, time_frames, output_path) print "" plot_ans = raw_input("Do you want to plot the detected steps? (y/n): ") if 'y' in plot_ans: