forked from Eli-S-Bridge/NAOC_Geos_2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalibration.R
127 lines (90 loc) · 4.97 KB
/
Calibration.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
#Geolocation analysis with Open Source Tools
#2016 North American Ornithological Congress, Washington D.C.
#Sponsored by:
#Migrate Technology LLC.-- www.migratetech.co.uk
#The Cooper Ornithological Society
#The National Science Foundation
#--------------------------------------------------------------
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
#--------------------------------------------------------------
#Calibrating for geolocator analyses
library(SGAT)
library(BAStag)
library(FLightR)
#start by reading in a data set consisting of twilight times
twl <- read.csv("data/749_twl.csv")
#we need the data in tFirst/tSecond format
twl <- data.frame(tFirst = twl$datetime[1:(nrow(twl)-1)],
tSecond = twl$datetime[2:nrow(twl)],
type = abs(twl$Rise[1:(nrow(twl)-1)]-2))
#format the date columns
twl$tFirst <- as.POSIXct(twl$tFirst, "UTC")
twl$tSecond <- as.POSIXct(twl$tSecond, "UTC")
#Lets say we know the bird stayed put for about 3 weeks after tag deployment.
#We can establish a subset of the twilight data for just those three weeks,
#from the start date (2011-06-15) to 2011-07-06
calib1 <- subset(twl, tFirst < as.POSIXct("2011-07-06", "UTC"))
#Define the coordinates of the tag for the calibration period (lon and lat)
start <- c(-80.46, 42.62)
#You can use getElevation() in GeoLight to get the median sun angle for
#the twilights in your calibration period
library(GeoLight)
cal1 <- getElevation(twl = calib1, known.coord = start, plot = T)
cal1
#You can now use GeoLight functions to get a first look at location data on a map
#Calculate coordinates for a track and run tripmap
track <- coord(twl = twl, degElevation = cal1, tol = 0,
method = "NOAA", note = TRUE)
tripMap(track, equinox = TRUE, xlim = c(-90,-70), ylim = c(10,50), legend = TRUE)
#--------------------------------------------------------------
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
#--------------------------------------------------------------
#You can also choose a calibration period from a light image
library("TwGeos") #open the BAStag package
d.lux <- readLig("data/749_000.lig", skip = 0) #read the data into a dataframe called d.lux
d.lux <- subset(d.lux,select=c("Date","Light")) #reduce the dataframe to just Date and Light
offset = 19
### Plot your light data with predicted twilight times assuming bird was stationary at deployment site for entire year
lightImage(d.lux, offset = offset)
### Leave plot from above open. The locator function can be used click on the outer boundaries of the calibration
### period. Once you run code below, you get a target cursor. First click defines the start
### of the calibration period, second click defines the end. User can define calibration period however they choose.
### Choice will affect resulting twilight error distribution.
tm.calib <- as.POSIXct(locator(n=2)$x, origin = "1970-01-01")
### See results of your selection
tm.calib
calib1 <- subset(twl, tFirst > tm.calib[1] & tFirst < tm.calib[2])
#You can now repeat the steps above to get a sun angle and a quick track
cal1 <- getElevation(twl = calib1, known.coord = start, plot = T)
cal1
track <- coord(twl = twl, degElevation = cal1, tol = 0,
method = "NOAA", note = TRUE)
tripMap(track, equinox = TRUE, xlim = c(-90,-70), ylim = c(10,50), legend = TRUE)
#--------------------------------------------------------------
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
#--------------------------------------------------------------
#What if you are not sure what data are good for calibrating?
#Here's a process that uses FlightR to delineate good calibration periods
library(FLightR)
Proc.data<-get.tags.data("data/A2_FLightR_twl.csv") #opens and formats data straight from TAGS formatted csv file
start=c(5.43, 52.93) #tracking orgin, start location longitude and latitude
plot.slopes.by.location(Proc.data=Proc.data, location=start)
#Use abline to visualize potential calibration periods
abline(v=as.POSIXct("2013-08-23")) # end of first calibration period
abline(v=as.POSIXct("2014-05-05")) # start of the second calibration period
# Next create a data.frame with a separate line is designated for each calibration period.
# The columns are:
# (1) start of the calibration period,
# (2) end of the calibration period,
# (3) longitude of the calibration location and,
# (4) latitude of the calibration location.
Calibration.periods<-data.frame( #This will create two lines of data
calibration.start=as.POSIXct(c(NA, "2014-05-05")),
calibration.stop=as.POSIXct(c("2013-08-23", NA)),
lon=5.43, lat=52.93) #use c() also for the geographic coordinates, if you have more than one calibration location (e. g., lon=c(5.43, 6.00), lat=c(52.93,52.94))
#View results
Calibration.periods
#create a calibration object
Calibration<-make.calibration(Proc.data, Calibration.periods)
#save it for later use
save(Calibration, file = "data/FLightR_calibration")