simba-uw-tf-dev 4.6.3__py3-none-any.whl → 4.6.6__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.
Files changed (41) hide show
  1. simba/assets/lookups/tooptips.json +6 -1
  2. simba/data_processors/cuda/geometry.py +45 -27
  3. simba/data_processors/cuda/image.py +1620 -1600
  4. simba/data_processors/cuda/statistics.py +17 -9
  5. simba/data_processors/egocentric_aligner.py +24 -6
  6. simba/data_processors/kleinberg_calculator.py +61 -29
  7. simba/feature_extractors/feature_subsets.py +12 -5
  8. simba/feature_extractors/straub_tail_analyzer.py +0 -2
  9. simba/mixins/statistics_mixin.py +9 -2
  10. simba/plotting/gantt_creator_mp.py +7 -5
  11. simba/plotting/pose_plotter_mp.py +7 -3
  12. simba/plotting/roi_plotter_mp.py +4 -3
  13. simba/plotting/yolo_pose_track_visualizer.py +3 -2
  14. simba/plotting/yolo_pose_visualizer.py +5 -4
  15. simba/sandbox/analyze_runtimes.py +30 -0
  16. simba/sandbox/cuda/egocentric_rotator.py +374 -374
  17. simba/sandbox/proboscis_to_tip.py +28 -0
  18. simba/sandbox/test_directionality.py +47 -0
  19. simba/sandbox/test_nonstatic_directionality.py +27 -0
  20. simba/sandbox/test_pycharm_cuda.py +51 -0
  21. simba/sandbox/test_simba_install.py +41 -0
  22. simba/sandbox/test_static_directionality.py +26 -0
  23. simba/sandbox/test_static_directionality_2d.py +26 -0
  24. simba/sandbox/verify_env.py +42 -0
  25. simba/ui/pop_ups/fsttc_pop_up.py +27 -25
  26. simba/ui/pop_ups/kleinberg_pop_up.py +39 -40
  27. simba/ui/tkinter_functions.py +3 -0
  28. simba/utils/data.py +0 -1
  29. simba/utils/errors.py +441 -440
  30. simba/utils/lookups.py +1203 -1203
  31. simba/utils/printing.py +124 -125
  32. simba/utils/read_write.py +43 -14
  33. simba/video_processors/egocentric_video_rotator.py +41 -36
  34. simba/video_processors/video_processing.py +5247 -5233
  35. simba/video_processors/videos_to_frames.py +41 -31
  36. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/METADATA +2 -2
  37. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/RECORD +41 -32
  38. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/LICENSE +0 -0
  39. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/WHEEL +0 -0
  40. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/entry_points.txt +0 -0
  41. {simba_uw_tf_dev-4.6.3.dist-info → simba_uw_tf_dev-4.6.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,28 @@
1
+ import os
2
+ from simba.mixins.feature_extraction_mixin import FeatureExtractionMixin
3
+ from simba.mixins.config_reader import ConfigReader
4
+ from simba.utils.read_write import read_df, get_fn_ext, read_video_info, write_df
5
+
6
+ CONFIG_PATH = r"C:\troubleshooting\srami0619\project_folder\project_config.ini"
7
+ BASE = 'prob_base'
8
+ TIP = 'prob_tip'
9
+
10
+
11
+ config = ConfigReader(config_path=CONFIG_PATH, read_video_info=True, create_logger=False)
12
+ animal_cnt = config.animal_cnt
13
+ for file_cnt, file_path in enumerate(config.outlier_corrected_paths):
14
+ file_name = get_fn_ext(file_path)[1]
15
+ _, px_per_mm, fps = read_video_info(video_name=file_name, video_info_df=config.video_info_df)
16
+ data_df = read_df(file_path=file_path)
17
+ save_path = os.path.join(config.features_dir, f'{file_name}.csv')
18
+ for animal_id in range(1, animal_cnt+1):
19
+ print(f'Analysing file {file_name}, animal {animal_id} ({file_cnt + 1}/{len(config.outlier_corrected_paths)})')
20
+ base_cols = [f'{BASE}_{animal_id}_x', f'{BASE}_{animal_id}_y']
21
+ tip_cols = [f'{TIP}_{animal_id}_x', f'{TIP}_{animal_id}_y']
22
+ prob_data, tip_data = data_df[base_cols], data_df[tip_cols]
23
+ data_df[f'animal_{animal_id}_base_tip_distance'] = FeatureExtractionMixin().keypoint_distances(a=prob_data.values, b=tip_data.values, px_per_mm=px_per_mm, in_centimeters=False)
24
+ write_df(df=data_df, file_type='csv', save_path=save_path, verbose=True)
25
+
26
+
27
+
28
+
@@ -0,0 +1,47 @@
1
+ """Test directionality_to_nonstatic_target function"""
2
+ import sys
3
+ import numpy as np
4
+
5
+ print(f"Python: {sys.executable}")
6
+ print("="*60)
7
+
8
+ try:
9
+ from simba.data_processors.cuda.geometry import directionality_to_nonstatic_target
10
+ print("✓ Function imported successfully")
11
+ except Exception as e:
12
+ print(f"✗ Error importing function: {e}")
13
+ import traceback
14
+ traceback.print_exc()
15
+ sys.exit(1)
16
+
17
+ # Create test data
18
+ print("\nCreating test data...")
19
+ left_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
20
+ right_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
21
+ nose = np.random.randint(0, 500, (10, 2)).astype(np.int32)
22
+ target = np.random.randint(0, 500, (10, 2)).astype(np.int32)
23
+
24
+ print(f"left_ear shape: {left_ear.shape}, dtype: {left_ear.dtype}")
25
+ print(f"right_ear shape: {right_ear.shape}, dtype: {right_ear.dtype}")
26
+ print(f"nose shape: {nose.shape}, dtype: {nose.dtype}")
27
+ print(f"target shape: {target.shape}, dtype: {target.dtype}")
28
+
29
+ # Test the function
30
+ print("\nTesting directionality_to_nonstatic_target...")
31
+ try:
32
+ result = directionality_to_nonstatic_target(
33
+ left_ear=left_ear,
34
+ right_ear=right_ear,
35
+ nose=nose,
36
+ target=target
37
+ )
38
+ print(f"✓ SUCCESS! Result shape: {result.shape}")
39
+ print(f"Result: {result}")
40
+ except Exception as e:
41
+ print(f"✗ Error running function: {e}")
42
+ import traceback
43
+ traceback.print_exc()
44
+ sys.exit(1)
45
+
46
+ print("\n" + "="*60)
47
+ print("Test passed!")
@@ -0,0 +1,27 @@
1
+ """Test directionality_to_nonstatic_target with int64"""
2
+ import numpy as np
3
+ from simba.data_processors.cuda.geometry import directionality_to_nonstatic_target
4
+
5
+ print("Testing directionality_to_nonstatic_target with int64...")
6
+
7
+ left_ear = np.random.randint(0, 500, (100, 2)).astype(np.int64)
8
+ right_ear = np.random.randint(0, 500, (100, 2)).astype(np.int64)
9
+ nose = np.random.randint(0, 500, (100, 2)).astype(np.int64)
10
+ target = np.random.randint(0, 500, (100, 2)).astype(np.int64)
11
+
12
+ print(f"Arrays shape: {left_ear.shape}, dtype: {left_ear.dtype}")
13
+
14
+ try:
15
+ result = directionality_to_nonstatic_target(
16
+ left_ear=left_ear,
17
+ right_ear=right_ear,
18
+ nose=nose,
19
+ target=target,
20
+ verbose=True
21
+ )
22
+ print(f"✓ SUCCESS! Result shape: {result.shape}, dtype: {result.dtype}")
23
+ print(f"First 5 results:\n{result[:5]}")
24
+ except Exception as e:
25
+ print(f"✗ Error: {e}")
26
+ import traceback
27
+ traceback.print_exc()
@@ -0,0 +1,51 @@
1
+ """Test script to verify PyCharm CUDA environment setup"""
2
+ import sys
3
+ print(f"Python version: {sys.version}")
4
+ print(f"Python path: {sys.executable}")
5
+
6
+ try:
7
+ from numba import cuda
8
+ print(f"\nNumba CUDA available: {cuda.is_available()}")
9
+ if cuda.is_available():
10
+ print(f"CUDA devices: {len(cuda.gpus)}")
11
+ except Exception as e:
12
+ print(f"\nError importing numba.cuda: {e}")
13
+
14
+ try:
15
+ import cupy as cp
16
+ print(f"CuPy version: {cp.__version__}")
17
+ # Test CuPy
18
+ x = cp.array([1, 2, 3, 4, 5])
19
+ print(f"CuPy test array: {x.get()}")
20
+ except Exception as e:
21
+ print(f"Error importing cupy: {e}")
22
+
23
+ try:
24
+ import numpy as np
25
+ print(f"NumPy version: {np.__version__}")
26
+ except Exception as e:
27
+ print(f"Error importing numpy: {e}")
28
+
29
+ try:
30
+ import cv2
31
+ print(f"OpenCV version: {cv2.__version__}")
32
+ except Exception as e:
33
+ print(f"Error importing cv2: {e}")
34
+
35
+ # Test SimBA CUDA imports
36
+ try:
37
+ from simba.data_processors.cuda.geometry import is_inside_rectangle
38
+ print("\n✓ Successfully imported simba.data_processors.cuda.geometry")
39
+
40
+ # Quick test
41
+ test_points = np.array([[150, 150], [300, 300], [50, 50]], dtype=np.int32)
42
+ test_rect = np.array([[100, 100], [400, 400]], dtype=np.int32)
43
+ result = is_inside_rectangle(x=test_points, y=test_rect)
44
+ print(f"✓ is_inside_rectangle test passed: {result}")
45
+ except Exception as e:
46
+ print(f"\n✗ Error importing SimBA CUDA functions: {e}")
47
+ import traceback
48
+ traceback.print_exc()
49
+
50
+ print("\n" + "="*50)
51
+ print("Environment check complete!")
@@ -0,0 +1,41 @@
1
+ """Test SimBA installation in conda environment"""
2
+ import sys
3
+ print(f"Python: {sys.executable}")
4
+
5
+ try:
6
+ import simba
7
+ print("✓ SimBA imported successfully!")
8
+ except Exception as e:
9
+ print(f"✗ Error importing SimBA: {e}")
10
+ import traceback
11
+ traceback.print_exc()
12
+ sys.exit(1)
13
+
14
+ try:
15
+ from simba.data_processors.cuda.geometry import is_inside_rectangle
16
+ print("✓ CUDA geometry functions imported!")
17
+ except Exception as e:
18
+ print(f"✗ Error importing CUDA functions: {e}")
19
+ import traceback
20
+ traceback.print_exc()
21
+ sys.exit(1)
22
+
23
+ try:
24
+ import cupy as cp
25
+ import numpy as np
26
+ print(f"✓ CuPy {cp.__version__} available")
27
+
28
+ # Quick test
29
+ test_points = np.array([[150, 150], [300, 300], [50, 50]], dtype=np.int32)
30
+ test_rect = np.array([[100, 100], [400, 400]], dtype=np.int32)
31
+ result = is_inside_rectangle(x=test_points, y=test_rect)
32
+ print(f"✓ CUDA function test passed: {result}")
33
+ except Exception as e:
34
+ print(f"✗ Error testing CUDA: {e}")
35
+ import traceback
36
+ traceback.print_exc()
37
+ sys.exit(1)
38
+
39
+ print("\n" + "="*50)
40
+ print("All tests passed! SimBA is ready to use.")
41
+ print("="*50)
@@ -0,0 +1,26 @@
1
+ """Test directionality_to_static_targets function"""
2
+ import numpy as np
3
+ from simba.data_processors.cuda.geometry import directionality_to_static_targets
4
+
5
+ print("Testing directionality_to_static_targets...")
6
+
7
+ left_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
8
+ right_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
9
+ nose = np.random.randint(0, 500, (10, 2)).astype(np.int32)
10
+ target = np.array([250, 250], dtype=np.int32)
11
+
12
+ print(f"target shape: {target.shape}, dtype: {target.dtype}")
13
+
14
+ try:
15
+ result = directionality_to_static_targets(
16
+ left_ear=left_ear,
17
+ right_ear=right_ear,
18
+ nose=nose,
19
+ target=target
20
+ )
21
+ print(f"✓ SUCCESS! Result shape: {result.shape}")
22
+ print(f"Result:\n{result}")
23
+ except Exception as e:
24
+ print(f"✗ Error: {e}")
25
+ import traceback
26
+ traceback.print_exc()
@@ -0,0 +1,26 @@
1
+ """Test directionality_to_static_targets with correct 1D target"""
2
+ import numpy as np
3
+ from simba.data_processors.cuda.geometry import directionality_to_static_targets
4
+
5
+ print("Testing directionality_to_static_targets with 1D target (correct)...")
6
+
7
+ left_ear = np.random.randint(0, 500, (100, 2)).astype(np.int32)
8
+ right_ear = np.random.randint(0, 500, (100, 2)).astype(np.int32)
9
+ nose = np.random.randint(0, 500, (100, 2)).astype(np.int32)
10
+ target = np.array([250, 250], dtype=np.int32) # 1D array for static target
11
+
12
+ print(f"target shape: {target.shape}, dtype: {target.dtype}")
13
+
14
+ try:
15
+ result = directionality_to_static_targets(
16
+ left_ear=left_ear,
17
+ right_ear=right_ear,
18
+ nose=nose,
19
+ target=target
20
+ )
21
+ print(f"✓ SUCCESS! Result shape: {result.shape}")
22
+ print(f"First 5 results:\n{result[:5]}")
23
+ except Exception as e:
24
+ print(f"✗ Error: {e}")
25
+ import traceback
26
+ traceback.print_exc()
@@ -0,0 +1,42 @@
1
+ """Verify CUDA environment is properly configured"""
2
+ from numba import cuda
3
+ import cupy as cp
4
+ import numba
5
+
6
+ print("="*60)
7
+ print("CUDA Environment Verification")
8
+ print("="*60)
9
+ print(f"Numba version: {numba.__version__}")
10
+ print(f"CuPy version: {cp.__version__}")
11
+ print(f"CUDA available: {cuda.is_available()}")
12
+ if cuda.is_available():
13
+ print(f"CUDA devices: {len(cuda.gpus)}")
14
+ for i, gpu in enumerate(cuda.gpus):
15
+ print(f" GPU {i}: {gpu}")
16
+
17
+ # Test the function
18
+ print("\n" + "="*60)
19
+ print("Testing directionality_to_nonstatic_target...")
20
+ try:
21
+ from simba.data_processors.cuda.geometry import directionality_to_nonstatic_target
22
+ import numpy as np
23
+
24
+ left_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
25
+ right_ear = np.random.randint(0, 500, (10, 2)).astype(np.int32)
26
+ nose = np.random.randint(0, 500, (10, 2)).astype(np.int32)
27
+ target = np.random.randint(0, 500, (10, 2)).astype(np.int32)
28
+
29
+ result = directionality_to_nonstatic_target(
30
+ left_ear=left_ear,
31
+ right_ear=right_ear,
32
+ nose=nose,
33
+ target=target
34
+ )
35
+ print(f"✓ Function works! Result shape: {result.shape}")
36
+ except Exception as e:
37
+ print(f"✗ Error: {e}")
38
+ import traceback
39
+ traceback.print_exc()
40
+
41
+ print("\n" + "="*60)
42
+ print("Environment is ready!")
@@ -7,25 +7,29 @@ from typing import Union
7
7
  from simba.data_processors.fsttc_calculator import FSTTCCalculator
8
8
  from simba.mixins.config_reader import ConfigReader
9
9
  from simba.mixins.pop_up_mixin import PopUpMixin
10
- from simba.ui.tkinter_functions import CreateLabelFrameWithIcon, Entry_Box
10
+ from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, Entry_Box,
11
+ SimbaCheckbox)
11
12
  from simba.utils.checks import check_int
12
- from simba.utils.enums import Defaults, Formats, Keys, Links
13
+ from simba.utils.enums import Formats, Keys, Links
13
14
  from simba.utils.errors import CountError
14
15
 
15
16
 
16
17
  class FSTTCPopUp(PopUpMixin, ConfigReader):
17
- def __init__(self, config_path: Union[str, os.PathLike]):
18
+ def __init__(self,
19
+ config_path: Union[str, os.PathLike]):
18
20
 
19
- PopUpMixin.__init__(self, title="FORWARD SPIKE TIME TILING COEFFICIENTS", icon='dependency')
20
21
  ConfigReader.__init__(self, config_path=config_path, read_video_info=False)
22
+ if len(self.clf_names) < 2:
23
+ raise CountError(msg=f'Cannot compute FSTTC: Needs project with at least 2 classified behaviors, got {len(self.clf_names)}', source=self.__class__.__name__)
24
+
25
+ PopUpMixin.__init__(self, title="FORWARD SPIKE TIME TILING COEFFICIENTS", icon='dependency')
21
26
  settings_frm = CreateLabelFrameWithIcon( parent=self.main_frm, header="SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.FSTTC.value,)
22
- self.time_delta_eb = Entry_Box(settings_frm, "TIME-DELTA", "10", validation="numeric")
23
- self.graph_cb_var = BooleanVar(value=False)
24
- graph_cb = Checkbutton(settings_frm, font=Formats.FONT_REGULAR.value, text="CREATE GRAPH", variable=self.graph_cb_var)
25
- self.join_bouts_within_delta_var = BooleanVar(value=False)
26
- join_bouts_within_delta_cb = Checkbutton(settings_frm, text="JOIN BOUTS WITHIN TIME-DELTA", font=Formats.FONT_REGULAR.value, variable=self.join_bouts_within_delta_var,)
27
- self.time_delta_at_onset_var = BooleanVar(value=False)
28
- time_delta_at_onset_cb = Checkbutton( settings_frm, text="TIME-DELTA AT BOUT START", font=Formats.FONT_REGULAR.value, variable=self.time_delta_at_onset_var)
27
+ self.time_delta_eb = Entry_Box(parent=settings_frm, fileDescription="TIME-DELTA", labelwidth=25, validation="numeric", entry_box_width=20, img='timer_2')
28
+
29
+ graph_cb, self.graph_cb_var = SimbaCheckbox(parent=settings_frm, font=Formats.FONT_REGULAR.value, val=False, txt_img='line_chart_blue', txt="CREATE GRAPH")
30
+ join_bouts_within_delta_cb, self.join_bouts_within_delta_var = SimbaCheckbox(parent=settings_frm, font=Formats.FONT_REGULAR.value, val=False, txt_img='join_purple', txt="JOIN BOUTS WITHIN TIME-DELTA")
31
+ time_delta_at_onset_cb, self.time_delta_at_onset_var = SimbaCheckbox(parent=settings_frm, font=Formats.FONT_REGULAR.value, val=False, txt_img='play', txt="TIME-DELTA AT BOUT START")
32
+
29
33
  settings_frm.grid(row=0, column=0, sticky=NW)
30
34
  self.time_delta_eb.grid(row=0, column=0, sticky="NW")
31
35
  join_bouts_within_delta_cb.grid(row=1, column=0, sticky="NW")
@@ -43,22 +47,20 @@ class FSTTCPopUp(PopUpMixin, ConfigReader):
43
47
  targets.append(behaviour)
44
48
 
45
49
  if len(targets) < 2:
46
- raise CountError(
47
- msg="FORWARD SPIKE TIME TILING COEFFICIENTS REQUIRE 2 OR MORE BEHAVIORS.",
48
- source=self.__class__.__name__,
49
- )
50
-
51
- fsttc_calculator = FSTTCCalculator(
52
- config_path=self.config_path,
53
- time_window=self.time_delta_eb.entry_get,
54
- join_bouts_within_delta=self.join_bouts_within_delta_var.get(),
55
- time_delta_at_onset=self.time_delta_at_onset_var.get(),
56
- behavior_lst=targets,
57
- create_graphs=self.graph_cb_var.get(),
58
- )
50
+ raise CountError(msg="FORWARD SPIKE TIME TILING COEFFICIENTS REQUIRE 2 OR MORE BEHAVIORS.", source=self.__class__.__name__,)
51
+
52
+ fsttc_calculator = FSTTCCalculator(config_path=self.config_path,
53
+ time_window=self.time_delta_eb.entry_get,
54
+ join_bouts_within_delta=self.join_bouts_within_delta_var.get(),
55
+ time_delta_at_onset=self.time_delta_at_onset_var.get(),
56
+ behavior_lst=targets,
57
+ create_graphs=self.graph_cb_var.get())
59
58
  fsttc_calculator.run()
60
59
 
61
60
 
62
- #ExtractAnnotationFramesPopUp(config_path=)
61
+
63
62
 
64
63
  #_ = FSTTCPopUp(config_path=r"C:\troubleshooting\multi_animal_dlc_two_c57\project_folder\project_config.ini")
64
+
65
+ #_ = FSTTCPopUp(config_path=r"C:\troubleshooting\mitra\project_folder\project_config.ini")
66
+
@@ -8,12 +8,13 @@ from simba.data_processors.kleinberg_calculator import KleinbergCalculator
8
8
  from simba.mixins.config_reader import ConfigReader
9
9
  from simba.mixins.pop_up_mixin import PopUpMixin
10
10
  from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, Entry_Box,
11
- SimbaButton, SimBADropDown)
11
+ SimbaButton, SimBADropDown, SimBALabel)
12
12
  from simba.utils.checks import check_float, check_int
13
13
  from simba.utils.enums import Formats, Keys, Links
14
14
  from simba.utils.errors import NoChoosenClassifierError, NoDataError
15
- from simba.utils.read_write import str_2_bool
15
+ from simba.utils.read_write import get_current_time, str_2_bool
16
16
 
17
+ INSTRUCTIONS_TXT = 'Results in the project_folder/csv/machine_results folder are overwritten.\n If saving the originals, the original un-smoothened data is saved in a subdirectory of \nthe project_folder/csv/machine_results folder'
17
18
 
18
19
  class KleinbergPopUp(PopUpMixin, ConfigReader):
19
20
  def __init__(self,
@@ -24,61 +25,59 @@ class KleinbergPopUp(PopUpMixin, ConfigReader):
24
25
  raise NoDataError(msg=f'Cannot perform Kleinberg smoothing: No data files found in {self.machine_results_dir} directory', source=self.__class__.__name__)
25
26
  PopUpMixin.__init__(self, title="APPLY KLEINBERG BEHAVIOR CLASSIFICATION SMOOTHING", icon='smooth')
26
27
  kleinberg_settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="KLEINBERG SETTINGS", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.KLEINBERG.value)
27
- self.k_sigma = Entry_Box(kleinberg_settings_frm, fileDescription="SIGMA", img='sigma', value='2', justify='center', labelwidth=35, entry_box_width=35)
28
- self.k_gamma = Entry_Box(kleinberg_settings_frm, fileDescription="GAMMA", img='gamma', value='0.3', justify='center', labelwidth=35, entry_box_width=35)
29
- self.k_hierarchy = Entry_Box(kleinberg_settings_frm, fileDescription="HIERARCHY", value=1, img='hierarchy_2', justify='center', labelwidth=35, entry_box_width=35)
30
- self.h_search_dropdown = SimBADropDown(parent=kleinberg_settings_frm, dropdown_options=['TRUE', 'FALSE'], label="HIERACHICAL SEARCH", value='FALSE', img='hierarchy', label_width=35, dropdown_width=35)
28
+ self.k_sigma = Entry_Box(kleinberg_settings_frm, fileDescription="SIGMA", img='sigma', value='2', justify='center', labelwidth=35, entry_box_width=35, tooltip_key='KLEINBERG_SIGMA')
29
+ self.k_gamma = Entry_Box(kleinberg_settings_frm, fileDescription="GAMMA", img='gamma', value='0.3', justify='center', labelwidth=35, entry_box_width=35, tooltip_key='KLEINBERG_GAMMA')
30
+ self.k_hierarchy = Entry_Box(kleinberg_settings_frm, fileDescription="HIERARCHY", value=1, img='hierarchy_2', justify='center', labelwidth=35, entry_box_width=35, validation='numeric', tooltip_key='KLEINBERG_HIERARCHY')
31
+ self.h_search_dropdown = SimBADropDown(parent=kleinberg_settings_frm, dropdown_options=['TRUE', 'FALSE'], label="HIERARCHICAL SEARCH", value='FALSE', img='hierarchy', label_width=35, dropdown_width=35, tooltip_key='KLEINBERG_HIERARCHY_SEARCH')
32
+ self.save_originals_dropdown = SimBADropDown(parent=kleinberg_settings_frm, dropdown_options=['TRUE', 'FALSE'], label="SAVE ORIGINAL DATA:", value='TRUE', img='save', label_width=35, dropdown_width=35, tooltip_key='KLEINBERG_SAVE_ORIGINALS')
33
+ self.instructions_lbl = SimBALabel(parent=kleinberg_settings_frm, txt=INSTRUCTIONS_TXT, justify='center', txt_clr='blue', font=Formats.FONT_REGULAR_ITALICS.value)
31
34
 
32
35
 
33
- kleinberg_table_frame = LabelFrame(self.main_frm, text="CHOOSE CLASSIFIER(S) FOR KLEINBERG SMOOTHING", font=Formats.FONT_HEADER.value)
36
+ kleinberg_table_frame = CreateLabelFrameWithIcon(parent=self.main_frm, header="CHOOSE CLASSIFIER(S) FOR KLEINBERG SMOOTHING", icon_name=Keys.DOCUMENTATION.value, icon_link=Links.KLEINBERG.value)
34
37
  clf_var_dict, clf_cb_dict = {}, {}
35
38
  for clf_cnt, clf in enumerate(self.clf_names):
36
39
  clf_var_dict[clf] = BooleanVar()
37
40
  clf_cb_dict[clf] = Checkbutton(kleinberg_table_frame, text=clf, font=Formats.FONT_REGULAR.value, variable=clf_var_dict[clf])
38
- clf_cb_dict[clf].grid(row=clf_cnt, sticky=NW)
41
+ clf_cb_dict[clf].grid(row=clf_cnt, column=0, sticky=NW)
39
42
 
40
43
  run_kleinberg_btn = SimbaButton(parent=self.main_frm, txt="APPLY KLEINBERG SMOOTHER", img='rocket', txt_clr="blue", font=Formats.FONT_REGULAR.value, cmd=self.run_kleinberg, cmd_kwargs={'behaviors_dict': lambda: clf_var_dict, 'hierarchical_search': lambda: str_2_bool(self.h_search_dropdown.get_value())})
41
- kleinberg_settings_frm.grid(row=0, sticky=W, padx=10)
42
- self.k_sigma.grid(row=0, sticky=W)
43
- self.k_gamma.grid(row=1, sticky=W)
44
- self.k_hierarchy.grid(row=2, sticky=W)
45
- self.h_search_dropdown.grid(row=3, column=0, sticky=W)
46
- kleinberg_table_frame.grid(row=1, pady=10, padx=10)
47
- run_kleinberg_btn.grid(row=2)
44
+ kleinberg_settings_frm.grid(row=0, sticky=W, pady=(15, 0))
45
+ self.instructions_lbl.grid(row=0, sticky=W)
46
+ self.k_sigma.grid(row=1, sticky=W)
47
+ self.k_gamma.grid(row=2, sticky=W)
48
+ self.k_hierarchy.grid(row=3, sticky=W)
49
+ self.h_search_dropdown.grid(row=4, column=0, sticky=W)
50
+ self.save_originals_dropdown.grid(row=5, column=0, sticky=W)
51
+ kleinberg_table_frame.grid(row=1, column=0, sticky=NW, pady=(15, 0))
52
+ run_kleinberg_btn.grid(row=2, column=0, sticky=NW, pady=(15, 0))
48
53
  self.main_frm.mainloop()
49
54
 
50
55
  def run_kleinberg(self, behaviors_dict: dict, hierarchical_search: bool):
51
56
  targets = []
52
57
  for behaviour, behavior_val in behaviors_dict.items():
53
- if behavior_val.get():
54
- targets.append(behaviour)
58
+ if behavior_val.get(): targets.append(behaviour)
55
59
 
56
60
  if len(targets) == 0:
57
61
  raise NoChoosenClassifierError(source=self.__class__.__name__)
58
62
 
59
- check_int(name="Hierarchy", value=self.k_hierarchy.entry_get)
60
- check_float(name="Sigma", value=self.k_sigma.entry_get)
61
- check_float(name="Gamma", value=self.k_gamma.entry_get)
62
-
63
- try:
64
- print(
65
- "Applying kleinberg hyperparameter Setting: Sigma: {}, Gamma: {}, Hierarchy: {}".format(
66
- str(self.k_sigma.entry_get),
67
- str(self.k_gamma.entry_get),
68
- str(self.k_hierarchy.entry_get),
69
- )
70
- )
71
- except:
72
- print("Please insert accurate values for all hyperparameters.")
73
-
74
- kleinberg_analyzer = KleinbergCalculator(
75
- config_path=self.config_path,
76
- classifier_names=targets,
77
- sigma=self.k_sigma.entry_get,
78
- gamma=self.k_gamma.entry_get,
79
- hierarchy=self.k_hierarchy.entry_get,
80
- hierarchical_search=hierarchical_search,
81
- )
63
+ k_hierarchy = self.k_hierarchy.entry_get
64
+ k_sigma = self.k_sigma.entry_get
65
+ k_gamma = self.k_gamma.entry_get
66
+ save_originals = str_2_bool(self.save_originals_dropdown.get_value())
67
+
68
+ check_int(name="Hierarchy", value=k_hierarchy, min_value=1, allow_negative=False, allow_zero=False, raise_error=True)
69
+ check_float(name="Sigma", value=k_sigma, allow_negative=False, allow_zero=False, raise_error=True)
70
+ check_float(name="Gamma", value=k_gamma, allow_negative=False, allow_zero=False, raise_error=True)
71
+
72
+ print(f"[{get_current_time()}] Applying kleinberg hyperparameter Setting: Sigma: {k_sigma}, Gamma: {k_gamma}, Hierarchy: {k_hierarchy}")
73
+
74
+ kleinberg_analyzer = KleinbergCalculator(config_path=self.config_path,
75
+ classifier_names=targets,
76
+ sigma=float(k_sigma),
77
+ gamma=float(k_gamma),
78
+ hierarchy=int(k_hierarchy),
79
+ hierarchical_search=hierarchical_search,
80
+ save_originals=save_originals)
82
81
  kleinberg_analyzer.run()
83
82
 
84
83
 
@@ -229,6 +229,7 @@ class Entry_Box(Frame):
229
229
  value: Optional[Any] = None,
230
230
  label_font: tuple = Formats.FONT_REGULAR.value,
231
231
  entry_font: tuple = Formats.FONT_REGULAR.value,
232
+ tooltip_key: Optional[str] = None,
232
233
  justify: Literal["left", "center", "right"] = 'left',
233
234
  cmd: Optional[Callable] = None,
234
235
  **kw):
@@ -249,6 +250,8 @@ class Entry_Box(Frame):
249
250
  self.filePath = StringVar()
250
251
  self.lblName = Label(self, text=fileDescription, width=labelwidth, anchor=W, font=label_font, bg=label_bg_clr)
251
252
  self.lblName.grid(row=0, column=1)
253
+ if tooltip_key in TOOLTIPS.keys():
254
+ CreateToolTip(widget=self.lblName, text=TOOLTIPS[tooltip_key])
252
255
  if not entry_box_width:
253
256
  self.entPath = Entry(self, textvariable=self.filePath, state=self.status, validate="key", validatecommand=self.validation_methods.get(validation, None), font=entry_font, justify=justify, bg=entry_box_clr)
254
257
  else:
simba/utils/data.py CHANGED
@@ -48,7 +48,6 @@ from simba.utils.errors import (BodypartColumnNotFoundError, CountError,
48
48
  InvalidFileTypeError, InvalidInputError,
49
49
  NoFilesFoundError, NoROIDataError,
50
50
  SimBAModuleNotFoundError)
51
- from simba.utils.lookups import get_current_time
52
51
  from simba.utils.printing import stdout_success, stdout_warning
53
52
  from simba.utils.read_write import (find_core_cnt, find_video_of_file,
54
53
  get_current_time, get_fn_ext,