From a433384ccb0d14bd8f51dda9f01a099bb81c58d1 Mon Sep 17 00:00:00 2001 From: sronilsson Date: Mon, 5 Aug 2024 10:29:19 -0400 Subject: [PATCH] path plotter with roi option --- setup.py | 2 +- simba/plotting/path_plotter.py | 11 ++++---- simba/plotting/path_plotter_mp.py | 33 +++++++++------------- simba/video_processors/video_processing.py | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/setup.py b/setup.py index 31681d8a7..e2cade522 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ # Setup configuration setuptools.setup( name="Simba-UW-tf-dev", - version="1.99.7", + version="1.99.9", author="Simon Nilsson, Jia Jie Choong, Sophia Hwang", author_email="sronilsson@gmail.com", description="Toolkit for computer classification and analysis of behaviors in experimental animals", diff --git a/simba/plotting/path_plotter.py b/simba/plotting/path_plotter.py index 17bdf9790..8ff0ca591 100644 --- a/simba/plotting/path_plotter.py +++ b/simba/plotting/path_plotter.py @@ -130,12 +130,13 @@ def __get_styles(self): else: pass else: - space_scaler, radius_scaler, res_scaler, font_scaler = 25, 10, 1500, 0.8 + font_size, _, _ = PlottingMixin().get_optimal_font_scales(text='MY LONG TEXT STRING', accepted_px_width=int(self.video_info["Resolution_width"] / 10), accepted_px_height=int(self.video_info["Resolution_width"] / 10)) + circle_size = PlottingMixin().get_optimal_circle_size(frame_size=(int(self.video_info["Resolution_width"]), int(self.video_info["Resolution_height"])), circle_frame_ratio=100) self.style_attr["width"] = int(self.video_info["Resolution_width"].values[0]) self.style_attr["height"] = int(self.video_info["Resolution_height"].values[0]) max_res = max(self.style_attr["width"], self.style_attr["height"]) - self.style_attr["circle size"] = int(radius_scaler / (res_scaler / max_res)) - self.style_attr["font size"] = min(0.5, (font_scaler / (res_scaler / max_res))) + self.style_attr["circle size"] = circle_size + self.style_attr["font size"] = font_size self.style_attr["bg color"] = self.color_dict["White"] self.style_attr["print_animal_names"] = self.print_animal_names self.style_attr["max lines"] = len(self.data_df) @@ -279,9 +280,9 @@ def run(self): self.timer.stop_timer() stdout_success(msg=f"Path visualizations for {len(self.files_found)} video(s) saved in {self.path_plot_dir} directory", elapsed_time=self.timer.elapsed_time_str, source=self.__class__.__name__) - - # +# +# # # style_attr = {'width': 'As input', # 'height': 'As input', # 'line width': 2, diff --git a/simba/plotting/path_plotter_mp.py b/simba/plotting/path_plotter_mp.py index d933dd002..de691b841 100644 --- a/simba/plotting/path_plotter_mp.py +++ b/simba/plotting/path_plotter_mp.py @@ -20,10 +20,7 @@ from simba.utils.enums import Formats, TagNames from simba.utils.errors import FrameRangeError, NoSpecifiedOutputError from simba.utils.printing import SimbaTimer, log_event, stdout_success -from simba.utils.read_write import (concatenate_videos_in_folder, - find_core_cnt, find_video_of_file, - get_fn_ext, get_video_meta_data, read_df, - read_frm_of_video, remove_a_folder) +from simba.utils.read_write import (concatenate_videos_in_folder, find_core_cnt, find_video_of_file, get_fn_ext, get_video_meta_data, read_df, read_frm_of_video, remove_a_folder) from simba.utils.warnings import ROIWarning @@ -107,8 +104,6 @@ class PathPlotterMulticore(ConfigReader, PlottingMixin): :param Optional[dict] input_clf_attr: Dict reprenting classified behavior locations, their color and size. If None, then no classified behavior locations are shown. :param Optional[dict] slicing: If Dict, start time and end time of video slice to create path plot from. E.g., {'start_time': '00:00:01', 'end_time': '00:00:03'}. If None, creates path plot for entire video. :param Optional[bool] roi: If True, also plots the ROIs associated with the video. Default False. - - :param int cores: Number of cores to use. .. note:: @@ -187,12 +182,12 @@ def __get_styles(self): else: pass else: - space_scaler, radius_scaler, res_scaler, font_scaler = 25, 10, 1500, 0.8 + font_size, _, _ = PlottingMixin().get_optimal_font_scales(text='MY LONG TEXT STRING', accepted_px_width=int(self.video_info["Resolution_width"] / 10), accepted_px_height=int(self.video_info["Resolution_width"] / 10)) + circle_size = PlottingMixin().get_optimal_circle_size(frame_size=(int(self.video_info["Resolution_width"]), int(self.video_info["Resolution_height"])), circle_frame_ratio=100) self.style_attr["width"] = int(self.video_info["Resolution_width"].values[0]) self.style_attr["height"] = int(self.video_info["Resolution_height"].values[0]) - max_res = max(self.style_attr["width"], self.style_attr["height"]) - self.style_attr["circle size"] = int(radius_scaler / (res_scaler / max_res)) - self.style_attr["font size"] = font_scaler / (res_scaler / max_res) + self.style_attr["circle size"] = circle_size + self.style_attr["font size"] = font_size self.style_attr["bg color"] = self.color_dict["White"] self.style_attr["print_animal_names"] = self.print_animal_names self.style_attr["max lines"] = len(self.data_df) @@ -332,15 +327,15 @@ def run(self): # animal_attr = {0: {'bp': 'Ear_right', 'color': (255, 0, 0)}, 1: {'bp': 'Tail_base', 'color': (0, 0, 255)}} #['Ear_right_1', 'Red'], 1: ['Ear_right_2', 'Green']} -# # style_attr = {'width': 'As input', -# # 'height': 'As input', -# # 'line width': 2, -# # 'font size': 0.9, -# # 'font thickness': 2, -# # 'circle size': 5, -# # 'bg color': {'type': 'moving', 'opacity': 50, 'frame_index': 200}, #{'type': 'static', 'opacity': 100, 'frame_index': 200} -# # 'max lines': 'entire video'} -# # clf_attr = {'Nose to Nose': {'color': (155, 1, 10), 'size': 30}, 'Nose to Tailbase': {'color': (155, 90, 10), 'size': 30}} +# style_attr = {'width': 'As input', +# 'height': 'As input', +# 'line width': 2, +# 'font size': 0.9, +# 'font thickness': 2, +# 'circle size': 5, +# 'bg color': {'type': 'moving', 'opacity': 50, 'frame_index': 200}, #{'type': 'static', 'opacity': 100, 'frame_index': 200} +# 'max lines': 'entire video'} +# clf_attr = {'Nose to Nose': {'color': (155, 1, 10), 'size': 30}, 'Nose to Tailbase': {'color': (155, 90, 10), 'size': 30}} # clf_attr=None # # path_plotter = PathPlotterMulticore(config_path='/Users/simon/Desktop/envs/simba/troubleshooting/RAT_NOR/project_folder/project_config.ini', diff --git a/simba/video_processors/video_processing.py b/simba/video_processors/video_processing.py index 067d59dd4..be9d9c952 100644 --- a/simba/video_processors/video_processing.py +++ b/simba/video_processors/video_processing.py @@ -2910,7 +2910,7 @@ def convert_to_mp4(path: Union[str, os.PathLike], _ = get_video_meta_data(video_path=file_path) out_path = os.path.join(save_dir, f'{video_name}.mp4') if codec == 'powerpoint': - cmd = f'ffmpeg -i "{file_path}" -c:v libx264 -preset slow -profile:v high -level:v 4.0 -pix_fmt yuv420p -crf {crf} -c:v libx264 -codec:a aac "{out_path}" -loglevel error -stats -hide_banner -y' + cmd = f'ffmpeg -i "{file_path}" -c:v libx264 -preset slow -profile:v high -level:v 4.0 -pix_fmt yuv420p -crf {quality} -c:v libx264 -codec:a aac "{out_path}" -loglevel error -stats -hide_banner -y' elif codec == 'vp9': cmd = f'ffmpeg -i "{file_path}" -c:v libvpx-vp9 -crf {quality} -b:v 0 -an "{out_path}" -loglevel error -stats -hide_banner -y' elif codec == 'h264_cuvid':