Outlier correction

We import pose-estimation data, and perform outlier correction on that pose-estimation data using heuristic rules. The application of those rules are described here: https://github.com/sgoldenlab/simba/blob/master/misc/Outlier_settings.pdf

[23]:
from simba.outlier_tools.outlier_corrector_movement import OutlierCorrecterMovement
from simba.outlier_tools.outlier_corrector_location import OutlierCorrecterLocation
from simba.utils.cli import set_outlier_correction_criteria_cli
from simba.pose_importers.dlc_importer_csv import import_multiple_dlc_tracking_csv_file
[11]:
# DEFINITIONS: HERE WE (i) DEFINE THE PATHS TO OUR DATA / SIMBA PROJECT, (ii) HOW WE SHOULD INTERPOLATE / SMOOTH OUR NEW
# DATA, AND (III) THE ATTRIBUTES OF OUR NEW VIDEOS (FPS ETC.)

## Define the path to our SimBA project config ini
CONFIG_PATH = '/Users/simon/Desktop/envs/troubleshooting/notebook_example/project_folder/project_config.ini'

## Define the path to the directory holding our new DLC CSV pose-estimation data
DATA_DIR = '/Users/simon/Desktop/envs/troubleshooting/notebook_example/data'

## Define if / how you want to interpolate missing pose-estimation data,
## and if/how you want to smooth the new pose estimation data: here we do neither.
INTERPOLATION_SETTING = 'None' # OPTIONS: 'None', Animal(s): Nearest', 'Animal(s): Linear', 'Animal(s): Quadratic','Body-parts: Nearest', 'Body-parts: Linear', 'Body-parts: Quadratic'
SMOOTHING_SETTING = None # OPTIONS: 'Gaussian', 'Savitzky Golay'
SMOOTHING_TIME = None # TIME IN MILLISECOND

## Define the fps and the pixels per millimeter of the incoming data: has to be the same for all new videos.
## if you have varying fps / px per millimeter / resolutions, then use gui (2023/05)
FPS = 15
PX_PER_MM = 4.6
RESOLUTION = (600, 400) # WIDTH X HEIGHT

#Define the body-parts and critera we want to use for outlier correction. NOTE: You can also set this manually in the project_config.ini or thrugh
# the SimBA GUI.
AGGREGATION_METHOD = 'mean'
BODY_PARTS = {'Animal_1': {'Movement': ['Nose_1', 'Tail_base_1'],
                           'Location': ['Nose_1', 'Tail_base_1']},
              'Animal_2': {'Movement': ['Nose_2', 'Tail_base_2'],
                           'Location': ['Nose_2', 'Tail_base_2']}}
MOVEMENT_CRITERION = 0.7
LOCATION_CRITERION = 2.0
[13]:
# WE RUN THE DATA IMPORTER FOR OUR DIRECTORY OF FILES
## This imports your DLC files in the ``DATA_DIR`` according to the smoothing / interpolation settings defined above
import_multiple_dlc_tracking_csv_file(config_path=CONFIG_PATH,
                                        interpolation_setting=INTERPOLATION_SETTING,
                                        smoothing_setting=SMOOTHING_SETTING,
                                        smoothing_time=SMOOTHING_TIME,
                                        data_dir=DATA_DIR)
Importing Aqu_FFJ_Cre_721 to SimBA project...
Pose-estimation data for video Aqu_FFJ_Cre_721 imported to SimBA project (elapsed time: 0.1718s)...
Importing Aqu_FFJ_Cre_723 to SimBA project...
Pose-estimation data for video Aqu_FFJ_Cre_723 imported to SimBA project (elapsed time: 0.1681s)...
Importing Aqu_FFJ_Cre_722 to SimBA project...
Pose-estimation data for video Aqu_FFJ_Cre_722 imported to SimBA project (elapsed time: 0.1617s)...
SIMBA COMPLETE: Imported 3 pose estimation file(s) (elapsed time: 0.5078s)      complete
[21]:
#We set the outlier criteria in the project_config.ini and run the outlier correction. NOTE: You can also set this manually in the project_config.ini or thrugh
# the SimBA GUI. If this has already been done, there is **no need** to call `set_outlier_correction_criteria_cli`.
set_outlier_correction_criteria_cli(config_path=CONFIG_PATH,
                                    aggregation=AGGREGATION_METHOD,
                                    body_parts=BODY_PARTS,
                                    movement_criterion=MOVEMENT_CRITERION,
                                    location_criterion=LOCATION_CRITERION)


_ = OutlierCorrecterMovement(config_path=CONFIG_PATH).run()
_ = OutlierCorrecterLocation(config_path=CONFIG_PATH).run()
Processing video Aqu_FFJ_Cre_721. Video 1/3...
Corrected movement outliers for file Aqu_FFJ_Cre_721 (elapsed time: 0.2929s)...
Processing video Aqu_FFJ_Cre_723. Video 2/3...
Corrected movement outliers for file Aqu_FFJ_Cre_723 (elapsed time: 0.2713s)...
Processing video Aqu_FFJ_Cre_722. Video 3/3...
Corrected movement outliers for file Aqu_FFJ_Cre_722 (elapsed time: 0.2674s)...
SIMBA COMPLETE: Log for corrected "movement outliers" saved in project_folder/logs (elapsed time: 0.8572s)      complete
Processing video Aqu_FFJ_Cre_721. Video 1/3..
Corrected location outliers for file Aqu_FFJ_Cre_721 (elapsed time: 49.6797s)...
Processing video Aqu_FFJ_Cre_723. Video 2/3..
Corrected location outliers for file Aqu_FFJ_Cre_723 (elapsed time: 24.645s)...
Processing video Aqu_FFJ_Cre_722. Video 3/3..
Corrected location outliers for file Aqu_FFJ_Cre_722 (elapsed time: 15.1142s)...
SIMBA COMPLETE: Log for corrected "location outliers" saved in project_folder/logs (elapsed time: 89.4743s)     complete
[ ]: