simba-uw-tf-dev 4.6.1__py3-none-any.whl → 4.6.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simba/SimBA.py +2 -2
- simba/assets/icons/frames_2.png +0 -0
- simba/data_processors/agg_clf_counter_mp.py +52 -53
- simba/data_processors/cuda/image.py +3 -1
- simba/data_processors/cue_light_analyzer.py +5 -9
- simba/mixins/geometry_mixin.py +14 -28
- simba/mixins/image_mixin.py +10 -14
- simba/mixins/train_model_mixin.py +2 -2
- simba/plotting/ROI_feature_visualizer_mp.py +3 -5
- simba/plotting/clf_validator_mp.py +4 -5
- simba/plotting/cue_light_visualizer.py +6 -7
- simba/plotting/directing_animals_visualizer_mp.py +2 -3
- simba/plotting/distance_plotter_mp.py +378 -378
- simba/plotting/frame_mergerer_ffmpeg.py +137 -137
- simba/plotting/gantt_creator_mp.py +59 -31
- simba/plotting/geometry_plotter.py +270 -272
- simba/plotting/heat_mapper_clf_mp.py +2 -4
- simba/plotting/heat_mapper_location_mp.py +2 -2
- simba/plotting/light_dark_box_plotter.py +2 -2
- simba/plotting/path_plotter_mp.py +26 -29
- simba/plotting/plot_clf_results_mp.py +455 -454
- simba/plotting/pose_plotter_mp.py +27 -32
- simba/plotting/probability_plot_creator_mp.py +288 -288
- simba/plotting/roi_plotter_mp.py +29 -30
- simba/plotting/single_run_model_validation_video_mp.py +427 -427
- simba/plotting/spontaneous_alternation_plotter.py +2 -3
- simba/plotting/yolo_pose_track_visualizer.py +31 -27
- simba/plotting/yolo_pose_visualizer.py +32 -34
- simba/plotting/yolo_seg_visualizer.py +2 -3
- simba/roi_tools/roi_aggregate_stats_mp.py +4 -3
- simba/roi_tools/roi_clf_calculator_mp.py +3 -3
- simba/sandbox/cuda/egocentric_rotator.py +374 -0
- simba/sandbox/get_cpu_pool.py +5 -0
- simba/ui/pop_ups/clf_add_remove_print_pop_up.py +3 -1
- simba/ui/pop_ups/egocentric_alignment_pop_up.py +6 -3
- simba/ui/pop_ups/multiple_videos_to_frames_popup.py +10 -11
- simba/ui/pop_ups/single_video_to_frames_popup.py +10 -10
- simba/ui/pop_ups/video_processing_pop_up.py +63 -63
- simba/ui/tkinter_functions.py +7 -1
- simba/utils/data.py +89 -12
- simba/utils/enums.py +1 -0
- simba/utils/printing.py +9 -8
- simba/utils/read_write.py +3726 -3721
- simba/video_processors/clahe_ui.py +65 -22
- simba/video_processors/egocentric_video_rotator.py +6 -9
- simba/video_processors/video_processing.py +21 -10
- simba/video_processors/videos_to_frames.py +3 -2
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/METADATA +1 -1
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/RECORD +53 -50
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/LICENSE +0 -0
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/WHEEL +0 -0
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/entry_points.txt +0 -0
- {simba_uw_tf_dev-4.6.1.dist-info → simba_uw_tf_dev-4.6.3.dist-info}/top_level.txt +0 -0
|
@@ -79,13 +79,12 @@ sys.setrecursionlimit(10**7)
|
|
|
79
79
|
|
|
80
80
|
class CLAHEPopUp(PopUpMixin):
|
|
81
81
|
def __init__(self):
|
|
82
|
-
super().__init__(title="CLAHE VIDEO CONVERSION")
|
|
82
|
+
super().__init__(title="CLAHE VIDEO CONVERSION", icon='clahe')
|
|
83
83
|
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name='settings', icon_link=Links.VIDEO_TOOLS.value)
|
|
84
84
|
lbl = SimBALabel(parent=settings_frm, txt='For more control over CLAHE conversion, try "Interactively CLAHE enhance videos" \n in SimBA Tools->Remove color from videos.', font=Formats.FONT_REGULAR_ITALICS.value)
|
|
85
|
-
self.core_cnt_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=list(range(1, find_core_cnt()[0]+1)), label='CORE COUNT:', label_width=25, dropdown_width=20, value=1)
|
|
86
|
-
self.gpu_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=['TRUE', 'FALSE'], label='USE GPU:', label_width=25, dropdown_width=20, value='FALSE')
|
|
87
|
-
if not check_nvidea_gpu_available():
|
|
88
|
-
self.gpu_dropdown.disable()
|
|
85
|
+
self.core_cnt_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=list(range(1, find_core_cnt()[0]+1)), label='CORE COUNT:', label_width=25, dropdown_width=20, value=1, img='cpu_small')
|
|
86
|
+
self.gpu_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=['TRUE', 'FALSE'], label='USE GPU:', label_width=25, dropdown_width=20, value='FALSE', img='gpu_3')
|
|
87
|
+
if not check_nvidea_gpu_available(): self.gpu_dropdown.disable()
|
|
89
88
|
|
|
90
89
|
settings_frm.grid(row=0, column=0, sticky=NW)
|
|
91
90
|
lbl.grid(row=0, column=0, sticky=NW)
|
|
@@ -93,10 +92,10 @@ class CLAHEPopUp(PopUpMixin):
|
|
|
93
92
|
self.gpu_dropdown.grid(row=2, column=0, sticky=NW)
|
|
94
93
|
|
|
95
94
|
single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SINGLE VIDEO - Contrast Limited Adaptive Histogram Equalization", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
96
|
-
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25)
|
|
95
|
+
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25, lbl_icon='video_2')
|
|
97
96
|
run_single_video_btn = SimbaButton(parent=single_video_frm, txt="Apply CLAHE on VIDEO", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_single_video, width=160)
|
|
98
97
|
multiple_videos_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="MULTIPLE VIDEOs - Contrast Limited Adaptive Histogram Equalization", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
99
|
-
self.selected_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", lblwidth=25)
|
|
98
|
+
self.selected_dir = FolderSelect(multiple_videos_frm, "VIDEO DIRECTORY PATH:", lblwidth=25, lbl_icon='folder')
|
|
100
99
|
|
|
101
100
|
run_multiple_btn = SimbaButton(parent=multiple_videos_frm, txt="Apply CLAHE on DIRECTORY", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_directory, width=160)
|
|
102
101
|
single_video_frm.grid(row=1, column=0, sticky=NW)
|
|
@@ -609,15 +608,18 @@ class ConvertVideoPopUp(PopUpMixin):
|
|
|
609
608
|
|
|
610
609
|
class ExtractSpecificFramesPopUp(PopUpMixin):
|
|
611
610
|
def __init__(self):
|
|
612
|
-
PopUpMixin.__init__(self, title="EXTRACT DEFINED FRAME RANGE FROM VIDEO", icon='frames')
|
|
611
|
+
PopUpMixin.__init__(self, title="EXTRACT DEFINED FRAME RANGE FROM SINGLE VIDEO", icon='frames')
|
|
613
612
|
self.settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm,header="SETTINGS", icon_name=Keys.DOCUMENTATION.value,icon_link=Links.VIDEO_TOOLS.value)
|
|
614
|
-
self.video_file_selected = FileSelect(self.settings_frm , "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=40)
|
|
615
|
-
self.save_dir = FolderSelect(self.settings_frm, "SAVE DIRECTORY: ", lblwidth=40, tooltip_txt='Optional directory where to save the images. \n If None, images are saved in a folder with the suffix `_frames` \n within the same directory as the video file')
|
|
613
|
+
self.video_file_selected = FileSelect(self.settings_frm , "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=40, lbl_icon='video_2')
|
|
614
|
+
self.save_dir = FolderSelect(self.settings_frm, "SAVE DIRECTORY: ", lblwidth=40, tooltip_txt='Optional directory where to save the images. \n If None, images are saved in a folder with the suffix `_frames` \n within the same directory as the video file', lbl_icon='folder')
|
|
615
|
+
|
|
616
|
+
self.format_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['jpeg', 'png', 'webp'], label="SAVE FORMAT: ", label_width=40, dropdown_width=25, value='png', img='file_type')
|
|
617
|
+
self.grey_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="GREYSCALE: ", label_width=40, dropdown_width=25, value='FALSE', img='grey')
|
|
618
|
+
self.clahe_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="CLAHE: ", label_width=40, dropdown_width=25, value='FALSE', img='clahe')
|
|
619
|
+
self.include_fn_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="INCLUDE VIDEO NAME IN IMAGE NAME: ", label_width=40, dropdown_width=25, value='FALSE', img='id_card_2')
|
|
620
|
+
self.start_frm = Entry_Box(parent=self.settings_frm, fileDescription="START FRAME NUMBER:", labelwidth=40, validation='numeric', width=25, img='play')
|
|
621
|
+
self.end_frm = Entry_Box(parent=self.settings_frm, fileDescription="END FRAME NUMBER:", labelwidth=40, validation='numeric', width=25, img='stop')
|
|
616
622
|
|
|
617
|
-
self.format_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['jpeg', 'png', 'webp'], label="FORMAT: ", label_width=40, dropdown_width=25, value='png')
|
|
618
|
-
self.grey_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="GREYSCALE: ", label_width=40, dropdown_width=25, value='FALSE')
|
|
619
|
-
self.clahe_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="CLAHE: ", label_width=40, dropdown_width=25, value='FALSE')
|
|
620
|
-
self.include_fn_dropdown = SimBADropDown(parent=self.settings_frm, dropdown_options=['TRUE', 'FALSE'], label="INCLUDE VIDEO NAME IN IMAGE NAME: ", label_width=40, dropdown_width=25, value='FALSE')
|
|
621
623
|
|
|
622
624
|
self.settings_frm.grid(row=0, column=0, sticky=NW)
|
|
623
625
|
self.video_file_selected.grid(row=0, column=0, sticky=NW)
|
|
@@ -626,16 +628,11 @@ class ExtractSpecificFramesPopUp(PopUpMixin):
|
|
|
626
628
|
self.grey_dropdown.grid(row=3, column=0, sticky=NW)
|
|
627
629
|
self.clahe_dropdown.grid(row=4, column=0, sticky=NW)
|
|
628
630
|
self.include_fn_dropdown.grid(row=5, column=0, sticky=NW)
|
|
631
|
+
self.start_frm.grid(row=6, column=0, sticky=NW)
|
|
632
|
+
self.end_frm.grid(row=7, column=0, sticky=NW)
|
|
629
633
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
self.end_frm = Entry_Box(select_frames_frm, "END FRAME NUMBER:", "40", validation='numeric')
|
|
633
|
-
run_btn = SimbaButton(parent=select_frames_frm, txt="RUN", img='rocket', font=Formats.FONT_REGULAR.value, cmd=self.start_frm_extraction)
|
|
634
|
-
|
|
635
|
-
select_frames_frm.grid(row=1, column=0, sticky=NW)
|
|
636
|
-
self.start_frm.grid(row=2, column=0, sticky=NW)
|
|
637
|
-
self.end_frm.grid(row=3, column=0, sticky=NW)
|
|
638
|
-
run_btn.grid(row=4, pady=5, sticky=NW)
|
|
634
|
+
run_btn = SimbaButton(parent=self.main_frm, txt="RUN", img='rocket', font=Formats.FONT_REGULAR.value, cmd=self.start_frm_extraction)
|
|
635
|
+
run_btn.grid(row=1, column=0, pady=5, sticky=NW)
|
|
639
636
|
self.main_frm.mainloop()
|
|
640
637
|
|
|
641
638
|
def start_frm_extraction(self):
|
|
@@ -848,30 +845,34 @@ class MergeFrames2VideoPopUp(PopUpMixin):
|
|
|
848
845
|
|
|
849
846
|
class CreateGIFPopUP(PopUpMixin):
|
|
850
847
|
def __init__(self):
|
|
851
|
-
PopUpMixin.__init__(self, title="CREATE GIF FROM VIDEO", size=(600, 400), icon='gif')
|
|
852
|
-
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
853
|
-
self.selected_video = FileSelect(settings_frm, "VIDEO PATH: ", title="Select a video file", file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=40)
|
|
854
|
-
self.start_time_entry_box = Entry_Box(settings_frm, "START TIME (s):", "40", validation="numeric")
|
|
855
|
-
self.duration_entry_box = Entry_Box(settings_frm, "DURATION (s): ", "40", validation="numeric")
|
|
856
848
|
resolution_widths = Options.RESOLUTION_OPTIONS_2.value
|
|
857
|
-
self.resolution_dropdown = DropDownMenu(settings_frm, "GIF WIDTH (ASPECT RATIO RETAINED):", resolution_widths, "40")
|
|
858
|
-
self.quality_dropdown = DropDownMenu(settings_frm, "GIF QUALITY (%):", list(range(1, 101, 1)), "40")
|
|
859
849
|
fps_lst = list(range(1, 101, 1))
|
|
860
850
|
fps_lst.insert(0, 'AUTO')
|
|
861
|
-
|
|
862
|
-
|
|
851
|
+
gpu_state = NORMAL if check_nvidea_gpu_available(raise_error=False) else DISABLED
|
|
852
|
+
PopUpMixin.__init__(self, title="CREATE GIF FROM VIDEO", size=(600, 400), icon='gif')
|
|
853
|
+
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
863
854
|
|
|
864
|
-
self.
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
855
|
+
info_lbl = SimBALabel(parent=self.main_frm, txt='Consider creating WEBM videos instead of creating GIFs.\n WEBM is optimized for web publish at \nconsiderbly smaller sizes than GIFs.', txt_clr='blue', font=Formats.FONT_REGULAR_ITALICS.value, justify='center')
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
self.selected_video = FileSelect(settings_frm, "VIDEO PATH: ", title="Select a video file", file_types=[("VIDEO FILE", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=40, lbl_icon='video_2')
|
|
859
|
+
self.start_time_entry_box = Entry_Box(parent=settings_frm, fileDescription="START TIME (s):", labelwidth=40, validation="numeric", img='play', width=25)
|
|
860
|
+
self.duration_entry_box = Entry_Box(parent=settings_frm, fileDescription="DURATION (s):", labelwidth=40, validation="numeric", img='stop', width=25)
|
|
861
|
+
|
|
862
|
+
self.resolution_dropdown = SimBADropDown(parent=settings_frm, label="GIF WIDTH (ASPECT RATIO RETAINED):", dropdown_options=resolution_widths, label_width=40, dropdown_width=25, value='AUTO', img='monitor')
|
|
863
|
+
self.quality_dropdown = SimBADropDown(parent=settings_frm, label="GIF QUALITY (%):", dropdown_options=list(range(1, 101, 1)), label_width=40, dropdown_width=25, value=100, img='pct_2')
|
|
864
|
+
self.fps_dropdown = SimBADropDown(parent=settings_frm, label="GIF FPS:", dropdown_options=fps_lst, label_width=40, dropdown_width=25, value='AUTO', img='fps')
|
|
865
|
+
self.gpu_dropdown = SimBADropDown(parent=settings_frm, label="USE GPU:", dropdown_options=['TRUE', 'FALSE'], label_width=40, dropdown_width=25, value='FALSE', img='gpu_3', state=gpu_state)
|
|
866
|
+
|
|
867
|
+
info_lbl.grid(row=0, sticky=NW)
|
|
868
|
+
settings_frm.grid(row=1, sticky=NW)
|
|
868
869
|
self.selected_video.grid(row=0, sticky=NW, pady=5)
|
|
869
870
|
self.start_time_entry_box.grid(row=1, sticky=NW)
|
|
870
871
|
self.duration_entry_box.grid(row=2, sticky=NW)
|
|
871
872
|
self.resolution_dropdown.grid(row=3, sticky=NW)
|
|
872
873
|
self.quality_dropdown.grid(row=4, sticky=NW)
|
|
873
874
|
self.fps_dropdown.grid(row=5, sticky=NW)
|
|
874
|
-
|
|
875
|
+
self.gpu_dropdown.grid(row=6, column=0, sticky=NW)
|
|
875
876
|
self.create_run_frm(run_function=self.run)
|
|
876
877
|
self.main_frm.mainloop()
|
|
877
878
|
|
|
@@ -882,7 +883,7 @@ class CreateGIFPopUP(PopUpMixin):
|
|
|
882
883
|
duration = self.duration_entry_box.entry_get
|
|
883
884
|
fps = self.fps_dropdown.getChoices()
|
|
884
885
|
quality = int(self.quality_dropdown.getChoices())
|
|
885
|
-
gpu = self.
|
|
886
|
+
gpu = self.gpu_dropdown.get_value()
|
|
886
887
|
check_ffmpeg_available()
|
|
887
888
|
if gpu: check_nvidea_gpu_available()
|
|
888
889
|
check_file_exist_and_readable(file_path=video_path)
|
|
@@ -892,7 +893,7 @@ class CreateGIFPopUP(PopUpMixin):
|
|
|
892
893
|
if fps == 'AUTO': fps = int(video_meta_data['fps'])
|
|
893
894
|
else: fps = int(fps)
|
|
894
895
|
if fps > int(video_meta_data['fps']):
|
|
895
|
-
FrameRangeWarning(msg=f'The chosen FPS ({fps}) is higher than the video FPS ({video_meta_data["fps"]}). The video FPS will be used', source=self.__class__.__name__)
|
|
896
|
+
FrameRangeWarning(msg=f'The chosen FPS ({fps}) is higher than the video FPS ({video_meta_data["fps"]}). The video FPS will be used ({video_meta_data["fps"]})', source=self.__class__.__name__)
|
|
896
897
|
fps = int(video_meta_data['fps'])
|
|
897
898
|
max_duration = video_meta_data['video_length_s'] - int(start_time)
|
|
898
899
|
check_int(name='start_time', value=start_time, max_value=video_meta_data['video_length_s'], min_value=0)
|
|
@@ -1765,16 +1766,16 @@ class BrightnessContrastPopUp(PopUpMixin):
|
|
|
1765
1766
|
:align: center
|
|
1766
1767
|
"""
|
|
1767
1768
|
def __init__(self):
|
|
1768
|
-
super().__init__(title="CHANGE BRIGHTNESS / CONTRAST")
|
|
1769
|
+
super().__init__(title="CHANGE BRIGHTNESS / CONTRAST", icon='brightness')
|
|
1769
1770
|
self.datetime = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
1770
1771
|
setting_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
1771
1772
|
gpu_available = NORMAL if check_nvidea_gpu_available() else DISABLED
|
|
1772
|
-
self.gpu_dropdown = SimBADropDown(parent=setting_frm, label="USE GPU:", dropdown_options=['TRUE', 'FALSE'], dropdown_width=20, value='FALSE', state=gpu_available, img='gpu_3')
|
|
1773
|
+
self.gpu_dropdown = SimBADropDown(parent=setting_frm, label="USE GPU:", dropdown_options=['TRUE', 'FALSE'], dropdown_width=20, value='FALSE', state=gpu_available, img='gpu_3', label_width=25)
|
|
1773
1774
|
setting_frm.grid(row=0, column=0, sticky="NW")
|
|
1774
1775
|
self.gpu_dropdown.grid(row=0, column=0, sticky="NW")
|
|
1775
1776
|
|
|
1776
1777
|
single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CHANGE BRIGHTNESS / CONTRAST SINGLE VIDEO", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
1777
|
-
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25)
|
|
1778
|
+
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25, lbl_icon='video_2')
|
|
1778
1779
|
run_video_btn = SimbaButton(parent=single_video_frm, txt="RUN SINGLE VIDEO", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_video)
|
|
1779
1780
|
|
|
1780
1781
|
single_video_frm.grid(row=1, column=0, sticky="NW")
|
|
@@ -1782,7 +1783,7 @@ class BrightnessContrastPopUp(PopUpMixin):
|
|
|
1782
1783
|
run_video_btn.grid(row=1, column=0, sticky="NW")
|
|
1783
1784
|
|
|
1784
1785
|
video_dir_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CHANGE BRIGHTNESS / CONTRAST MULTIPLE VIDEOS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
1785
|
-
self.selected_dir = FolderSelect(video_dir_frm, "VIDEO DIRECTORY PATH:", lblwidth=25)
|
|
1786
|
+
self.selected_dir = FolderSelect(video_dir_frm, "VIDEO DIRECTORY PATH:", lblwidth=25, lbl_icon='folder')
|
|
1786
1787
|
|
|
1787
1788
|
run_dir_btn = SimbaButton(parent=video_dir_frm, txt="RUN VIDEO DIRECTORY", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_directory)
|
|
1788
1789
|
|
|
@@ -1837,11 +1838,11 @@ class InteractiveClahePopUp(PopUpMixin):
|
|
|
1837
1838
|
"""
|
|
1838
1839
|
|
|
1839
1840
|
def __init__(self):
|
|
1840
|
-
super().__init__(title="INTERACTIVE CLAHE")
|
|
1841
|
+
super().__init__(title="INTERACTIVE CLAHE", icon='clahe')
|
|
1841
1842
|
self.datetime = datetime.now().strftime("%Y%m%d%H%M%S")
|
|
1842
1843
|
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name='settings', icon_link=Links.VIDEO_TOOLS.value)
|
|
1843
|
-
self.core_cnt_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=list(range(1, find_core_cnt()[0]+1)), label='CORE COUNT:', label_width=25, dropdown_width=20, value=1)
|
|
1844
|
-
self.gpu_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=['TRUE', 'FALSE'], label='USE GPU:', label_width=25, dropdown_width=20, value='FALSE')
|
|
1844
|
+
self.core_cnt_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=list(range(1, find_core_cnt()[0]+1)), label='CORE COUNT:', label_width=25, dropdown_width=20, value=1, img='cpu_small')
|
|
1845
|
+
self.gpu_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=['TRUE', 'FALSE'], label='USE GPU:', label_width=25, dropdown_width=20, value='FALSE', img='gpu_3')
|
|
1845
1846
|
if not check_nvidea_gpu_available():
|
|
1846
1847
|
self.gpu_dropdown.disable()
|
|
1847
1848
|
|
|
@@ -1852,7 +1853,7 @@ class InteractiveClahePopUp(PopUpMixin):
|
|
|
1852
1853
|
|
|
1853
1854
|
|
|
1854
1855
|
single_video_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="INTERACTIVE CLAHE - SINGLE VIDEO", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
1855
|
-
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25)
|
|
1856
|
+
self.selected_video = FileSelect(single_video_frm, "VIDEO PATH:", title="Select a video file", file_types=[("VIDEO", Options.ALL_VIDEO_FORMAT_STR_OPTIONS.value)], lblwidth=25, lbl_icon='video_2')
|
|
1856
1857
|
run_video_btn = SimbaButton(parent=single_video_frm, txt="RUN SINGLE VIDEO", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_video, width=160)
|
|
1857
1858
|
|
|
1858
1859
|
|
|
@@ -1861,7 +1862,7 @@ class InteractiveClahePopUp(PopUpMixin):
|
|
|
1861
1862
|
run_video_btn.grid(row=1, column=0, sticky="NW")
|
|
1862
1863
|
|
|
1863
1864
|
video_dir_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="INTERACTIVE CLAHE - MULTIPLE VIDEOS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
1864
|
-
self.selected_dir = FolderSelect(video_dir_frm, "VIDEO DIRECTORY PATH:", lblwidth=25)
|
|
1865
|
+
self.selected_dir = FolderSelect(video_dir_frm, "VIDEO DIRECTORY PATH:", lblwidth=25, lbl_icon='folder')
|
|
1865
1866
|
run_dir_btn = SimbaButton(parent=video_dir_frm, txt="RUN VIDEO DIRECTORY", img='rocket', txt_clr='blue', font=Formats.FONT_REGULAR.value, cmd=self.run_directory, width=160)
|
|
1866
1867
|
video_dir_frm.grid(row=2, column=0, sticky="NW")
|
|
1867
1868
|
self.selected_dir.grid(row=0, column=0, sticky="NW")
|
|
@@ -2048,16 +2049,15 @@ class DownsampleMultipleVideosPopUp(PopUpMixin):
|
|
|
2048
2049
|
|
|
2049
2050
|
class Convert2jpegPopUp(PopUpMixin):
|
|
2050
2051
|
def __init__(self):
|
|
2051
|
-
super().__init__(title="CONVERT
|
|
2052
|
+
super().__init__(title="CONVERT IMAGES TO JPEG", icon='jpeg')
|
|
2052
2053
|
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2053
|
-
|
|
2054
|
-
self.quality_scale =
|
|
2055
|
-
self.quality_scale.set(95)
|
|
2054
|
+
|
|
2055
|
+
self.quality_scale = SimBAScaleBar(parent=settings_frm, label="JPEG OUTPUT QUALITY: ", orient=HORIZONTAL, length=200, value=95, label_width=25, lbl_img='pct_2')
|
|
2056
2056
|
settings_frm.grid(row=0, column=0, sticky="NW")
|
|
2057
2057
|
self.quality_scale.grid(row=0, column=0, sticky="NW")
|
|
2058
2058
|
|
|
2059
2059
|
img_dir_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE DIRECTORY TO JPEG", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2060
|
-
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25)
|
|
2060
|
+
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25, lbl_icon='folder')
|
|
2061
2061
|
|
|
2062
2062
|
run_btn_dir = SimbaButton(parent=img_dir_frm, txt="RUN DIRECTORY JPEG CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=self.run_dir)
|
|
2063
2063
|
img_dir_frm.grid(row=1, column=0, sticky="NW")
|
|
@@ -2065,7 +2065,7 @@ class Convert2jpegPopUp(PopUpMixin):
|
|
|
2065
2065
|
run_btn_dir.grid(row=1, column=0, sticky="NW")
|
|
2066
2066
|
|
|
2067
2067
|
img_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE TO JPEG", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2068
|
-
self.selected_file = FileSelect(img_frm, "IMAGE PATH:", title="Select an image file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_IMAGE_FORMAT_OPTIONS.value)])
|
|
2068
|
+
self.selected_file = FileSelect(img_frm, "IMAGE PATH:", title="Select an image file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_IMAGE_FORMAT_OPTIONS.value)], lbl_icon='frames')
|
|
2069
2069
|
|
|
2070
2070
|
run_btn_img = SimbaButton(parent=img_frm, txt="RUN IMAGE JPEG CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=self.run_img)
|
|
2071
2071
|
img_frm.grid(row=2, column=0, sticky="NW")
|
|
@@ -2075,19 +2075,19 @@ class Convert2jpegPopUp(PopUpMixin):
|
|
|
2075
2075
|
def run_dir(self):
|
|
2076
2076
|
folder_path = self.selected_frame_dir.folder_path
|
|
2077
2077
|
check_if_dir_exists(in_dir=folder_path)
|
|
2078
|
-
_ = convert_to_jpeg(path=folder_path, quality=int(self.quality_scale.
|
|
2078
|
+
_ = convert_to_jpeg(path=folder_path, quality=int(self.quality_scale.get_value()), verbose=True)
|
|
2079
2079
|
|
|
2080
2080
|
def run_img(self):
|
|
2081
2081
|
file_path = self.selected_file.file_path
|
|
2082
2082
|
check_file_exist_and_readable(file_path)
|
|
2083
|
-
_ = convert_to_jpeg(path=file_path, quality=int(self.quality_scale.
|
|
2083
|
+
_ = convert_to_jpeg(path=file_path, quality=int(self.quality_scale.get_value()), verbose=True)
|
|
2084
2084
|
|
|
2085
2085
|
|
|
2086
2086
|
class Convert2bmpPopUp(PopUpMixin):
|
|
2087
2087
|
def __init__(self):
|
|
2088
|
-
super().__init__(title="CONVERT IMAGES TO BMP")
|
|
2088
|
+
super().__init__(title="CONVERT IMAGES TO BMP", icon='bmp')
|
|
2089
2089
|
img_dir_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE DIRECTORY TO BMP", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2090
|
-
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25)
|
|
2090
|
+
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25, lbl_icon='folder')
|
|
2091
2091
|
|
|
2092
2092
|
run_btn_dir = SimbaButton(parent=img_dir_frm, txt="RUN DIRECTORY BMP CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=self.run_dir)
|
|
2093
2093
|
img_dir_frm.grid(row=0, column=0, sticky="NW")
|
|
@@ -2095,7 +2095,7 @@ class Convert2bmpPopUp(PopUpMixin):
|
|
|
2095
2095
|
run_btn_dir.grid(row=1, column=0, sticky="NW")
|
|
2096
2096
|
|
|
2097
2097
|
img_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE TO BMP", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2098
|
-
self.selected_file = FileSelect(img_frm, "IMAGE PATH:", title="Select an image file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_IMAGE_FORMAT_OPTIONS.value)])
|
|
2098
|
+
self.selected_file = FileSelect(img_frm, "IMAGE PATH:", title="Select an image file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_IMAGE_FORMAT_OPTIONS.value)], lbl_icon='bmp')
|
|
2099
2099
|
run_btn_img = SimbaButton(parent=img_frm, txt="RUN IMAGE BMP CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=lambda: self.run_img())
|
|
2100
2100
|
|
|
2101
2101
|
img_frm.grid(row=1, column=0, sticky="NW")
|
|
@@ -2157,7 +2157,7 @@ class Convert2WEBPPopUp(PopUpMixin):
|
|
|
2157
2157
|
|
|
2158
2158
|
class Convert2TIFFPopUp(PopUpMixin):
|
|
2159
2159
|
def __init__(self):
|
|
2160
|
-
super().__init__(title="CONVERT IMAGE DIRECTORY TO TIFF")
|
|
2160
|
+
super().__init__(title="CONVERT IMAGE DIRECTORY TO TIFF", icon='tiff')
|
|
2161
2161
|
settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2162
2162
|
self.selected_frame_dir = FolderSelect(settings_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25, lbl_icon='browse')
|
|
2163
2163
|
self.compression_dropdown = SimBADropDown(parent=settings_frm, dropdown_options=['raw', 'tiff_deflate', 'tiff_lzw'], label="COMPRESSION:", label_width=25, dropdown_width=25, value='raw', img='file_type')
|
|
@@ -2178,9 +2178,9 @@ class Convert2TIFFPopUp(PopUpMixin):
|
|
|
2178
2178
|
|
|
2179
2179
|
class Convert2PNGPopUp(PopUpMixin):
|
|
2180
2180
|
def __init__(self):
|
|
2181
|
-
super().__init__(title="CONVERT IMAGE TO PNG")
|
|
2181
|
+
super().__init__(title="CONVERT IMAGE TO PNG", icon='png')
|
|
2182
2182
|
img_dir_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE DIRECTORY TO PNG", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2183
|
-
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25)
|
|
2183
|
+
self.selected_frame_dir = FolderSelect(img_dir_frm, "IMAGE DIRECTORY PATH:", title="Select a image directory", lblwidth=25, lbl_icon='folder')
|
|
2184
2184
|
run_btn_dir = SimbaButton(parent=img_dir_frm, txt="RUN DIRECTORY PNG CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=lambda: self.run_dir())
|
|
2185
2185
|
|
|
2186
2186
|
img_dir_frm.grid(row=0, column=0, sticky="NW")
|
|
@@ -2189,7 +2189,7 @@ class Convert2PNGPopUp(PopUpMixin):
|
|
|
2189
2189
|
|
|
2190
2190
|
img_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="CONVERT IMAGE TO PNG", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.VIDEO_TOOLS.value)
|
|
2191
2191
|
self.selected_file_dir = FileSelect(img_frm, "IMAGE PATH:", title="Select a video file", lblwidth=25, file_types=[("VIDEO FILE", Options.ALL_IMAGE_FORMAT_OPTIONS.value)], lbl_icon='file_type')
|
|
2192
|
-
run_btn_img = SimbaButton(parent=img_frm, txt="RUN PNG CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=lambda: self.run_img())
|
|
2192
|
+
run_btn_img = SimbaButton(parent=img_frm, txt="RUN IMAGE PNG CONVERSION", img='rocket', txt_clr='black', font=Formats.FONT_REGULAR.value, cmd=lambda: self.run_img())
|
|
2193
2193
|
|
|
2194
2194
|
img_frm.grid(row=1, column=0, sticky="NW")
|
|
2195
2195
|
self.selected_file_dir.grid(row=0, column=0, sticky="NW")
|
simba/ui/tkinter_functions.py
CHANGED
|
@@ -156,6 +156,7 @@ class SimBAScaleBar(Frame):
|
|
|
156
156
|
def __init__(self,
|
|
157
157
|
parent: Union[Frame, Canvas, LabelFrame, Toplevel, Tk],
|
|
158
158
|
label: Optional[str] = None,
|
|
159
|
+
label_width: Optional[int] = None,
|
|
159
160
|
orient: Literal['horizontal', 'vertical'] = HORIZONTAL,
|
|
160
161
|
length: int = 200,
|
|
161
162
|
value: Optional[int] = 95,
|
|
@@ -194,7 +195,7 @@ class SimBAScaleBar(Frame):
|
|
|
194
195
|
showvalue=showvalue)
|
|
195
196
|
|
|
196
197
|
if label is not None:
|
|
197
|
-
self.lbl = SimBALabel(parent=self, txt=label, font=lbl_font, txt_clr=label_clr)
|
|
198
|
+
self.lbl = SimBALabel(parent=self, txt=label, font=lbl_font, txt_clr=label_clr, width=label_width)
|
|
198
199
|
self.lbl.grid(row=0, column=1, sticky=SW)
|
|
199
200
|
|
|
200
201
|
self.scale.grid(row=0, column=2, sticky=NW)
|
|
@@ -207,6 +208,11 @@ class SimBAScaleBar(Frame):
|
|
|
207
208
|
def get_value(self) -> Union[int, float]:
|
|
208
209
|
return self.scale.get()
|
|
209
210
|
|
|
211
|
+
def get(self) -> Union[int, float]:
|
|
212
|
+
## Alternative for ``get_value`` for legacy reasons.
|
|
213
|
+
return self.scale.get()
|
|
214
|
+
|
|
215
|
+
|
|
210
216
|
|
|
211
217
|
|
|
212
218
|
class Entry_Box(Frame):
|
simba/utils/data.py
CHANGED
|
@@ -5,6 +5,7 @@ import configparser
|
|
|
5
5
|
import gc
|
|
6
6
|
import io
|
|
7
7
|
import os
|
|
8
|
+
import platform
|
|
8
9
|
import subprocess
|
|
9
10
|
from copy import deepcopy
|
|
10
11
|
from datetime import datetime
|
|
@@ -38,15 +39,19 @@ from simba.utils.checks import (check_file_exist_and_readable, check_float,
|
|
|
38
39
|
check_if_valid_rgb_tuple, check_instance,
|
|
39
40
|
check_int, check_str, check_that_column_exist,
|
|
40
41
|
check_that_hhmmss_start_is_before_end,
|
|
41
|
-
check_valid_array,
|
|
42
|
-
check_valid_dataframe,
|
|
43
|
-
|
|
42
|
+
check_valid_array, check_valid_boolean,
|
|
43
|
+
check_valid_cpu_pool, check_valid_dataframe,
|
|
44
|
+
check_valid_lst)
|
|
45
|
+
from simba.utils.enums import (OS, ConfigKey, Defaults, Dtypes, Formats, Keys,
|
|
46
|
+
Options)
|
|
44
47
|
from simba.utils.errors import (BodypartColumnNotFoundError, CountError,
|
|
45
48
|
InvalidFileTypeError, InvalidInputError,
|
|
46
49
|
NoFilesFoundError, NoROIDataError,
|
|
47
50
|
SimBAModuleNotFoundError)
|
|
51
|
+
from simba.utils.lookups import get_current_time
|
|
48
52
|
from simba.utils.printing import stdout_success, stdout_warning
|
|
49
|
-
from simba.utils.read_write import (
|
|
53
|
+
from simba.utils.read_write import (find_core_cnt, find_video_of_file,
|
|
54
|
+
get_current_time, get_fn_ext,
|
|
50
55
|
get_video_meta_data, read_config_entry,
|
|
51
56
|
read_config_file, read_df,
|
|
52
57
|
read_project_path_and_file_type,
|
|
@@ -1813,33 +1818,105 @@ def fft_lowpass_filter(data: np.ndarray, cut_off: float = 0.1) -> np.ndarray:
|
|
|
1813
1818
|
return results.astype(data.dtype)
|
|
1814
1819
|
|
|
1815
1820
|
|
|
1816
|
-
def terminate_cpu_pool(pool:
|
|
1817
|
-
force: bool = False
|
|
1821
|
+
def terminate_cpu_pool(pool: multiprocessing.pool.Pool,
|
|
1822
|
+
force: bool = False,
|
|
1823
|
+
verbose: bool = True,
|
|
1824
|
+
source: Optional[str] = None) -> None:
|
|
1818
1825
|
"""
|
|
1819
|
-
Safely terminates a multiprocessing.Pool instance.
|
|
1826
|
+
Safely terminates a multiprocessing.Pool instance with optional graceful shutdown.
|
|
1820
1827
|
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1828
|
+
.. note::
|
|
1829
|
+
If pool is None or invalid, function returns without action. Exceptions during termination are silently caught.
|
|
1830
|
+
|
|
1831
|
+
:param multiprocessing.pool.Pool pool: The multiprocessing pool to terminate. If None, function returns without action.
|
|
1832
|
+
:param bool force: If True, skips graceful shutdown (close/join) and immediately terminates. Default: False.
|
|
1833
|
+
:param bool verbose: If True, prints termination message with timestamp. Default: True.
|
|
1834
|
+
:param Optional[str] source: Optional identifier string for logging purposes (e.g., 'VideoProcessor'). Default: None.
|
|
1824
1835
|
|
|
1825
1836
|
:example:
|
|
1826
1837
|
>>> import multiprocessing
|
|
1827
1838
|
>>> pool = multiprocessing.Pool(4)
|
|
1828
|
-
>>> terminate_cpu_pool(pool)
|
|
1839
|
+
>>> terminate_cpu_pool(pool=pool, force=False, verbose=True, source='FeatureExtractor')
|
|
1829
1840
|
"""
|
|
1830
1841
|
if pool is None:
|
|
1831
1842
|
return
|
|
1832
|
-
check_valid_cpu_pool(value=pool, source=terminate_cpu_pool.__name__, raise_error=
|
|
1843
|
+
if not check_valid_cpu_pool(value=pool, source=terminate_cpu_pool.__name__, raise_error=False):
|
|
1844
|
+
return
|
|
1833
1845
|
try:
|
|
1846
|
+
core_cnt = pool._processes if hasattr(pool, '_processes') else None
|
|
1834
1847
|
if not force:
|
|
1835
1848
|
pool.close()
|
|
1836
1849
|
pool.join()
|
|
1837
1850
|
pool.terminate()
|
|
1851
|
+
if verbose: print(f'[{get_current_time()}] {"" if source is None else f"{core_cnt} core"} SimBA CPU pool {"" if source is None else source} terminated.')
|
|
1838
1852
|
except (ValueError, AssertionError, AttributeError):
|
|
1839
1853
|
pass
|
|
1840
1854
|
gc.collect()
|
|
1841
1855
|
|
|
1842
1856
|
|
|
1857
|
+
|
|
1858
|
+
def get_cpu_pool(core_cnt: int = -1,
|
|
1859
|
+
maxtasksperchild: int = Defaults.MAXIMUM_MAX_TASK_PER_CHILD.value,
|
|
1860
|
+
context: Literal['fork', 'spawn', 'forkserver'] = None,
|
|
1861
|
+
verbose: bool = True,
|
|
1862
|
+
source: Optional[str] = None) -> multiprocessing.Pool:
|
|
1863
|
+
"""
|
|
1864
|
+
Creates and returns a multiprocessing.Pool instance with platform-appropriate defaults and validation.
|
|
1865
|
+
|
|
1866
|
+
:param int core_cnt: Number of worker processes. -1 uses all available cores. Default: -1.
|
|
1867
|
+
:param int maxtasksperchild: Maximum number of tasks a worker process can complete before being replaced. Default: From Defaults.MAXIMUM_MAX_TASK_PER_CHILD.
|
|
1868
|
+
:param Optional[Literal['fork', 'spawn', 'forkserver']] context: Multiprocessing start method. None uses platform default. Default: None.
|
|
1869
|
+
:param bool verbose: If True, prints pool creation message with timestamp. Default: True.
|
|
1870
|
+
:param Optional[str] source: Optional identifier string for logging purposes (e.g., 'VideoProcessor'). Default: None.
|
|
1871
|
+
:return: Configured multiprocessing.Pool instance.
|
|
1872
|
+
:rtype: multiprocessing.Pool
|
|
1873
|
+
|
|
1874
|
+
:example:
|
|
1875
|
+
>>> pool = get_cpu_pool(core_cnt=4, source='FeatureExtractor')
|
|
1876
|
+
>>> pool = get_cpu_pool(core_cnt=-1, context='spawn', verbose=True)
|
|
1877
|
+
>>> pool = get_cpu_pool(core_cnt=8, maxtasksperchild=100, source='VideoProcessor')
|
|
1878
|
+
"""
|
|
1879
|
+
|
|
1880
|
+
check_int(name=f'{get_cpu_pool.__name__} core_cnt', min_value=-1, unaccepted_vals=[0], value=core_cnt, raise_error=True)
|
|
1881
|
+
check_int(name=f'{get_cpu_pool.__name__} maxtasksperchild', min_value=1, value=maxtasksperchild, raise_error=True)
|
|
1882
|
+
check_valid_boolean(value=verbose, source=f'{get_cpu_pool.__name__} verbose', raise_error=True)
|
|
1883
|
+
if source is not None: check_str(name=f'{get_cpu_pool.__name__} source', value=source, raise_error=True, allow_blank=True)
|
|
1884
|
+
current_process = multiprocessing.current_process()
|
|
1885
|
+
if current_process.name != 'MainProcess': core_cnt = 1
|
|
1886
|
+
core_cnt = find_core_cnt()[0] if core_cnt == -1 or core_cnt > find_core_cnt()[0] else core_cnt
|
|
1887
|
+
if verbose: print(f'[{get_current_time()}] {core_cnt} core SimBA CPU pool {"" if source is None else source} started.')
|
|
1888
|
+
if context is not None:
|
|
1889
|
+
check_str(name=f'{get_cpu_pool.__name__} context', value=context, options=('fork', 'spawn', 'forkserver'), raise_error=True)
|
|
1890
|
+
else:
|
|
1891
|
+
existing_method = multiprocessing.get_start_method(allow_none=True)
|
|
1892
|
+
if existing_method is not None:
|
|
1893
|
+
context = existing_method
|
|
1894
|
+
else:
|
|
1895
|
+
system = platform.system()
|
|
1896
|
+
if system == OS.WINDOWS.value: context = OS.SPAWN.value
|
|
1897
|
+
elif system == OS.MAC.value: context = OS.SPAWN.value
|
|
1898
|
+
else: context = OS.FORK.value
|
|
1899
|
+
|
|
1900
|
+
if context is not None:
|
|
1901
|
+
try:
|
|
1902
|
+
ctx = multiprocessing.get_context(context)
|
|
1903
|
+
except ValueError:
|
|
1904
|
+
system = platform.system()
|
|
1905
|
+
if system == OS.WINDOWS.value: fallback_context = OS.SPAWN.value
|
|
1906
|
+
elif system == OS.MAC.value: fallback_context = OS.SPAWN.value
|
|
1907
|
+
else: fallback_context = OS.FORK.value
|
|
1908
|
+
try:
|
|
1909
|
+
ctx = multiprocessing.get_context(fallback_context)
|
|
1910
|
+
except ValueError:
|
|
1911
|
+
pool = multiprocessing.Pool(processes=core_cnt, maxtasksperchild=maxtasksperchild)
|
|
1912
|
+
return pool
|
|
1913
|
+
pool = ctx.Pool(processes=core_cnt, maxtasksperchild=maxtasksperchild)
|
|
1914
|
+
else:
|
|
1915
|
+
pool = multiprocessing.Pool(processes=core_cnt, maxtasksperchild=maxtasksperchild)
|
|
1916
|
+
return pool
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
#get_cpu_pool()
|
|
1843
1920
|
# run_user_defined_feature_extraction_class(config_path='/Users/simon/Desktop/envs/troubleshooting/circular_features_zebrafish/project_folder/project_config.ini', file_path='/Users/simon/Desktop/fish_feature_extractor_2023_version_5.py')
|
|
1844
1921
|
|
|
1845
1922
|
|
simba/utils/enums.py
CHANGED
|
@@ -127,6 +127,7 @@ class OS(Enum):
|
|
|
127
127
|
LINUX = "Linux"
|
|
128
128
|
MAC = "Darwin"
|
|
129
129
|
SPAWN = 'spawn'
|
|
130
|
+
FORK = 'fork'
|
|
130
131
|
PYTHON_VER = str(f"{sys.version_info.major}.{sys.version_info.minor}")
|
|
131
132
|
try:
|
|
132
133
|
SIMBA_VERSION = pkg_resources.get_distribution("simba-uw-tf-dev").version
|
simba/utils/printing.py
CHANGED
|
@@ -9,6 +9,7 @@ except:
|
|
|
9
9
|
import logging
|
|
10
10
|
import time
|
|
11
11
|
from typing import Optional
|
|
12
|
+
from datetime import datetime
|
|
12
13
|
|
|
13
14
|
from simba.utils.enums import Defaults, TagNames
|
|
14
15
|
|
|
@@ -25,9 +26,9 @@ def stdout_success(msg: str, source: Optional[str] = "", elapsed_time: Optional[
|
|
|
25
26
|
|
|
26
27
|
log_event(logger_name=f"{source}.{stdout_success.__name__}", log_type=TagNames.COMPLETE.value, msg=msg)
|
|
27
28
|
if elapsed_time:
|
|
28
|
-
print(f"SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.COMPLETE.value}")
|
|
29
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.COMPLETE.value}")
|
|
29
30
|
else:
|
|
30
|
-
print(f"SIMBA COMPLETE: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.COMPLETE.value}")
|
|
31
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA COMPLETE: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.COMPLETE.value}")
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
def stdout_warning(msg: str, elapsed_time: Optional[str] = None) -> None:
|
|
@@ -41,9 +42,9 @@ def stdout_warning(msg: str, elapsed_time: Optional[str] = None) -> None:
|
|
|
41
42
|
"""
|
|
42
43
|
|
|
43
44
|
if elapsed_time:
|
|
44
|
-
print(f"SIMBA WARNING: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.WARNING.value}")
|
|
45
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA WARNING: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.WARNING.value}")
|
|
45
46
|
else:
|
|
46
|
-
print(f"SIMBA WARNING: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.WARNING.value}")
|
|
47
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA WARNING: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.WARNING.value}")
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
def stdout_trash(msg: str, source: Optional[str] = "", elapsed_time: Optional[str] = None) -> None:
|
|
@@ -58,9 +59,9 @@ def stdout_trash(msg: str, source: Optional[str] = "", elapsed_time: Optional[st
|
|
|
58
59
|
|
|
59
60
|
log_event(logger_name=f"{source}.{stdout_trash.__name__}", log_type=TagNames.TRASH.value, msg=msg)
|
|
60
61
|
if elapsed_time:
|
|
61
|
-
print(f"SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.TRASH.value}")
|
|
62
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.TRASH.value}")
|
|
62
63
|
else:
|
|
63
|
-
print(f"SIMBA COMPLETE: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.TRASH.value}")
|
|
64
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA COMPLETE: {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.TRASH.value}")
|
|
64
65
|
|
|
65
66
|
|
|
66
67
|
def stdout_information(msg: str, source: Optional[str] = "", elapsed_time: Optional[str] = None) -> None:
|
|
@@ -75,9 +76,9 @@ def stdout_information(msg: str, source: Optional[str] = "", elapsed_time: Optio
|
|
|
75
76
|
|
|
76
77
|
log_event(logger_name=f"{source}.{stdout_trash.__name__}", log_type=TagNames.INFORMATION.value, msg=msg)
|
|
77
78
|
if elapsed_time:
|
|
78
|
-
print(f"SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.INFORMATION.value}")
|
|
79
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] SIMBA COMPLETE: {msg} (elapsed time: {elapsed_time}s) {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.INFORMATION.value}")
|
|
79
80
|
else:
|
|
80
|
-
print(f"{msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.INFORMATION.value}")
|
|
81
|
+
print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg} {Defaults.STR_SPLIT_DELIMITER.value}{TagNames.INFORMATION.value}")
|
|
81
82
|
|
|
82
83
|
|
|
83
84
|
class SimbaTimer(object):
|