def _gather_hand_data(self, subjects, rotation=None): """ Returns a dictionary with the data for the hand, sorted by task. Each key,value pair of dictionary is: key: name of task, string. Ex: "a_n" value: list of AsteriskTrial objects for the corresponding task, with all subjects specified :param subjects: list of subjects to get """ data_dictionary = dict() if rotation is None: for t, r in datamanager.generate_t_r_pairs(self.hand.get_name()): key = f"{t}_{r}" data_dictionary[key] = self._make_asterisk_trials(subjects, t, r, datamanager.generate_options("numbers")) elif rotation in ["n", "m15", "p15"]: # TODO: also add a check for just cw and ccw for t in ["a", "b", "c", "d", "e", "f", "g", "h"]: key = f"{t}_{rotation}" data_dictionary[key] = self._make_asterisk_trials(subjects, t, rotation, datamanager.generate_options("numbers")) elif rotation in ["cw", "ccw"]: key = f"n_{rotation}" data_dictionary[key] = self._make_asterisk_trials(subjects, "n", rotation, datamanager.generate_options("numbers")) else: print("invalid key") data_dictionary = None return data_dictionary
def run_ast_study(): """ Handles running an asterisk study 1) imports all specified data 2) filters everything with a 15 sample moving average 3) averages all similar trials 4) produces a final averaged plot for each hand, as well as by subject 5) writes salient data tp external files (averaged asterisk data, final statistics, generated plots) """ home_directory = Path(__file__).parent.absolute() # right now, just compiles data and saves it all using the AsteriskHandData object subjects = datamanager.generate_options("subjects") hand_names = [ "basic" ] #, "2v2"] # ["basic", "m2stiff", "m2active", "2v2", "3v3", "2v3", "barrett", "modelvf"] # failed_files = [] # TODO: add ability to collect failed files for h in hand_names: print(f"Running: {h}, {subjects}") # input("Please press <ENTER> to continue") # added this for debugging by hand print("Analyzing aruco codes on viz data...") for s in subjects: batch_aruco_analysis(s, h, no_rotations=True, home=home_directory) print(f"Getting {h} data...") data = AsteriskHandData(subjects, h, rotation="n", blocklist_file="trial_blocklist.csv") # data = study.return_hand(h) print(f"Getting {h} data...") data.filter_data(10) # don't use if you're using an asterisk_study obj print("Generating CSVs of paths...") data.save_all_data() print("Calculating averages...") data.calc_averages(rotation="n") print("Saving plots...") data.plot_ast_avg(rotation="n", show_plot=False, save_plot=True) for a in data.averages: a.avg_debug_plot(show_plot=False, save_plot=True, use_filtered=True) print("Consolidating metrics together...") results = AstHandAnalyzer(data) print("Saving metric data...") results.save_data() print(f"{h} data generation is complete!")
def calc_averages(self, subjects=None, rotation=None): """ calculate and store all averages :param subjects: subject(s) to include in the average. Defaults to all subjects in object :param rotation: refers to the rotation type ("n", "m15", "p15"). Defaults to all options """ averages = [] if subjects is None: # if no subjects given, defaults to all subjects subjects = self.subjects_containing if rotation is None: # TODO: make this smarter, so that we base the list on what exists on object for t, r in datamanager.generate_t_r_pairs(self.hand.get_name()): avg = self._average_dir(t, r, subjects) averages.append(avg) else: for t in datamanager.generate_options("translations"): avg = self._average_dir(translation=t, rotation=rotation, subject=subjects) averages.append(avg) self.averages = averages return averages