simba-uw-tf-dev 4.6.2__py3-none-any.whl → 4.7.2__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 (96) hide show
  1. simba/assets/.recent_projects.txt +1 -0
  2. simba/assets/lookups/tooptips.json +6 -1
  3. simba/assets/lookups/yolo_schematics/yolo_mitra.csv +9 -0
  4. simba/data_processors/agg_clf_counter_mp.py +52 -53
  5. simba/data_processors/blob_location_computer.py +1 -1
  6. simba/data_processors/circling_detector.py +30 -13
  7. simba/data_processors/cuda/geometry.py +45 -27
  8. simba/data_processors/cuda/image.py +1648 -1598
  9. simba/data_processors/cuda/statistics.py +72 -26
  10. simba/data_processors/cuda/timeseries.py +1 -1
  11. simba/data_processors/cue_light_analyzer.py +5 -9
  12. simba/data_processors/egocentric_aligner.py +25 -7
  13. simba/data_processors/freezing_detector.py +55 -47
  14. simba/data_processors/kleinberg_calculator.py +61 -29
  15. simba/feature_extractors/feature_subsets.py +14 -7
  16. simba/feature_extractors/mitra_feature_extractor.py +2 -2
  17. simba/feature_extractors/straub_tail_analyzer.py +4 -6
  18. simba/labelling/standard_labeller.py +1 -1
  19. simba/mixins/config_reader.py +5 -2
  20. simba/mixins/geometry_mixin.py +22 -36
  21. simba/mixins/image_mixin.py +24 -28
  22. simba/mixins/plotting_mixin.py +28 -10
  23. simba/mixins/statistics_mixin.py +48 -11
  24. simba/mixins/timeseries_features_mixin.py +1 -1
  25. simba/mixins/train_model_mixin.py +68 -33
  26. simba/model/inference_batch.py +2 -2
  27. simba/model/yolo_seg_inference.py +3 -3
  28. simba/outlier_tools/skip_outlier_correction.py +1 -1
  29. simba/plotting/ROI_feature_visualizer_mp.py +3 -5
  30. simba/plotting/clf_validator_mp.py +4 -5
  31. simba/plotting/cue_light_visualizer.py +6 -7
  32. simba/plotting/directing_animals_visualizer_mp.py +2 -3
  33. simba/plotting/distance_plotter_mp.py +378 -378
  34. simba/plotting/gantt_creator.py +29 -10
  35. simba/plotting/gantt_creator_mp.py +96 -33
  36. simba/plotting/geometry_plotter.py +270 -272
  37. simba/plotting/heat_mapper_clf_mp.py +4 -6
  38. simba/plotting/heat_mapper_location_mp.py +2 -2
  39. simba/plotting/light_dark_box_plotter.py +2 -2
  40. simba/plotting/path_plotter_mp.py +26 -29
  41. simba/plotting/plot_clf_results_mp.py +455 -454
  42. simba/plotting/pose_plotter_mp.py +28 -29
  43. simba/plotting/probability_plot_creator_mp.py +288 -288
  44. simba/plotting/roi_plotter_mp.py +31 -31
  45. simba/plotting/single_run_model_validation_video_mp.py +427 -427
  46. simba/plotting/spontaneous_alternation_plotter.py +2 -3
  47. simba/plotting/yolo_pose_track_visualizer.py +32 -27
  48. simba/plotting/yolo_pose_visualizer.py +35 -36
  49. simba/plotting/yolo_seg_visualizer.py +2 -3
  50. simba/pose_importers/simba_blob_importer.py +3 -3
  51. simba/roi_tools/roi_aggregate_stats_mp.py +5 -4
  52. simba/roi_tools/roi_clf_calculator_mp.py +4 -4
  53. simba/sandbox/analyze_runtimes.py +30 -0
  54. simba/sandbox/cuda/egocentric_rotator.py +374 -374
  55. simba/sandbox/get_cpu_pool.py +5 -0
  56. simba/sandbox/proboscis_to_tip.py +28 -0
  57. simba/sandbox/test_directionality.py +47 -0
  58. simba/sandbox/test_nonstatic_directionality.py +27 -0
  59. simba/sandbox/test_pycharm_cuda.py +51 -0
  60. simba/sandbox/test_simba_install.py +41 -0
  61. simba/sandbox/test_static_directionality.py +26 -0
  62. simba/sandbox/test_static_directionality_2d.py +26 -0
  63. simba/sandbox/verify_env.py +42 -0
  64. simba/third_party_label_appenders/transform/coco_keypoints_to_yolo.py +3 -3
  65. simba/third_party_label_appenders/transform/coco_keypoints_to_yolo_bbox.py +2 -2
  66. simba/third_party_label_appenders/transform/simba_to_yolo.py +8 -5
  67. simba/ui/pop_ups/clf_plot_pop_up.py +2 -2
  68. simba/ui/pop_ups/fsttc_pop_up.py +27 -25
  69. simba/ui/pop_ups/gantt_pop_up.py +31 -6
  70. simba/ui/pop_ups/kleinberg_pop_up.py +39 -40
  71. simba/ui/pop_ups/run_machine_models_popup.py +21 -21
  72. simba/ui/pop_ups/simba_to_yolo_keypoints_popup.py +2 -2
  73. simba/ui/pop_ups/video_processing_pop_up.py +37 -29
  74. simba/ui/pop_ups/yolo_inference_popup.py +1 -1
  75. simba/ui/pop_ups/yolo_pose_train_popup.py +1 -1
  76. simba/ui/tkinter_functions.py +3 -0
  77. simba/utils/custom_feature_extractor.py +1 -1
  78. simba/utils/data.py +90 -14
  79. simba/utils/enums.py +1 -0
  80. simba/utils/errors.py +441 -440
  81. simba/utils/lookups.py +1203 -1203
  82. simba/utils/printing.py +124 -124
  83. simba/utils/read_write.py +3769 -3721
  84. simba/utils/yolo.py +10 -1
  85. simba/video_processors/blob_tracking_executor.py +2 -2
  86. simba/video_processors/clahe_ui.py +1 -1
  87. simba/video_processors/egocentric_video_rotator.py +44 -41
  88. simba/video_processors/multi_cropper.py +1 -1
  89. simba/video_processors/video_processing.py +75 -33
  90. simba/video_processors/videos_to_frames.py +43 -33
  91. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/METADATA +4 -3
  92. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/RECORD +96 -85
  93. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/LICENSE +0 -0
  94. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/WHEEL +0 -0
  95. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/entry_points.txt +0 -0
  96. {simba_uw_tf_dev-4.6.2.dist-info → simba_uw_tf_dev-4.7.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,5 @@
1
+ from simba.utils.data import get_cpu_pool, terminate_cpu_pool
2
+
3
+
4
+ pool = get_cpu_pool()
5
+ terminate_cpu_pool(pool=pool)
@@ -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!")
@@ -54,15 +54,15 @@ class COCOKeypoints2Yolo:
54
54
  :return: None
55
55
 
56
56
  :example:
57
- >>> runner = COCOKeypoints2Yolo(coco_path=r"D:\cvat_annotations\frames\coco_keypoints_1\s1\annotations\s1.json", img_dir=r"D:\cvat_annotations\frames\simon", save_dir=r"D:\cvat_annotations\frames\yolo_keypoints", clahe=True)
57
+ >>> runner = COCOKeypoints2Yolo(coco_path=r"D:/cvat_annotations/frames/coco_keypoints_1/s1/annotations/s1.json", img_dir=r"D:/cvat_annotations/frames/simon", save_dir=r"D:/cvat_annotations/frames/yolo_keypoints", clahe=True)
58
58
  >>> runner.run()
59
59
 
60
60
  :example II:
61
- >>> runner = COCOKeypoints2Yolo(coco_path=r"D:\cvat_annotations\frames\coco_keypoints_1\merged.json", img_dir=r"D:\cvat_annotations\frames", save_dir=r"D:\cvat_annotations\frames\yolo", clahe=False)
61
+ >>> runner = COCOKeypoints2Yolo(coco_path=r"D:/cvat_annotations/frames/coco_keypoints_1/merged.json", img_dir=r"D:/cvat_annotations/frames", save_dir=r"D:/cvat_annotations/frames/yolo", clahe=False)
62
62
  >>> runner.run()
63
63
 
64
64
  :example III:
65
- >>> runner = COCOKeypoints2Yolo(coco_path=r"E:\netholabs_videos\mosaics\subset\to_annotate\2d_mosaic_batch_1.json", img_dir=r"E:\netholabs_videos\mosaics\subset\to_annotate", save_dir=r"E:\netholabs_videos\mosaics\yolo_mdl", clahe=False)
65
+ >>> runner = COCOKeypoints2Yolo(coco_path=r"E:/netholabs_videos/mosaics/subset/to_annotate/2d_mosaic_batch_1.json", img_dir=r"E:/netholabs_videos/mosaics/subset/to_annotate", save_dir=r"E:/netholabs_videos/mosaics/yolo_mdl", clahe=False)
66
66
  >>> runner.run()
67
67
 
68
68
  :references:
@@ -58,11 +58,11 @@ class COCOKeypoints2YoloBbox:
58
58
  :return: None
59
59
 
60
60
  :example:
61
- >>> runner = COCOKeypoints2Yolo(coco_path=r"D:\cvat_annotations\frames\coco_keypoints_1\s1\annotations\s1.json", img_dir=r"D:\cvat_annotations\frames\simon", save_dir=r"D:\cvat_annotations\frames\yolo_keypoints", clahe=True)
61
+ >>> runner = COCOKeypoints2YoloBbox(coco_path=r"D:/cvat_annotations/frames/coco_keypoints_1/s1/annotations/s1.json", img_dir=r"D:/cvat_annotations/frames/simon", save_dir=r"D:/cvat_annotations/frames/yolo_keypoints", clahe=True)
62
62
  >>> runner.run()
63
63
 
64
64
  :example II:
65
- >>> runner = COCOKeypoints2Yolo(coco_path=r"D:\cvat_annotations\frames\coco_keypoints_1\merged.json", img_dir=r"D:\cvat_annotations\frames", save_dir=r"D:\cvat_annotations\frames\yolo", clahe=False)
65
+ >>> runner = COCOKeypoints2YoloBbox(coco_path=r"D:/cvat_annotations/frames/coco_keypoints_1/merged.json", img_dir=r"D:/cvat_annotations/frames", save_dir=r"D:/cvat_annotations/frames/yolo", clahe=False)
66
66
  >>> runner.run()
67
67
 
68
68
  :references:
@@ -117,12 +117,15 @@ class SimBA2Yolo:
117
117
  annotations, timer, body_part_headers = [], SimbaTimer(start=True), []
118
118
  for file_cnt, video_name in enumerate(self.data_w_video):
119
119
  data = read_df(file_path=self.data_paths[video_name], file_type=self.config.file_type)
120
+ data.columns = [x.lower() for x in list(data.columns)]
121
+ bp_header_names = [x.lower() for x in self.config.bp_headers]
120
122
  check_valid_dataframe(df=data, source=f'{self.__class__.__name__} {self.data_paths[video_name]}', valid_dtypes=Formats.NUMERIC_DTYPES.value)
121
123
  video_path = self.video_paths[video_name]
122
124
  check_video_and_data_frm_count_align(video=video_path, data=data, name=self.data_paths[video_name], raise_error=True)
123
125
  p_data = data[data.columns[list(data.columns.str.endswith('_p'))]]
124
126
  data = data.loc[:, ~data.columns.str.endswith('_p')].reset_index(drop=True)
125
127
  data = data.iloc[(p_data[(p_data > self.threshold).all(axis=1)].index)]
128
+ data = data[[x for x in bp_header_names if not x.endswith('_p')]]
126
129
  body_part_headers = data.columns
127
130
  data['video'], frm_cnt = video_name, len(data)
128
131
  if self.sample_size is None:
@@ -155,7 +158,7 @@ class SimBA2Yolo:
155
158
  if frm_idx in train_idx:
156
159
  img_save_path, lbl_save_path = os.path.join(self.img_train_dir, f'{file_name}.png'), os.path.join(self.lbl_train_dir, f'{file_name}.txt')
157
160
  else:
158
- img_save_path, lbl_save_path = os.path.join(self.img_train_dir, f'{file_name}.png'), os.path.join(self.lb_val_dir, f'{file_name}.txt')
161
+ img_save_path, lbl_save_path = os.path.join(self.img_val_dir, f'{file_name}.png'), os.path.join(self.lb_val_dir, f'{file_name}.txt')
159
162
  img = read_frm_of_video(video_path=vid_path, frame_index=frm_idx, greyscale=self.greyscale, clahe=self.clahe)
160
163
  img_h, img_w = img.shape[0], img.shape[1]
161
164
  keypoints_with_id = {}
@@ -181,8 +184,8 @@ class SimBA2Yolo:
181
184
  timer.stop_timer()
182
185
  stdout_success(msg=f'YOLO formated data saved in {self.save_dir} directory', source=self.__class__.__name__, elapsed_time=timer.elapsed_time_str)
183
186
 
184
-
185
- # SAVE_DIR = r'D:\troubleshooting\mitra\mitra_yolo'
186
- # CONFIG_PATH = r"C:\troubleshooting\mitra\project_folder\project_config.ini"
187
- # runner = SimBA2Yolo(config_path=CONFIG_PATH, save_dir=SAVE_DIR, sample_size=10, verbose=True, names=('animal_1',))
187
+ #
188
+ # SAVE_DIR = r'E:\troubleshooting\mitra\yolo_0126\yolo_train_0126'
189
+ # CONFIG_PATH = r"E:\troubleshooting\mitra\project_folder\project_config.ini"
190
+ # runner = SimBA2Yolo(config_path=CONFIG_PATH, save_dir=SAVE_DIR, sample_size=50, verbose=True, names=('animal_1',), threshold=0.5)
188
191
  # runner.run()
@@ -49,8 +49,8 @@ class SklearnVisualizationPopUp(PopUpMixin, ConfigReader):
49
49
  pose_palettes = Options.PALETTE_OPTIONS_CATEGORICAL.value + Options.PALETTE_OPTIONS.value
50
50
  PopUpMixin.__init__(self, title="VISUALIZE CLASSIFICATION (SKLEARN) RESULTS", icon='photos')
51
51
  bp_threshold_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="BODY-PART VISUALIZATION THRESHOLD", icon_name='threshold', icon_link=Links.SKLEARN_PLOTS.value, padx=5, pady=5, relief='solid')
52
- self.bp_threshold_lbl = SimBALabel(parent=bp_threshold_frm, txt="Body-parts detected below the set threshold won't be shown in the output videos.", font=Formats.FONT_REGULAR_ITALICS.value)
53
- self.bp_threshold_entry = Entry_Box(parent=bp_threshold_frm, fileDescription='BODY-PART PROBABILITY THRESHOLD: ', labelwidth=40, entry_box_width=15, value=0.00, img='green_dice')
52
+ self.bp_threshold_lbl = SimBALabel(parent=bp_threshold_frm, txt="Body-parts detected below the set threshold won't be shown in the output videos (use 0.0 to see all body-part predictions)", font=Formats.FONT_REGULAR_ITALICS.value)
53
+ self.bp_threshold_entry = Entry_Box(parent=bp_threshold_frm, fileDescription='BODY-PART PROBABILITY THRESHOLD: ', labelwidth=40, entry_box_width=15, value=0.00, img='green_dice', justify='center')
54
54
  self.get_bp_probability_threshold()
55
55
 
56
56
  bp_threshold_frm.grid(row=0, column=0, sticky=NW)
@@ -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
+
@@ -13,6 +13,7 @@ from simba.ui.tkinter_functions import (CreateLabelFrameWithIcon, SimbaButton,
13
13
  from simba.utils.checks import check_if_filepath_list_is_empty
14
14
  from simba.utils.enums import Formats, Links, Options
15
15
  from simba.utils.errors import NoSpecifiedOutputError
16
+ from simba.utils.lookups import get_fonts
16
17
  from simba.utils.read_write import find_files_of_filetypes_in_directory
17
18
 
18
19
 
@@ -29,7 +30,9 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
29
30
  check_if_filepath_list_is_empty(filepaths=self.machine_results_paths,error_msg=f"SIMBA ERROR: Zero files found in the {self.machine_results_dir} directory. Create classification results before visualizing gantt charts",)
30
31
  palettes = Options.PALETTE_OPTIONS_CATEGORICAL.value + Options.PALETTE_OPTIONS.value
31
32
  self.data_paths = find_files_of_filetypes_in_directory(directory=self.machine_results_dir, extensions=[f'.{self.file_type}'], as_dict=True)
32
- max_file_name_len = max(len(k) for k in self.data_paths) + 5
33
+ max_file_name_len, fonts = max(len(k) for k in self.data_paths) + 5, list(get_fonts(sort_alphabetically=True).keys())
34
+ fonts.insert(0, 'AUTO')
35
+ default_font = 'Arial' if 'Arial' in fonts else 'AUTO'
33
36
  PopUpMixin.__init__(self, config_path=config_path, title="VISUALIZE GANTT PLOTS", icon='gantt_small')
34
37
 
35
38
  self.style_settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="STYLE SETTINGS", icon_name='settings', icon_link=Links.GANTT_PLOTS.value, relief='solid', padx=5, pady=5)
@@ -39,6 +42,15 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
39
42
  self.palette_dropdown = SimBADropDown(parent=self.style_settings_frm, dropdown_options=palettes, label='COLOR PALETTE: ', label_width=30, dropdown_width=30, value='Set1', img='palette_small')
40
43
  self.time_format_dropdown = SimBADropDown(parent=self.style_settings_frm, dropdown_options=['SECONDS', 'HH:MM:SS'], label='X-AXIS TIME FORMAT: ', label_width=30, dropdown_width=30, value='SECONDS', img='timer_2')
41
44
  self.core_dropdown = SimBADropDown(parent=self.style_settings_frm, dropdown_options=list(range(1, self.cpu_cnt+1)), label='CPU CORES: ', label_width=30, dropdown_width=30, value=int(self.cpu_cnt/2), img='cpu_small')
45
+ self.font_dropdown = SimBADropDown(parent=self.style_settings_frm, dropdown_options=fonts, label='FONT: ', label_width=30, dropdown_width=30, value=default_font, img='font')
46
+
47
+
48
+ self.clf_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="BEHAVIORS", icon_name='forest', icon_link=Links.GANTT_PLOTS.value, relief='solid', padx=5, pady=5)
49
+ self.clf_choices = {}
50
+ for cnt, clf_name in enumerate(self.clf_names):
51
+ gantt_frames_cb, self.gantt_frames_var = SimbaCheckbox(parent=self.clf_frm, txt=clf_name, val=True)
52
+ self.clf_choices[clf_name] = self.gantt_frames_var
53
+ gantt_frames_cb.grid(row=cnt, column=0, sticky=NW)
42
54
 
43
55
  self.settings_frm = CreateLabelFrameWithIcon(parent=self.main_frm, header="VISUALIZATION SETTINGS", icon_name='eye', icon_link=Links.GANTT_PLOTS.value, relief='solid', padx=5, pady=5)
44
56
  gantt_frames_cb, self.gantt_frames_var = SimbaCheckbox(parent=self.settings_frm, txt='CREATE FRAMES', txt_img='frames', val=False)
@@ -57,18 +69,20 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
57
69
  self.font_rotation_dropdown.grid(row=2, sticky=NW)
58
70
  self.palette_dropdown.grid(row=3, sticky=NW)
59
71
  self.time_format_dropdown.grid(row=4, sticky=NW)
60
- self.core_dropdown.grid(row=5, sticky=NW)
72
+ self.font_dropdown.grid(row=5, sticky=NW)
73
+ self.core_dropdown.grid(row=6, sticky=NW)
61
74
 
62
- self.settings_frm.grid(row=1, sticky=NW, padx=10, pady=10)
75
+ self.clf_frm.grid(row=1, sticky=NW, padx=10, pady=10)
76
+ self.settings_frm.grid(row=2, sticky=NW, padx=10, pady=10)
63
77
  gantt_videos_cb.grid(row=0, sticky=NW)
64
78
  gantt_frames_cb.grid(row=1, sticky=W)
65
79
  gantt_last_frame_cb.grid(row=2, sticky=NW)
66
80
 
67
- self.run_single_video_frm.grid(row=2, sticky=NW)
81
+ self.run_single_video_frm.grid(row=3, sticky=NW)
68
82
  self.run_single_video_btn.grid(row=0, sticky=NW)
69
83
  self.single_video_dropdown.grid(row=0, column=1, sticky=NW)
70
84
 
71
- self.run_multiple_videos.grid(row=3, sticky=NW)
85
+ self.run_multiple_videos.grid(row=4, sticky=NW)
72
86
  self.run_multiple_video_btn.grid(row=0, sticky=NW)
73
87
 
74
88
  self.main_frm.mainloop()
@@ -85,8 +99,14 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
85
99
  video_setting = self.gantt_videos_var.get()
86
100
  last_frm_setting = self.gantt_last_frame_var.get()
87
101
  palette = self.palette_dropdown.get_value()
102
+ font = self.font_dropdown.get_value()
103
+ font = None if font == 'AUTO' else font
88
104
  hhmmss = True if self.time_format_dropdown.get_value() == 'HH:MM:SS' else False
89
-
105
+ clf_names = []
106
+ for clf_name, clf_val in self.clf_choices.items():
107
+ if clf_val.get(): clf_names.append(clf_name)
108
+ if len(clf_names) < 1:
109
+ raise NoSpecifiedOutputError(msg="Select AT LEAST one behavior name.")
90
110
  if not frame_setting and not video_setting and not last_frm_setting:
91
111
  raise NoSpecifiedOutputError(msg="SIMBA ERROR: Please select gantt videos, frames, and/or last frame.")
92
112
 
@@ -103,6 +123,8 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
103
123
  data_paths=data_paths,
104
124
  width=width,
105
125
  height=height,
126
+ font=font,
127
+ clf_names=clf_names,
106
128
  font_size=font_size,
107
129
  font_rotation=font_rotation,
108
130
  core_cnt=core_cnt,
@@ -116,7 +138,9 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
116
138
  last_frm_setting=last_frm_setting,
117
139
  data_paths=data_paths,
118
140
  width=width,
141
+ font=font,
119
142
  height=height,
143
+ clf_names=clf_names,
120
144
  font_size=font_size,
121
145
  font_rotation=font_rotation,
122
146
  palette=palette)
@@ -124,6 +148,7 @@ class GanttPlotPopUp(PopUpMixin, ConfigReader):
124
148
 
125
149
 
126
150
  #_ = GanttPlotPopUp(config_path=r"D:\troubleshooting\maplight_ri\project_folder\project_config.ini")
151
+ #_ = GanttPlotPopUp(config_path=r"C:\troubleshooting\mitra\project_folder\project_config.ini")
127
152
  # _ = GanttPlotPopUp(config_path=r"/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini")
128
153
 
129
154
  # _ = GanttPlotPopUp(config_path=r"C:\troubleshooting\RAT_NOR\project_folder\project_config.ini")