-
Notifications
You must be signed in to change notification settings - Fork 12
tuneInterpolation
niels edited this page Oct 25, 2017
·
2 revisions
#- Script to tune the cHs method
#- Load a high resolution VMS dataset
data(VMShf)
colnames(VMShf) <- c("VE_REF","SI_LATI","SI_LONG","SI_SP","SI_HE","SI_DATIM")
VMShf$SI_DATE <- ac(as.Date(VMShf$SI_DATIM))
VMShf$SI_TIME <- ac(format(VMShf$SI_DATIM,format="%H:%M"))
#- Calculate speed
VMShf <- calculateSpeed(VMShf,level="vessel",fill.na=T)
#- Generate low resolution VMS dataset from high resolution set
VMShf <- intervalTacsat(VMShf,level="vessel",fill.na=T)
VMShf$INTVCUM <- cumsum(VMShf$INTV)
VMSlf <- VMShf[which(VMShf$INTVCUM %% 120 == 0),]
VMShf <- VMShf[which(VMShf$INTVCUM %% 120 == 0)[1]:nrow(VMShf),]
#- Filter out only fishing pings
VMShf <- subset(VMShf,SI_SPCA >= 4 & SI_SPCA <= 8.5)
VMSlf <- subset(VMSlf,SI_SPCA >= 4 & SI_SPCA <= 8.5)
#- Define the tuning method
tunecHsInterpolation <- function(lowResTacsat,
hiResTacsat,
interval,
margin,
res,
headingAdjustment=0,
st=c(4,8.5)){
#- Define the optimization routine inside the function
optimInterpolation <- function(x){
ints <- interpolateTacsat(hiResTacsat,
interval=interval,
margin=margin,
res=res,
method="cHs",
params=list(fm=x,distscale=NA,signline=NA,st=st),
headingAdjustment=headingAdjustment)
diffs <- diffInter(ints,hiResTacsat)[,"mean"]
pointsToRemove <- which(diffs <= quantile(diffs,probs=c(0.01),na.rm=T) | diffs >= quantile(diffs,probs=c(0.99),na.rm=T))
meddiffs <- median(diffs[-pointsToRemove],na.rm=T)
return(meddiffs)}
res <- optimize(optimInterpolation,interval=c(0,1),tol=0.0005)$minimum
return(res)}
#- Perform the tuning
#- There is no sensitivity to the 'st' parameter settings, as long as you use the same set of
# two numbers in all occasions
tunecHsInterpolation(lowResTacsat=VMSlf,hiResTacsat=VMShf,interval=120,margin=3,res=100,headingAdjustment=1,st=c(4,8.5))
#- Plot the result (remember, this is an example dataset which is extremely short :-))
ints <- interpolateTacsat(VMShf,
interval=120,
margin=3,
res=100,
method="cHs",
params=list(fm=0.236955,distscale=NA,signline=NA,st=c(4,8.5)),
headingAdjustment=0)
intsTC<- interpolation2Tacsat(ints,VMShf)
plot(intsTC$SI_LONG,intsTC$SI_LATI,type="l",xlab="Longitude",ylab="Latitude")
lines(VMShf$SI_LONG,VMShf$SI_LATI,col=2)
points(VMSlf$SI_LONG,VMSlf$SI_LATI,pch=19,cex=1,col="blue")
- VMStools introductory (i) course (5-9th of June 2023)
- Pi1: Getting the VMS and logbook data into R
- Pi2: Cleaning and processing the VMS and logbook data, and accounting for potential problems
- Pi3: Linking VMS and logbook data and exploring the benefits
- Pi4: How to link VMS, logbook data to spatial grids
- Pi5: Interpolation methods for VMS tracks
- Pi6: Calculating indicators at different spatial scales
- Pi7: The ICES datacall and working together across countries
- Pi8: How to link VMS data with other spatial datasets
- Pi9: Making pictures and tables
- VMS advanced (a) course (8-12 February 2021)
- VMStools workflow example scripts
- Benthis WP2