DLCutils - importing data from DLC for "time_in_each_roi"


I am trying to implement and use the “time_in_each_roi.py” file from my data which I collected from the first part of the DeepLabCut pipeline, but am running into issues with how to properly incorporate the data into the new script. Do I need to edit the code specifically for my data set? I am trying to calculate the velocity in pixels per frame for an animal subject during an experiment.

If anyone has advice on how to proceed forward, it would be much appreciated!



it would probably be good to add an example notebook or so (https://github.com/AlexEMG/DLCutils/blob/master/time_in_each_roi.py). Anyway, in the script it says:

Example usage:
rois --> a dictionary with name and position of each roi
tracking --> a pandas dataframe with X,Y,Velocity for each bodypart
bodyparts --> a list with the name of all the bodyparts

results = {}
for bp in bodyparts:
    bp_tracking = np.array((tracking.bp.x.values, tracking.bp.y.values, tracking.bp.Velocity.values))
    res = get_timeinrois_stats(bp_tracking, roi, fps=30)
    results[bp] = res

if Velocity is not know, it can be calculated using "calc_distance_between_points_in_a_vector_2d":
    vel = calc_distance_between_points_in_a_vector_2d(np.array(tracking.bp.x.values, tracking.bp.y.values))
which returns a 1d vector with the velocity in pixels/frame [effectively the number pixels a tracked point moved
from one frame to the next]


So in other words you need to load the output of DLC and then compute distances/velocity based on the X/Y arrays for a particular bodypart.

Hope that helps,

Hey Alexander,

Thanks for the assistance. I guess I should clarify my issue. I am still working on familiarizing myself with DLC (as well as Python in general) and I am not sure how to load the output of DLC so that the distances/velocities may be computed.

Thanks again!

Dear Michael,

I see, I made some example notebook for example data that you can check out. Hope it is useful!