-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_TC_gusts_per_cyclone.r
50 lines (45 loc) · 1.77 KB
/
get_TC_gusts_per_cyclone.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
# function to extract gusts from a BoM dataset at a usr-provided time
# keeping track of the cyclone which orginated those gust winds.
# (called from program 'tc_TC_wnds_stns.r')
get_TC_gusts_per_cyclone = function(obs_gusts, ST, datetime, pressure, cyclone){
#bom_dset = name of BoM-provided wind dataset
#ST = state where dataset is located
#date = date at which TC hit the station
#time = corresponding time
#cyclone = Cyclone name
#open dataset:
#obs_gusts <- read.csv(bom_dset, skip = 1, header = FALSE)
#Read Local Standard Time (LST) in BoM dataset:
#build the LST datetime string:
obs_datetime1 <- obs_gusts$datetime #ISOdatetime(ds_yr, ds_m, ds_d, ds_hr, ds_min, sec = 0, tz = "GMT")
#Transform LST to UTC time (to match TC dataset):
if (ST == "WA") {
obs_datetime <- obs_datetime1 - 8.*3600
}else if (ST == "NT") {
obs_datetime <- obs_datetime1 - 9.5*3600
}else{
obs_datetime <- obs_datetime1 - 10*3600
}
tcdt = strptime(datetime$V8, format = "%Y-%m-%d %H:%M:%S", tz = "GMT")
if (max(tcdt) < min(obs_datetime)) {
#print(paste("No obs available for cyclone: ", as.character(cyclone[1,1]), ": ", max(tcdt)))
return(NA)
}
obsidx = c()
for (i in 1:length(tcdt)) {
dtm = tcdt[i] - 3600
dtp = tcdt[i] + 5400
idx = which((obs_datetime >= dtm) & (obs_datetime <= dtp))
obsidx = append(obsidx, idx, after = length(obsidx))
}
#rint("Select only wind records at given times")
wnd_gusts <- obs_gusts[(obsidx),]
if (length(wnd_gusts$station) < 1) return(NA)
#Build up vector of name to match wnd_gusts:
NN <- cyclone[1,1]
cycl_name <- c()
cycl_name[1:length(wnd_gusts$station)] <- as.character(NN)
#Return cyclonic wind speeds (same format as BoM dataset) plus cyclone name in last column:
#print(paste("Return cyclonic wind speeds for ", as.character(NN)))
cbind(wnd_gusts, cycl_name)
}