Advanced outlier correction

Here, we perform location- and movement-based outlier correction that allows different heuristic outlier criteria for different animals or body-parts. For example, we will correct some outlier body-parts with a heuristic criteria of 4x above the mean movement, and other body-parts with a heuristic critera of 2x above the mean movement. For a scematic describing movement and location-based outlier correcttion, click HERE. Use SimBA version > 1.71.4.

[1]:
from simba.outlier_tools.outlier_corrector_movement_advanced import OutlierCorrecterMovementAdvanced
from simba.outlier_tools.outlier_corrector_location_advanced import OutlierCorrecterLocationAdvanced
[2]:
# DEFINITIONS

# The path to your SimBA project project_config.ini file.
CONFIG_PATH='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/project_config.ini'

#The directory containing the pose-estimation data to detect outliers within.
INPUT_DIR='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/csv/input_csv'

#If you provide one heuristic multiplier criterion per animal, set type to "animal". If you have
# one heuristic multiplier criterion per body part, set type to "body-part".
TYPE='animal'

#If you want to calculate the aggregate animal sizes using the mean or median euclidean lengths in the video.
AGG_METHOD='mean'

#The body-parts for each animals that you wish to use to calculate the aggregate size of the animals in the videos
CRITERION_BODY_PARTS={'Simon': ['Nose_1', 'Tail_base_1'], 'JJ': ['Nose_2', 'Tail_base_2']}

# The multiplier criterion for animal.  Here we use one multipler per animal. If you want to use different multiplers for each body-part
# then provide a nested dictyionary, e.g., below. If you are using a nested dictionary and provide different multiplier per body-part,
# remember to set type = 'body-part.'
#SETTINGS = {'Simon': {'Ear_left_1': 1.1,
#                           'Ear_right_1': 5.1,
#                          'Nose_1': 2.1,
#                          'Center_1': 1.5,
#                          'Lat_left_1': 3.1,
#                          'Lat_right_1': 1.9,
#                          'Tail_base_1': 2.3,
#                          'Tail_end_1': 1.4},
#                'JJ': {'Ear_left_2': 1.2,
#                       'Ear_right_2': 1.2,
#                       'Nose_2': 2,
#                       'Center_2': 4.1,
#                       'Lat_left_2': 9,
#                       'Lat_right_2': 1.2,
#                       'Tail_base_2': 1.6,
#                       'Tail_end_2': 2.2}}
SETTINGS={'Simon': 2.1, 'JJ': 3.2}
[3]:
#We initialize the advanced outlier movement corrector and run it. The redults will be saved in the
# project_folder/csv/outlier_corrected_movement directory of the SimBA project.
movement_outlier_corrector = OutlierCorrecterMovementAdvanced(config_path=CONFIG_PATH,
                                                              input_dir=INPUT_DIR,
                                                              criterion_body_parts=CRITERION_BODY_PARTS,
                                                              type=TYPE,
                                                              agg_method=AGG_METHOD,
                                                              settings=SETTINGS)
movement_outlier_corrector.run()
Processing video Together_1. Video 1/1...
SIMBA COMPLETE: Movement outliers complete for video Together_1. (elapsed time: 0.9181s)        complete
SIMBA COMPLETE: Movement outlier log saved at /Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/logs/movement_outliers_20230811132623.csv         complete
SIMBA COMPLETE: 1 video(s) corrected for movement outliers. Saved in /Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/csv/outlier_corrected_movement     complete
[5]:
#Next, we want to perform location outlier correction. We will perform location outlier correction on the files that
# was processed by the movement outlier corrector above, so we change the input directory to the folder that contains
# those files:
INPUT_DIR='/Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/csv/outlier_corrected_movement'

# This time, we will also change the ``settings``, so rather than providing one multiplier per animal, we now provide
# one multiplier per body-part:
SETTINGS = {'Simon': {'Ear_left_1': 1.1,
                      'Ear_right_1': 5.1,
                      'Nose_1': 2.1,
                      'Center_1': 1.5,
                      'Lat_left_1': 3.1,
                      'Lat_right_1': 1.9,
                      'Tail_base_1': 2.3,
                      'Tail_end_1': 1.4},
               'JJ': {'Ear_left_2': 1.2,
                      'Ear_right_2': 1.2,
                      'Nose_2': 2,
                      'Center_2': 4.1,
                      'Lat_left_2': 9,
                      'Lat_right_2': 1.2,
                      'Tail_base_2': 1.6,
                      'Tail_end_2': 2.2}}
TYPE='body-parts'


[6]:
#We initialize the advanced outlier location corrector and run it. The redults will be saved in the
# project_folder/csv/outlier_corrected_movement directory of the SimBA project.
location_outlier_corrector = OutlierCorrecterLocationAdvanced(config_path=CONFIG_PATH,
                                                              input_dir=INPUT_DIR,
                                                              criterion_body_parts=CRITERION_BODY_PARTS,
                                                              type=TYPE,
                                                              agg_method=AGG_METHOD,
                                                              settings=SETTINGS)
location_outlier_corrector.run()
Processing video Together_1. Video 1/1...
SIMBA COMPLETE: Location outliers complete for video Together_1. (elapsed time: 1.327s)         complete
SIMBA COMPLETE: Location outlier log saved at /Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/logs/location_outliers_20230811132629.csv         complete
SIMBA COMPLETE: 1 video(s) corrected for location outliers. Saved in /Users/simon/Desktop/envs/troubleshooting/two_black_animals_14bp/project_folder/csv/outlier_corrected_movement_location    complete
[ ]: