Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	simba/plotting/ez_path_plot.py
  • Loading branch information
sronilsson committed Apr 22, 2024
2 parents 6560f42 + c57d5dc commit d5644ea
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 60 deletions.
77 changes: 54 additions & 23 deletions simba/ui/pop_ups/make_path_plot_pop_up.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
from tkinter import *
import threading
from tkinter import *

from simba.mixins.pop_up_mixin import PopUpMixin
from simba.plotting.ez_path_plot import EzPathPlot
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu, Entry_Box, FileSelect)
from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, DropDownMenu,
Entry_Box, FileSelect)
from simba.utils.checks import (check_file_exist_and_readable,
check_if_valid_rgb_tuple, check_int, check_str)
from simba.utils.enums import Keys, Links, Options
from simba.utils.lookups import get_color_dict
from simba.utils.checks import check_file_exist_and_readable, check_int, check_if_valid_rgb_tuple, check_str


class MakePathPlotPopUp(PopUpMixin):
def __init__(self):
PopUpMixin.__init__(self, title="CREATE SIMPLE PATH PLOT", size=(500, 300))
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value,
settings_frm = CreateLabelFrameWithIcon(
parent=self.main_frm,
header="SETTINGS",
icon_name=Keys.DOCUMENTATION.value,
icon_link=Links.VIDEO_TOOLS.value,
)
self.video_path = FileSelect(
settings_frm,
"VIDEO PATH: ",
lblwidth="30",
file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)],
)
self.video_path = FileSelect(settings_frm, "VIDEO PATH: ", lblwidth="30", file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)])
self.body_part = Entry_Box(settings_frm, "BODY PART: ", "30")
self.data_path = FileSelect(
settings_frm, "DATA PATH (e.g., H5 or CSV file): ", lblwidth="30"
)
color_lst = list(get_color_dict().keys())
self.background_color = DropDownMenu(settings_frm, "BACKGROUND COLOR: ", color_lst, "30"
self.background_color = DropDownMenu(
settings_frm, "BACKGROUND COLOR: ", color_lst, "30"
)
self.background_color.setChoices(choice="White")
self.line_color = DropDownMenu(settings_frm, "LINE COLOR: ", color_lst, "30")
Expand All @@ -29,9 +41,13 @@ def __init__(self):
settings_frm, "LINE THICKNESS: ", list(range(1, 11)), "30"
)
self.line_thickness.setChoices(choice=1)
self.circle_size = DropDownMenu(settings_frm, "CIRCLE SIZE: ", list(range(1, 11)), "30")
self.last_frm_only_dropdown = DropDownMenu(settings_frm, "LAST FRAME ONLY: ", ['TRUE', 'FALSE'], "30")
self.last_frm_only_dropdown.setChoices('FALSE')
self.circle_size = DropDownMenu(
settings_frm, "CIRCLE SIZE: ", list(range(1, 11)), "30"
)
self.last_frm_only_dropdown = DropDownMenu(
settings_frm, "LAST FRAME ONLY: ", ["TRUE", "FALSE"], "30"
)
self.last_frm_only_dropdown.setChoices("FALSE")
self.circle_size.setChoices(choice=5)
settings_frm.grid(row=0, sticky=W)
self.video_path.grid(row=0, sticky=W)
Expand All @@ -42,7 +58,11 @@ def __init__(self):
self.line_thickness.grid(row=5, sticky=W)
self.circle_size.grid(row=6, sticky=W)
self.last_frm_only_dropdown.grid(row=7, sticky=W)
Label(settings_frm, fg='green', text=" NOTE: For more complex path plots, faster, \n see 'CREATE PATH PLOTS' under the [VISUALIZATIONS] tab after loading your SimBA project").grid(row=8, sticky=W)
Label(
settings_frm,
fg="green",
text=" NOTE: For more complex path plots, faster, \n see 'CREATE PATH PLOTS' under the [VISUALIZATIONS] tab after loading your SimBA project",
).grid(row=8, sticky=W)
self.create_run_frm(run_function=self.run)
self.main_frm.mainloop()

Expand All @@ -55,24 +75,35 @@ def run(self):
circle_size = self.circle_size.getChoices()
bp = self.body_part.entry_get
check_file_exist_and_readable(file_path=data_path)
check_int(name=f'{self.__class__.__name__} line_thickness', value=line_thickness, min_value=1)
check_int(name=f'{self.__class__.__name__} circle_size', value=circle_size, min_value=1)
check_int(
name=f"{self.__class__.__name__} line_thickness",
value=line_thickness,
min_value=1,
)
check_int(
name=f"{self.__class__.__name__} circle_size",
value=circle_size,
min_value=1,
)
check_if_valid_rgb_tuple(data=background_color)
check_if_valid_rgb_tuple(data=line_color)
check_str(name=f'{self.__class__.__name__} body-part', value=bp)
check_str(name=f"{self.__class__.__name__} body-part", value=bp)
last_frm = self.last_frm_only_dropdown.getChoices()
if last_frm == 'TRUE':
if last_frm == "TRUE":
last_frm = True
else:
last_frm = False
plotter = EzPathPlot(data_path=data_path,
video_path=video_path,
body_part=bp,
bg_color=background_color,
line_color=line_color,
line_thickness=int(line_thickness),
circle_size=int(circle_size),
last_frm_only=last_frm)
plotter = EzPathPlot(
data_path=data_path,
video_path=video_path,
body_part=bp,
bg_color=background_color,
line_color=line_color,
line_thickness=int(line_thickness),
circle_size=int(circle_size),
last_frm_only=last_frm,
)
threading.Thread(target=plotter.run).start()

#MakePathPlotPopUp()

# MakePathPlotPopUp()
111 changes: 74 additions & 37 deletions simba/ui/pop_ups/quick_path_plot_pop_up.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import os
from typing import Union
from tkinter import *
import threading
from tkinter import *
from typing import Union

from simba.mixins.config_reader import ConfigReader
from simba.mixins.pop_up_mixin import PopUpMixin
from simba.plotting.ez_path_plot import EzPathPlot
from simba.utils.errors import NoFilesFoundError
from simba.utils.read_write import find_all_videos_in_directory, get_fn_ext, read_video_info
from simba.utils.checks import check_file_exist_and_readable, check_int, check_str, check_if_valid_rgb_tuple
from simba.ui.tkinter_functions import DropDownMenu
from simba.utils.checks import (check_file_exist_and_readable,
check_if_valid_rgb_tuple, check_int, check_str)
from simba.utils.errors import NoFilesFoundError
from simba.utils.lookups import get_color_dict
from simba.utils.read_write import (find_all_videos_in_directory, get_fn_ext,
read_video_info)


class QuickLineplotPopup(PopUpMixin, ConfigReader):
def __init__(self,
config_path: Union[str, os.PathLike]):

def __init__(self, config_path: Union[str, os.PathLike]):
"""
:example:
>>> _ = QuickLineplotPopup(config_path='/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')
Expand All @@ -26,24 +26,40 @@ def __init__(self,
PopUpMixin.__init__(self, title="SIMPLE LINE PLOT")
ConfigReader.__init__(self, config_path=config_path)
if len(self.outlier_corrected_paths) == 0:
raise NoFilesFoundError(msg=f'No data found in the {self.outlier_corrected_paths} directory. Place files in this directory to create quick path plots.')
self.video_filepaths = {get_fn_ext(filepath=i)[1]: i for i in self.outlier_corrected_paths}
raise NoFilesFoundError(
msg=f"No data found in the {self.outlier_corrected_paths} directory. Place files in this directory to create quick path plots."
)
self.video_filepaths = {
get_fn_ext(filepath=i)[1]: i for i in self.outlier_corrected_paths
}
settings_frm = LabelFrame(self.main_frm, text="SETTINGS")
color_lst = list(get_color_dict().keys())
self.video_dropdown = DropDownMenu(settings_frm, "VIDEO: ", list(self.video_filepaths.keys()), "18")
self.video_dropdown = DropDownMenu(
settings_frm, "VIDEO: ", list(self.video_filepaths.keys()), "18"
)
self.video_dropdown.setChoices(list(self.video_filepaths.keys())[0])
self.bp_dropdown = DropDownMenu(settings_frm, "BODY-PART: ", self.body_parts_lst, "18")
self.bp_dropdown = DropDownMenu(
settings_frm, "BODY-PART: ", self.body_parts_lst, "18"
)
self.bp_dropdown.setChoices(self.body_parts_lst[0])
self.background_color = DropDownMenu(settings_frm, "BACKGROUND COLOR: ", color_lst, "18")
self.background_color = DropDownMenu(
settings_frm, "BACKGROUND COLOR: ", color_lst, "18"
)
self.background_color.setChoices(choice="White")
self.line_color = DropDownMenu(settings_frm, "LINE COLOR: ", color_lst, "18")
self.line_color.setChoices(choice="Red")
self.line_thickness = DropDownMenu(settings_frm, "LINE THICKNESS: ", list(range(1, 11)), "18")
self.line_thickness = DropDownMenu(
settings_frm, "LINE THICKNESS: ", list(range(1, 11)), "18"
)
self.line_thickness.setChoices(choice=1)
self.circle_size = DropDownMenu(settings_frm, "CIRCLE SIZE: ", list(range(1, 11)), "18")
self.circle_size = DropDownMenu(
settings_frm, "CIRCLE SIZE: ", list(range(1, 11)), "18"
)
self.circle_size.setChoices(choice=5)
self.last_frm_only_dropdown = DropDownMenu(settings_frm, "LAST FRAME ONLY: ", ['TRUE', 'FALSE'], "18")
self.last_frm_only_dropdown.setChoices('FALSE')
self.last_frm_only_dropdown = DropDownMenu(
settings_frm, "LAST FRAME ONLY: ", ["TRUE", "FALSE"], "18"
)
self.last_frm_only_dropdown.setChoices("FALSE")
settings_frm.grid(row=0, sticky=W)
self.video_dropdown.grid(row=0, sticky=W)
self.bp_dropdown.grid(row=2, sticky=W)
Expand All @@ -52,21 +68,31 @@ def __init__(self,
self.line_thickness.grid(row=5, sticky=W)
self.circle_size.grid(row=6, sticky=W)
self.last_frm_only_dropdown.grid(row=7, sticky=W)
Label(settings_frm, fg='green', text=" NOTE: For more complex path plots, faster, \n see 'CREATE PATH PLOTS' under the [VISUALIZATIONS] tab").grid(row=8, sticky=W)
Label(
settings_frm,
fg="green",
text=" NOTE: For more complex path plots, faster, \n see 'CREATE PATH PLOTS' under the [VISUALIZATIONS] tab",
).grid(row=8, sticky=W)
self.create_run_frm(run_function=self.run)
self.main_frm.mainloop()

def run(self):
video_name = self.video_dropdown.getChoices()
data_path = self.video_filepaths[video_name]
meta_data, _, fps = read_video_info(vid_info_df=self.video_info_df, video_name=video_name)
size = (int(meta_data['Resolution_width']), int(meta_data['Resolution_height']))
meta_data, _, fps = read_video_info(
vid_info_df=self.video_info_df, video_name=video_name
)
size = (int(meta_data["Resolution_width"]), int(meta_data["Resolution_height"]))
last_frm = self.last_frm_only_dropdown.getChoices()
if last_frm == 'TRUE':
save_path = os.path.join(self.path_plot_dir, f'{video_name}_simple_path_plot.png')
if last_frm == "TRUE":
save_path = os.path.join(
self.path_plot_dir, f"{video_name}_simple_path_plot.png"
)
last_frm = True
else:
save_path = os.path.join(self.path_plot_dir, f'{video_name}_simple_path_plot.mp4')
save_path = os.path.join(
self.path_plot_dir, f"{video_name}_simple_path_plot.mp4"
)
last_frm = False
if not os.path.isdir(self.path_plot_dir):
os.makedirs(self.path_plot_dir)
Expand All @@ -75,22 +101,33 @@ def run(self):
line_thickness = self.line_thickness.getChoices()
circle_size = self.circle_size.getChoices()
bp = self.bp_dropdown.getChoices()
check_int(name=f'{self.__class__.__name__} line_thickness', value=line_thickness, min_value=1)
check_int(name=f'{self.__class__.__name__} circle_size', value=circle_size, min_value=1)
check_int(
name=f"{self.__class__.__name__} line_thickness",
value=line_thickness,
min_value=1,
)
check_int(
name=f"{self.__class__.__name__} circle_size",
value=circle_size,
min_value=1,
)
check_if_valid_rgb_tuple(data=background_color)
check_if_valid_rgb_tuple(data=line_color)
check_str(name=f'{self.__class__.__name__} body-part', value=bp)
plotter = EzPathPlot(data_path=data_path,
size=size,
fps=fps,
body_part=bp,
bg_color=background_color,
line_color=line_color,
line_thickness=int(line_thickness),
circle_size=int(circle_size),
last_frm_only=last_frm,
save_path=save_path)
check_str(name=f"{self.__class__.__name__} body-part", value=bp)
plotter = EzPathPlot(
data_path=data_path,
size=size,
fps=fps,
body_part=bp,
bg_color=background_color,
line_color=line_color,
line_thickness=int(line_thickness),
circle_size=int(circle_size),
last_frm_only=last_frm,
save_path=save_path,
)
threading.Thread(target=plotter.run).start()

#_ = QuickLineplotPopup(config_path='/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')

# _ = QuickLineplotPopup(config_path='/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')
# _ = QuickLineplotPopup(config_path='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini')

0 comments on commit d5644ea

Please sign in to comment.