Processes
behavysis.processes.update_configs.UpdateConfigs
¶
summary
Source code in behavysis/processes/update_configs.py
update_configs(configs_fp, default_configs_fp, overwrite)
staticmethod
¶
Initialises the config files with the given default_configs
.
The different types of overwriting are:
- "user": Only the user parameters are updated.
- "all": All parameters are updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configs_fp
|
str
|
The filepath of the existing config file. |
required |
default_configs_fp
|
str
|
The filepath of the default config file to use. |
required |
overwrite
|
Literal['user', 'all']
|
Specifies how to update the config files. |
required |
Returns:
Type | Description |
---|---|
str
|
Description of the function's outcome. |
Source code in behavysis/processes/update_configs.py
behavysis.processes.format_vid.FormatVid
¶
Class for formatting videos based on given parameters.
Source code in behavysis/processes/format_vid.py
format_vid(raw_vid_fp, formatted_vid_fp, configs_fp, overwrite)
classmethod
¶
Formats the input video with the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_fp
|
str
|
The input video filepath. |
required |
formatted_fp
|
str
|
The output video filepath. |
required |
configs_fp
|
str
|
The JSON configs filepath. |
required |
overwrite
|
bool
|
Whether to overwrite the output file (if it exists). |
required |
Returns:
Type | Description |
---|---|
str
|
Description of the function's outcome. |
Source code in behavysis/processes/format_vid.py
get_vids_metadata(raw_vid_fp, formatted_vid_fp, configs_fp)
classmethod
¶
Finds the video metadata/parameters for either the raw or formatted video, and stores this data in the experiment's config file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_fp
|
str
|
The input video filepath. |
required |
formatted_fp
|
str
|
The output video filepath. |
required |
configs_fp
|
str
|
The JSON configs filepath. |
required |
Returns:
Type | Description |
---|---|
str
|
Description of the function's outcome. |
Source code in behavysis/processes/format_vid.py
behavysis.processes.run_dlc.RunDLC
¶
summary
Source code in behavysis/processes/run_dlc.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
ma_dlc_run_batch(vid_fp_ls, keypoints_dir, configs_dir, gputouse, overwrite)
staticmethod
¶
Running custom DLC script to generate a DLC keypoints dataframe from a single video.
Source code in behavysis/processes/run_dlc.py
ma_dlc_run_single(formatted_vid_fp, keypoints_fp, configs_fp, gputouse, overwrite)
classmethod
¶
Running custom DLC script to generate a DLC keypoints dataframe from a single video.
Source code in behavysis/processes/run_dlc.py
behavysis.processes.calculate_params.CalculateParams
¶
Source code in behavysis/processes/calculate_params.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
dur_frames_from_likelihood(keypoints_fp, configs_fp)
staticmethod
¶
Calculates the duration in seconds, from the time the specified bodyparts appeared to the time they disappeared. Appear/disappear is calculated from likelihood.
Source code in behavysis/processes/calculate_params.py
px_per_mm(keypoints_fp, configs_fp)
staticmethod
¶
Calculates the pixels per mm conversion for the video.
This is done by averaging the (x, y) coordinates of each corner, finding the average x difference for the widths in pixels and y distance for the heights in pixels, dividing these pixel distances by their respective mm distances (from the *config.json file), and taking the average of these width and height conversions to estimate the px to mm conversion.
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/calculate_params.py
start_frame_from_csv(keypoints_fp, configs_fp)
staticmethod
¶
Reads the start time of the experiment from a given CSV file (filepath specified in config file).
Expects value to be in seconds (so will convert to frames). Also expects the csv_fp to be a csv file, where the first column is the name of the video and the second column is the start time.
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/calculate_params.py
start_frame_from_likelihood(keypoints_fp, configs_fp)
staticmethod
¶
Determines the starting frame of the experiment based on when the subject "likely" entered the frame of view.
This is done by looking at a sliding window of time. If the median likelihood of the subject existing in each frame across the sliding window is greater than the defined pcutoff, then the determine this as the start time.
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/calculate_params.py
stop_frame_from_dur(keypoints_fp, configs_fp)
staticmethod
¶
Calculates the end time according to the following equation:
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/calculate_params.py
stop_frame_from_likelihood(keypoints_fp, configs_fp)
staticmethod
¶
Determines the starting frame of the experiment based on when the subject "likely" entered the frame of view.
This is done by looking at a sliding window of time. If the median likelihood of the subject existing in each frame across the sliding window is greater than the defined pcutoff, then the determine this as the start time.
Source code in behavysis/processes/calculate_params.py
behavysis.processes.preprocess.Preprocess
¶
summary
Source code in behavysis/processes/preprocess.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
interpolate(src_fp, dst_fp, configs_fp, overwrite)
classmethod
¶
"Smooths" out noticeable jitter of points, where the likelihood (and accuracy) of a point's coordinates are low (e.g., when the subject's head goes out of view). It does this by linearly interpolating the frames of a body part that are below a given likelihood pcutoff.
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/preprocess.py
interpolate_stationary(src_fp, dst_fp, configs_fp, overwrite)
classmethod
¶
If the point detection (above a certain threshold) is below a certain proportion, then the x and y coordinates are set to the given values (usually corners). Otherwise, does nothing (encouraged to run Preprocess.interpolate afterwards).
Notes
The config file must contain the following parameters:
- user
- preprocess
- interpolate_stationary
[
- bodypart: str (assumed to be the "single" individual)
- pcutoff: float (between 0 and 1)
- pcutoff_all: float (between 0 and 1)
- x: float (between 0 and 1 - proportion of the video width)
- y: float (between 0 and 1 - proportion of the video height)
]
Source code in behavysis/processes/preprocess.py
refine_ids(src_fp, dst_fp, configs_fp, overwrite)
classmethod
¶
Ensures that the identity is correctly tracked for maDLC. Assumes interpolate_points has already been run.
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/preprocess.py
start_stop_trim(src_fp, dst_fp, configs_fp, overwrite)
classmethod
¶
Filters the rows of a DLC formatted dataframe to include only rows within the start and end time of the experiment, given a corresponding configs dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dlc_fp
|
str
|
The file path of the input DLC formatted dataframe. |
required |
dst_fp
|
str
|
The file path of the output trimmed dataframe. |
required |
configs_fp
|
str
|
The file path of the configs dict. |
required |
overwrite
|
bool
|
If True, overwrite the output file if it already exists. If False, skip processing if the output file already exists. |
required |
Returns:
Type | Description |
---|---|
str
|
An outcome message indicating the result of the trimming process. |
Notes
The config file must contain the following parameters:
Source code in behavysis/processes/preprocess.py
behavysis.processes.extract_features.ExtractFeatures
¶
Source code in behavysis/processes/extract_features.py
extract_features(keypoints_fp, features_fp, configs_fp, overwrite)
staticmethod
¶
Extracting features from preprocessed keypoints dataframe using SimBA processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypoints_fp
|
str
|
Preprocessed keypoints filepath. |
required |
dst_fp
|
str
|
Filepath to save extracted_features dataframe. |
required |
configs_fp
|
str
|
Configs JSON filepath. |
required |
overwrite
|
bool
|
Whether to overwrite the dst_fp file (if it exists). |
required |
Returns:
Type | Description |
---|---|
str
|
The outcome of the process. |
Source code in behavysis/processes/extract_features.py
behavysis.processes.classify_behavs.ClassifyBehavs
¶
Source code in behavysis/processes/classify_behavs.py
classify_behavs(features_fp, behavs_fp, configs_fp, overwrite)
classmethod
¶
Given model config files in the BehavClassifier format, generates beahviour predidctions on the given extracted features dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features_fp
|
str
|
description |
required |
dst_fp
|
str
|
description |
required |
configs_fp
|
str
|
description |
required |
overwrite
|
bool
|
Whether to overwrite the output file (if it exists). |
required |
Returns:
Type | Description |
---|---|
str
|
Description of the function's outcome. |
Notes
The config file must contain the following parameters:
Where themodels
list is a list of model_config.json
filepaths.
Source code in behavysis/processes/classify_behavs.py
behavysis.processes.analyse_behavs.AnalyseBehavs
¶
Source code in behavysis/processes/analyse_behavs.py
analyse_behavs(behavs_fp, dst_dir, configs_fp)
staticmethod
¶
Takes a behavs dataframe and generates a summary and binned version of the data.
Source code in behavysis/processes/analyse_behavs.py
behavysis.processes.analyse.Analyse
¶
Source code in behavysis/processes/analyse.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
freezing(keypoints_fp, dst_dir, configs_fp)
staticmethod
¶
Determines the frames in which the subject is frozen.
"Frozen" is defined as not moving outside of a radius of threshold_mm
, and only
includes bouts that last longer than window_sec
spent seconds.
NOTE: method is "greedy" because it looks at a freezing bout from earliest possible frame.
Source code in behavysis/processes/analyse.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
in_roi(keypoints_fp, dst_dir, configs_fp)
staticmethod
¶
Determines the frames in which the subject is inside the cage (from average of given bodypoints).
Points are padding_px
padded (away) from center.
Source code in behavysis/processes/analyse.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
social_distance(keypoints_fp, dst_dir, configs_fp)
staticmethod
¶
Determines the speed of the subject in each frame.
Source code in behavysis/processes/analyse.py
speed(keypoints_fp, dst_dir, configs_fp)
staticmethod
¶
Determines the speed of the subject in each frame.
Source code in behavysis/processes/analyse.py
behavysis.processes.combine_analysis
¶
CombineAnalysis
¶
Source code in behavysis/processes/combine_analysis.py
combine_analysis(analysis_dir, analysis_combined_fp, configs_fp, overwrite)
classmethod
¶
Concatenates across columns the frame-by-frame dataframes for all analysis subdirectories and saves this in a single dataframe.
Source code in behavysis/processes/combine_analysis.py
behavysis.processes.evaluate.Evaluate
¶
summary
Source code in behavysis/processes/evaluate/__init__.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
behav_plot(vid_fp, dlc_fp, behavs_fp, dst_dir, configs_fp, overwrite)
staticmethod
¶
Make behaviour evaluation plot of the predicted and actual behaviours through time.
Source code in behavysis/processes/evaluate/__init__.py
keypoints_plot(vid_fp, dlc_fp, behavs_fp, dst_dir, configs_fp, overwrite)
staticmethod
¶
Make keypoints evaluation plot of likelihood of each bodypart through time.