ETHZ-INS / DLCAnalyzer

R Scripts to analyze deep lab cut point data and related data
GNU General Public License v3.0
60 stars 16 forks source link

Zone transitions #15

Open sofiasalvatore opened 2 years ago

sofiasalvatore commented 2 years ago

Hi @lukasvonziegler,

Thank you for putting this all together!!

I am trying to format your zone transitions report which uses the CalculateTransitions function to report zone entries rather than transitions in an out of a zone. I am stuck on how the Boolean from avgBool is created. Do 1's correspond to a moment in which the animal is outside the zone of interest and 0's when an animal enters a zone of interest?

Sofia

lukasvonziegler commented 2 years ago

Regarding your question: maybe to make it easier for you to get what you need quickly: zone entries will simply be zone transitions / 2. if the mouse starts in the zone you round down, if it starts outside you round up ;)

the function IsInZone (t = TrackingObject, p = "PointName",z = "ZoneName") will return a boolean vector (1s and 0s) that tell you if the animal is in the zone ( = 1) or not (= 0) at each frame.

the function avgbool(x,window) then smooths such a boolean vector (1s and 0s) over an integration window. i.e if x = c(1,1,1,0,1,1,1,0,0,0,0,0,0,0) it avgbool (x, 5) would smooth to c(1,1,1,1,1,1,1,0,0,0,0,0,0,0). This helps to remove single image transitions (i.e. of the bodycenter jumps over the zone border for a single frame which can happen multiple times in short interval if it sits just on the border) from impacting the analysis to much.

sofiasalvatore commented 2 years ago

Thanks!!

marytast commented 1 year ago

@sofiasalvatore Could you share how you change the code to reflect the number of entries instead of transitions, please? I am also stuck in that point. I would really appreciate your help. Thank you!

sofiasalvatore commented 1 year ago

@marytast

I edited the DLCAnalyzer_Functionsfinal.R file to report zone entries as "entries". Below is the code I added.

Report[[paste(zone.name, "entries", sep = ".")]] <- CalculateTransitions(in.zone, t$integration_period)/2

The logic is explained in the previous comment, where if the mouse starts in the zone you round down, if it starts outside you round up

marytast commented 1 year ago

@sofiasalvatore Thank you so much for your quick reply!!!

plant1987 commented 4 months ago

Hi: I am just wondering if I did not add zones. And directly run, e.g., OFTAnalysis. Does it mean that the mouse is running in the whole aerna?