Time_in_each_roi Results Issue

I am utilizing the time_in_each_roi script to analyze the amount of time mice spend interacting. I’m relying pretty heavily on the DeepLabCut Toolbox - demo for post processing example. In the example, the ROIs each cover half of the arena (https://github.com/AlexEMG/DLCutils/blob/master/Demo_loadandanalyzeDLCdata.ipynb) .

I have edited the script for my particular ROI’s, which are much smaller, but the output still seems to be calculating the time in each half of the arena, as opposed to my determined ROI’s.

Here is the last portion of my code and the output. It is giving me stats for each half of the arena, and I need my given ROI’s (which are much smaller). I’m not sure how to do this?

In [46]: from collections import namedtuple ; position = namedtuple(‘position’,[‘topleft’,‘bottomright’]) ; xsnout=Dataframe[DLCscorer][bpt][‘x’].values ; ysnout=Dataframe[DLCscorer][bpt][‘y’].values ; bp_tracking = np.array((xsnout, ysnout, vsnout))

In [53]: rois = {‘leftside’:position((0,0),(105.37,67.8)),‘rightside’:position((139.12,192.46), (240,240))} ; print(rois) ; plt.plot(time,vel*1./fps) ; plt.xlabel(‘Time in Seconds’) ; plt.ylabel(‘Speed in Pixels Per Second’) ; plt.show() ;

In [54]: import matplotlib.patches as patches ; fig,ax = plt.subplots(1) ; plt.plot(xsnout,ysnout,’.-’) ; rect1 = patches.Rectangle(rois[‘rightside’].topleft,rois[‘rightside’].bottomright[0]-rois[‘rightside’].topleft[0],rois[‘rightside’].bottomright[1]-rois[‘rightside’].topleft[1],linewidth=1,edgecolor=‘purple’,facecolor =‘none’) ; rect2 = patches.Rectangle(rois[‘leftside’].topleft,rois[‘leftside’].bottomright[0]-rois[‘leftside’].topleft[0],rois[‘leftside’].bottomright[1]-rois[‘leftside’].topleft[1],linewidth=1,edgecolor=‘blue’,facecolor=‘none’) ; ax.add_patch(rect1) ; ax.add_patch(rect2) ; ax.add_patch(rect2) ; plt.ylim(0,240) ; plt.show()

In [23]: import time_in_each_roi ; res = time_in_each_roi.get_timeinrois_stats(bp_tracking.T, rois, fps=16) ; res

Out[46]:
{‘avg_time_in_roi’: {‘leftside’: 168.48979591836735,
‘rightside’: 25.877551020408163},
‘avg_time_in_roi_sec’: {‘leftside’: 10.53061224489796,
‘rightside’: 1.6173469387755102},
‘avg_vel_in_roi’: {‘leftside’: 3.175061720136605,
‘rightside’: 5.322323880919266},
‘cumulative_time_in_roi’: {‘leftside’: 1268, ‘rightside’: 8256},
‘cumulative_time_in_roi_sec’: {‘leftside’: 79.25, ‘rightside’: 516.0},
‘transitions_per_roi’: {‘leftside’: 49, ‘rightside’: 49}}

@rcparent2

I believe @AlexanderMathis @MWMathis might be the best persons to answer your question…

Dear @etadobson - we are very active in answering, so no worries about tagging us in all the posts :wink: This was resolved on GitHub: https://github.com/AlexEMG/DLCutils/issues/8

2 Likes

No worries. Sorry to be a bother… just trying to get to some unanswered folks - and to be sure if solutions are provided elsewhere (as in this case) - it’s helpful that they are linked back here on the forum. That’s helpful for folks in the future to know the issue has been solved.

2 Likes