-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotMotionStat.r
executable file
·174 lines (129 loc) · 6.37 KB
/
plotMotionStat.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
################# MOTION ######################
##Motion Plots - Path Length ##
par(bg="white")
sampleSize = sum(unlist(datMotionStat[,"nLarva"],use.names = FALSE))
totalFrames = sum(unlist(datMotionStat[,"totalFrames"],use.names = FALSE))
moveFrames = sum(unlist(datMotionStat[,"totalMotionFrames"],use.names = FALSE))
FPS = 420;
strsub = paste("#n=", sampleSize, " #F:",totalFrames,
"(",format(totalFrames/FPS/60,digits =3),"min)",
" F_M/F:",format( moveFrames/totalFrames,use.names = FALSE ,digits =3) ,
" #Events:",sum(unlist(datMotionStat[,"totalEventCount"])),
collapse=NULL)
strPlotName = "plots/meanPathLengthLarva.pdf"
vDat <- datMotionStat[,"vPathLengths"]
vDatSetID <- datMotionStat[,"vDataSetID"]
vIDTable <- datHuntStat[,"vIDLookupTable"]
datmean <- unlist(datMotionStat[,"meanPathLength"],use.names = FALSE)*DIM_MMPERPX
datse <- unlist(datMotionStat[,"sePathLength"],use.names = FALSE)*DIM_MMPERPX
strtitle <- "Mean Path Length (mm) Per Larva"
##Fish With No Hunting Events #
#datHuntStat[,"vexpID"]$NE[datHuntStat[,"vHLarvaEventCount"]$NE == 0]
##*All:unlist(datHuntStat[,"vexpID"],,use.names=FALSE)[unlist(datHuntStat[,"vHLarvaEventCount"],use.names=FALSE) == 0]
pdf(strPlotName,width=8,height=8) #col=(as.integer(filtereddatAllFrames$expID))
ylim <- max(unlist(vDat,use.names=FALSE))*DIM_MMPERPX
xbarcenters <- boxplotPerCondition(datMotionStat, datmean,datse,strtitle,strsub,strPlotName,ylim)
#vpch = c(0:25,32:127)
for (g in strCondTags)
{
idx <- match(g,strCondTags)
vpt <- unlist(vDat[g],use.names=FALSE)*DIM_MMPERPX
##OPTIONAL - PLot NA points As Zero -
##vpt <-replace(vpt,is.na(vpt),0) ##NA Appear Where for exp Where no Hunting Episodes Occured
points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=idx,col=r[idx] )
points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=as.numeric(vDatSetID[[g]]),col=rDataset[as.numeric(vDatSetID[[g]])] )
}
#plotConnectedPointsPairs(vIDTable,vDat,strCondTags,xbarcenters) ##Not datMotionStat not Ready yet
dev.off();
#plot(rep(xbarcenters[1],NROW(datMotionStat[[1,"vPathLengths"]]) ),datMotionStat[[1,"vPathLengths"]] )
##Motion Plots - Speed ##
strPlotName = "plots/meanSpeedLarva.pdf"
vDat <- datMotionStat[,"vSpeed"]
vDatSetID <- datMotionStat[,"vDataSetID"]
datmean <- unlist(datMotionStat[,"meanSpeed"],use.names = FALSE)
datse <- unlist(datMotionStat[,"seSpeed"],use.names = FALSE)
strtitle <- "Movement Speed Per Larva"
pdf(strPlotName,width=8,height=8) #col=(as.integer(filtereddatAllFrames$expID))
ylim <- max(unlist(vDat,use.names=FALSE))
xbarcenters <- boxplotPerCondition(datMotionStat,datmean,datse,strtitle,strsub,strPlotName,ylim)
for (g in strCondTags)
{
idx <- match(g,strCondTags)
vpt <- unlist(vDat[g],use.names=TRUE)
##OPTIONAL - PLot NA points As Zero -
##vpt <-replace(vpt,is.na(vpt),0) ##NA Appear Where for exp Where no Hunting Episodes Occured
#points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=idx,col=r[idx] )
points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=as.numeric(vDatSetID[[g]]),col=rDataset[as.numeric(vDatSetID[[g]])] )
}
dev.off();
##Motion Ratio - ##
strPlotName = "plots/moveRatioGroup.pdf"
vDat <- datMotionStat[,"vMovementRatio"]
vDatSetID <- datMotionStat[,"vDataSetID"]
datmean <- unlist(datMotionStat[,"meanMotionRatio"])
datse <- unlist(datMotionStat[,"seSpeed"],use.names = FALSE)
strtitle <- "Movement Ratio Per Larva"
pdf(strPlotName,width=8,height=8) #col=(as.integer(filtereddatAllFrames$expID))
ylim <- max(unlist(vDat,use.names=FALSE))
xbarcenters <- boxplotPerCondition(datMotionStat,datmean,datse,strtitle,strsub,strPlotName,ylim)
for (g in strCondTags)
{
idx <- match(g,strCondTags)
vpt <- unlist(vDat[g],use.names=TRUE)
##OPTIONAL - PLot NA points As Zero -
##vpt <-replace(vpt,is.na(vpt),0) ##NA Appear Where for exp Where no Hunting Episodes Occured
#points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=idx,col=r[idx] )
points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=as.numeric(vDatSetID[[g]]),col=rDataset[as.numeric(vDatSetID[[g]])] )
}
dev.off();
##Motion Sinuosity - ##
strPlotName = "plots/pathSinuosityGroup.pdf"
vDat <- datMotionStat[,"vSinuosity"]
vDatSetID <- datMotionStat[,"vDataSetID"]
datmean <- unlist(datMotionStat[,"meanSinuosity"])
datse <- unlist(datMotionStat[,"seSinuosity"],use.names = FALSE)
strtitle <- "Path Sinuosity Ratio Per Larva"
pdf(strPlotName,width=8,height=8) #col=(as.integer(filtereddatAllFrames$expID))
ylim <- 20 #max(unlist(vDat,use.names=FALSE))
xbarcenters <- boxplotPerCondition(datMotionStat,datmean,datse,strtitle,strsub,strPlotName,ylim)
for (g in strCondTags)
{
idx <- match(g,strCondTags)
vpt <- unlist(vDat[g],use.names=TRUE)
##OPTIONAL - PLot NA points As Zero -
##vpt <-replace(vpt,is.na(vpt),0) ##NA Appear Where for exp Where no Hunting Episodes Occured
#points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=idx,col=r[idx] )
points(rep(xbarcenters[idx],NROW(vpt) ),vpt,pch=as.numeric(vDatSetID[[g]]),col=rDataset[as.numeric(vDatSetID[[g]])] )
}
dev.off()
##### Scattter OF Hunt Events Vs Initial Prey Counts ### ##
strPlotName = "plots/EventsCountInFedTestVsInitPreyCount_scatter.pdf"
pdf(strPlotName,width=8,height=8,title="Number of Prey In Live Test Conditions")
vDat <- datHuntStat[,"vHInitialPreyCount"]
yl <- c(0,ceiling(max(datMotionStat[,"vEventCounts"]$LL,datMotionStat[,"vEventCounts"]$DL,datMotionStat[,"vEventCounts"]$NL)/10)*10 )
xl <- c(0,60)
hist(vDat$LL,col=colourH[1],ylim=yl,xlim=xl,breaks=10,
main="Number of recorded Events vs Prey",
xlab = "Number of Prey at start of experiment",
ylab = "Number of Recorded Events")
hist(vDat$NL,col=colourH[2],ylim=yl,xlim=xl,breaks=10,add=T)
hist(vDat$DL,col=colourH[3],ylim=yl,xlim=xl,breaks=10,add=T)
box()
par(new=TRUE)
##Add Scatter Of Hunt Events
plot(datHuntStat[,"vHInitialPreyCount"]$LL,as.numeric(datMotionStat[,"vEventCounts"]$LL),
pch=4,col=1,
xlab="",ylab="",ylim=yl,xlim=xl,main="")
points(datHuntStat[,"vHInitialPreyCount"]$NL,as.numeric(datMotionStat[,"vEventCounts"]$NL),
pch=2 ,col=2,type ="p",
xlab="",ylab="",ylim=yl,xlim=xl)
points(datHuntStat[,"vHInitialPreyCount"]$DL,as.numeric(datMotionStat[,"vEventCounts"]$DL),
pch=19 ,col=6,type ="p",
xlab="",ylab="",ylim=yl,xlim=xl)
legend(50,25,legend=c("LL","NL","DL"),
fill=colourH,
col = c(1, 2,6),pch = c(4,2,19),
bg = "gray90",lty = c(2, -1, 1),
merge=TRUE)
dev.off()
########## # ## # # # #