Skip to content
Tim Lam edited this page Sep 30, 2021 · 23 revisions

Installation of R and geolocation packages

  • Please understand that R is being very rapidly developed and geolocation packages may sometimes lag in catching up with the fundamental changes made in R.

  • We just completed updates to support ncdf4 and R.4.1.1. Let us know if you have experienced any issues.

Easy installation of geolocation packages

  • To make installation a bit easier, a script has been prepared to set up all required packages. To run it, fire up R and type (or paste) the following:
  if (!any('devtools' == installed.packages()[,"Package"])){
  install.packages('devtools', repos="http://cran.rstudio.com/")}
  require(devtools)
  source_url("https://raw.githubusercontent.com/positioning/kalmanfilter/master/install.r")

  ### Optional install analyzepsat as well
  # devtools::install_github('galuardi/analyzepsat', dep = T, ref = 'v4.0')  

It is best to...

  • Inform yourself with an overview of the geolocation methods:

http://www.soest.hawaii.edu/PFRP/nov07mtg/nielsen.pdf

Conducting an example run of different geolocation packages

  • Start up R, copy-and-paste lines or block of code to run the commands

  • Kftrack

# Note: delete the hash sign (#) at the beginning to uncomment a line

library(kftrack)

data(big.241) # load packaged example data

track <- big.241
#track<-read.table("datafile.dat", header=TRUE) # change file name and path for your own file

fit1 <-kftrack(track)
fit1 # inspect model parameters

plot(fit1, map=FALSE, ci=TRUE)
save(fit1, file="kf-example.Rdata")
# Note: delete the hash sign (#) at the beginning to uncomment a line

library(ukfsst)
#library(kfsst)

data(blue.shark) # load packaged example data
#track<-read.table("datafile.dat", header=TRUE) # change file name and path for your own file

sst.path<- suppressWarnings(get.sst.from.server(blue.shark))
#sst.file<-write.sst.field(sst.path) # only used in kfsst

track <- blue.shark # delete this line when you use your own data
fit2<- kfsst(track, bx.a=F, bsst.a=F)
fit2 # inspect model parameters

plot(fit2, map=FALSE, ci=TRUE)
save(fit2, file="kf-example.Rdata")
# Note: delete the hash sign (#) at the beginning to uncomment a line

library(trackit)
data(gmt3); data(deltat); deltat$JDE = with(deltat,JDE(year,month,day))
  
data(drifter) # load packaged example data
#track<-read.table("datafile.dat", header=TRUE) # change file name and path for your own file
prep.track<-prepit(drifter, fix.first=c(360-161.45,22.85,2002,9,10,0,0,0), 
                   fix.last=c(360-159.87,21.95,2003,5,21,0,0,0), scan=FALSE)
 
fit3<-trackit(prep.track, D.ph=2)
print.trackit(fit3) # inspect model parameters

plot.trackit(fit3)
fitmap(fit3, ci=T)
points(fit3$most.prob.track, pch=20)
save(fit3, file="kf-example.Rdata")

Exporting results from R

Assume we have run our tracks successfully, and everything is in an active R session, we can output the tracks for other programs.

  • Download the export script for R, fit2csv (Right-click to "save link/ file as")

  • Make sure you note where you save the downloaded file. Drag-and-drop the file into the main R window, or use the function, source

# Note: delete the hash sign (#) to uncomment a line

# Preparation; find out/ define your working directory:

getwd()
# setwd("C:/Test") # give path to your desired output directory

# Main code:

source("fit2csv.R") # make sure R knows where the file is located,
                    # or move fit2csv.R to the working directory, as shown above
fit2csv(fit1)
fit2csv(fit2)
  • A set of output files (e.g fit1a.csv, fit1b.csv, fit1c.csv) will be generated for each tag. The output files are:
    1. -a.csv - track points
    2. -b.csv - model parameters
    3. -c.csv - initialization values to model