Skip to content

Commit

Permalink
path plotter with roi option
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Aug 5, 2024
1 parent f1d587b commit a433384
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
description="Toolkit for computer classification and analysis of behaviors in experimental animals",
Expand Down
11 changes: 6 additions & 5 deletions simba/plotting/path_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 14 additions & 19 deletions simba/plotting/path_plotter_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion simba/video_processors/video_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit a433384

Please sign in to comment.