def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent=parent) # load parameters to set dimension of frames and graphs configs = ConfigFunctions.load_config('./config.yaml') self.window_width = configs['window_width'] self.window_height = configs['window_height'] self.dirname = os.getcwd() self.folder1 = '' self.folder2 = '' self.sizer = wx.GridBagSizer(0, 0) self.header = wx.StaticText(self, -1, "Random Forest Classification", size=(500, 100)) font = wx.Font(20, wx.MODERN, wx.NORMAL, wx.NORMAL) self.header.SetFont(font) self.sizer.Add(self.header, pos=(0, 0), span=(2, 5), flag=wx.LEFT | wx.TOP, border=25) instructions = "Classify animals using extracted gait kinematic parameters and identify important parameters." self.instructions = wx.StaticText(self, -1, instructions, size=(self.window_width,50)) font = wx.Font(15, wx.MODERN, wx.NORMAL, wx.NORMAL) self.instructions.SetFont(font) self.sizer.Add(self.instructions, pos=(2, 0), span=(1, 6), flag=wx.LEFT, border=25) self.data_widgets = [] ################################# self.select_group1_button = wx.Button(self, id=wx.ID_ANY, label="Group 1") self.sizer.Add(self.select_group1_button, pos=(3, 0), flag=wx.LEFT | wx.TOP, border=25) self.data_widgets.append(self.select_group1_button) self.Bind(wx.EVT_BUTTON, lambda event, group_no = 0 : self.SelectGroupFolder(event, group_no), self.select_group1_button) self.select_group1_text = wx.StaticText(self, label="\nPlease select kinematic data folder of the first group.") self.sizer.Add(self.select_group1_text, pos=(3, 1), flag=wx.LEFT | wx.TOP, border=25) self.data_widgets.append(self.select_group1_text) ################################# self.select_group2_button = wx.Button(self, id=wx.ID_ANY, label="Group 2") self.sizer.Add(self.select_group2_button, pos=(4, 0), flag=wx.LEFT | wx.TOP, border=25) self.data_widgets.append(self.select_group2_button) self.Bind(wx.EVT_BUTTON, lambda event, group_no = 1 : self.SelectGroupFolder(event, group_no), self.select_group2_button) self.select_group2_text = wx.StaticText(self, label="\nPlease select kinematic data folder of the second group.") self.sizer.Add(self.select_group2_text, pos=(4, 1), flag=wx.LEFT | wx.TOP, border=25) self.data_widgets.append(self.select_group2_text) ################################# self.select_output_folder_button = wx.Button( self, id=wx.ID_ANY, label='Select output path') self.sizer.Add(self.select_output_folder_button, pos=( 7, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=25) self.data_widgets.append(self.select_output_folder_button) self.select_output_folder_button.Bind(wx.EVT_BUTTON, self.SelectOutputFolder) self.select_output_folder_button.Show() self.SetSizer(self.sizer) self.GetParent().Layout()
def ImportKinematicsCSV(self, e): import_dialog = wx.FileDialog( self, 'Choose a file', self.dirname, '', 'CSV files (*.csv)|*.csv|All files(*.*)|*.*', wx.FD_OPEN) if import_dialog.ShowModal() == wx.ID_OK: self.csv_dirname = import_dialog.GetDirectory() self.filename = os.path.join( self.csv_dirname, import_dialog.GetFilename()) self.df, self.filename = KinematicsFunctions.read_file( self.filename) self.df, self.bodyparts = KinematicsFunctions.fix_column_names( self.df) try: if self.df is not None: self.has_imported_file = True self.has_input_path = False self.import_csv_text.SetLabel( f"File imported! \n\n{self.filename}\n") self.GetParent().Layout() configs = ConfigFunctions.load_config('./config.yaml') self.cutoff_f = configs['lowpass_filter_cutoff'] if self.analysis_type == 'Treadmill': self.px_to_cm_speed_ratio = configs['px_to_cm_speed_ratio'] if configs['cm_speed'] == '': self.cm_speed = 1 else: self.cm_speed = configs['cm_speed'] elif self.analysis_type == 'Spontaneous walking': self.pixels_per_cm = configs['pixels_per_cm'] self.method_label.Show() self.method_choices.Show() self.method_note_text.Show() try: self.select_output_folder_button.Hide() self.select_output_folder_button.Destroy() self.bulk_extract_parameters_button.Hide() self.bulk_extract_parameters_button.Destroy() self.extract_parameters_text.Hide() self.extract_parameters_text.Destroy() except: pass self.GetParent().Layout() except AttributeError: # user cancelled file import in pop up self.GetParent().Layout() pass
def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent=parent) configs = ConfigFunctions.load_config('./config.yaml') self.window_width = configs['window_width'] self.window_height = configs['window_height'] self.frame_rate = configs['frame_rate'] self.cutoff_f = configs['lowpass_filter_cutoff'] self.px_to_cm_speed_ratio = configs['px_to_cm_speed_ratio'] self.analysis_type = "Treadmill" self.pixels_per_cm = configs['pixels_per_cm'] if configs['cm_speed'] == '': self.cm_speed = None else: self.cm_speed = configs['cm_speed'] self.dragging_filter = bool(configs['dragging_filter']) self.no_outlier_filter = bool(configs['no_outlier_filter']) self.stride_widgets = [] self.has_input_path = False self.has_imported_file = False self.dirname = os.getcwd() self.sizer = wx.GridBagSizer(0, 0) self.header = wx.StaticText( self, -1, "Kinematic Analysis", size=(500, 100)) font = wx.Font(20, wx.MODERN, wx.NORMAL, wx.NORMAL) self.header.SetFont(font) self.sizer.Add(self.header, pos=(0, 0), span=( 2, 4), flag=wx.LEFT | wx.TOP, border=25) self.instructions = wx.StaticText( self, -1, "Load the csv file of bodypart coordinates and extract kinematic parameters.", size=(self.window_width,50)) font = wx.Font(15,wx.MODERN,wx.NORMAL,wx.NORMAL) self.instructions.SetFont(font) self.sizer.Add(self.instructions, pos=( 2, 0), span=(1, 4), flag=wx.LEFT, border=25) self.Stride_UI()
def BulkImportKinematicsCSV(self, e): import_dialog = wx.DirDialog( self, 'Choose a folder', self.dirname, style=wx.DD_DEFAULT_STYLE) # Show the dialog and retrieve the user response. if import_dialog.ShowModal() == wx.ID_OK: self.input_path = import_dialog.GetPath() self.files = [] for file in os.listdir(self.input_path): if file.endswith('.csv'): self.files.append(file) try: if len(self.files) > 0: self.df = None self.has_input_path = True self.has_imported_file = False self.import_csv_text.SetLabel( f"Loaded {len(self.files)} csv files found in {self.input_path}.\n") self.GetParent().Layout() configs = ConfigFunctions.load_config('./config.yaml') self.cutoff_f = configs['lowpass_filter_cutoff'] if self.analysis_type == 'Treadmill': self.px_to_cm_speed_ratio = configs['px_to_cm_speed_ratio'] if configs['cm_speed'] == '': self.cm_speed = None else: self.cm_speed = configs['cm_speed'] elif self.analysis_type == 'Spontaneous walking': self.pixels_per_cm = configs['pixels_per_cm'] self.method_label.Show() self.method_choices.Show() self.method_note_text.Show() self.GetParent().Layout() try: self.select_output_path_button.Hide() self.select_output_path_button.Destroy() self.extract_parameters_text.Hide() self.extract_parameters_text.Destroy() self.extract_parameters_button.Hide() self.extract_parameters_button.Destroy() except: pass self.GetParent().Layout() return self.input_path, self.files, len(self.files) else: self.has_input_path = False except AttributeError: # user cancelled file import in pop up self.GetParent().Layout() pass else: self.input_path = '' import_dialog.Destroy()
def __init__(self, parent): """Constructor""" wx.Panel.__init__(self, parent=parent) self.sizer = wx.GridBagSizer(0, 0) ################################# configs = ConfigFunctions.load_config('./config.yaml') self.window_width = configs['window_width'] self.window_height = configs['window_height'] self.header = wx.StaticText(self, -1, "Automated Limb Motion Analysis (ALMA)", size=(self.window_width, 60)) font = wx.Font(30, wx.MODERN, wx.NORMAL, wx.NORMAL) self.header.SetFont(font) self.sizer.Add(self.header, pos=(1, 0), span=(1, 2), flag=wx.ALL, border=25) self.intro_text = wx.StaticText( self, label="Select behavioral test to analyze:\n") font = wx.Font(15, wx.MODERN, wx.NORMAL, wx.NORMAL) self.intro_text.SetFont(font) ladder_rung_img = wx.Bitmap('./Resources/image_ladder_rung.png') w, h = ladder_rung_img.GetWidth(), ladder_rung_img.GetHeight() ladder_rung_img = wx.Bitmap.ConvertToImage(ladder_rung_img) ladder_rung_img.Rescale(w // (3000 // self.window_width), h // (3000 // self.window_width)) ladder_rung_img = wx.Bitmap(ladder_rung_img) self.ladder_rung_button = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=ladder_rung_img) kinematics_img = wx.Bitmap('./Resources/image_kinematics.png') kinematics_img = wx.Bitmap.ConvertToImage(kinematics_img) kinematics_img.Rescale(w // (3000 // self.window_width), h // (3000 // self.window_width)) kinematics_img = wx.Bitmap(kinematics_img) self.kinematics_button = wx.BitmapButton(self, id=wx.ID_ANY, bitmap=kinematics_img) self.sizer.Add(self.intro_text, pos=(2, 0), flag=wx.ALL, border=25) self.sizer.Add(self.ladder_rung_button, pos=(3, 0), flag=wx.ALL, border=25) self.sizer.Add(self.kinematics_button, pos=(3, 1), flag=wx.ALL, border=25) # self.sizer.Add(control) self.ladder_rung_button.Bind(wx.EVT_BUTTON, parent.on_analyze_footfall) self.kinematics_button.Bind(wx.EVT_BUTTON, parent.on_analyze_stride) self.SetSizer(self.sizer) self.GetParent().Layout()
self.SetStatusText('Run PCA on extracted gait kinematic parameters') self.Layout() self.Refresh() # refresh to show slider in right proportion def on_about(self, e): wx.MessageBox( "This is a toolbox for fully automated (rodent) "\ "limb motion analysis with markerless bodypart tracking data. "\ "Compatible with csv output from DeepLabCut.", "About ALMA", wx.OK|wx.ICON_INFORMATION) def on_help(self, event): wx.MessageBox("Please go to our GitHub Wiki for help or email us :)", "Support", wx.OK|wx.ICON_INFORMATION) if __name__ == '__main__': from Functions import ConfigFunctions configs = ConfigFunctions.load_config('./config.yaml') window_width, window_height = configs['window_width'], configs['window_height'] app = wx.App(redirect = True) home_frame = HomeFrame(None, title='ALMA - Automated Limb Motion Analysis', size=(window_width, window_height)) home_frame.Show() app.MainLoop()