-
Notifications
You must be signed in to change notification settings - Fork 14
/
TSS_CSVexample.R
65 lines (51 loc) · 2.23 KB
/
TSS_CSVexample.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
# Set the woking diroctory to the location
# this.dir <- dirname(parent.frame(2)$ofile)
# setwd(this.dir)
# install the devtools package (contains the install_github)
# install.packages("devtools")
# library("devtools")
library("lineprof")
# install_github("ArdenB/SegmentedRESTREND_pub", subdir="TSS.RESTREND")
# library(TSS.RESTREND)
#Import the .csv that contains the monthly Vegetation data
# in.VI = read.csv("./demo_data/rabitVI.csv")
# in.VI = read.csv("./demo_data/mungoVI.csv")
# in.VI = read.csv("./demo_data/darlingVI.csv")
# in.VI = read.csv("./demo_data/desertVI.csv")
# in.VI = read.csv("./demo_data/southwaVI.csv")
in.VI = read.csv("./demo_data/chow2VI.csv")
# in.VI = read.csv("./demo_data/failVI.csv")
# turn that data into a time series object.
#Starts january 1982 and ends december 2013 with a
#monthly frequency (frequency = 12)
CTSR.VI = ts(in.VI, start=c(1982, 1), end=c(2013,12), frequency = 12)
# Import the associated rainfall series
# Note that the rainfall sequences is longer to allow for the
# accumulation period and the offset period. The start dates vary but the
# end dates are the same.
# in.RF = read.csv("./demo_data/rabitRF.csv")
# in.RF = read.csv("./demo_data/mungoRF.csv")
# in.RF = read.csv("./demo_data/darlingRF.csv")
# in.RF = read.csv("./demo_data/desertRF.csv")
# in.RF = read.csv("./demo_data/southwaRF.csv")
in.RF = read.csv("./demo_data/chow2RF.csv")
# in.RF = read.csv("./demo_data/failRF.csv")
#turn the data into a time series object
rf.data=ts(in.RF,end=c(2013,12),frequency = 12)
# Define the max accumuulation period
max.acp <- 12
#Define the max offset period
max.osp <- 4
#Create a table of every possible precipitation value given the max.acp and max.osp
ACP.table <- climate.accumulator(CTSR.VI, rf.data, max.acp, max.osp)
#save this data out
# rabbitACPtable <- ACP.table
# # rabbitACPtable <- iconv(rabbitACPtable, "latin1", "ASCII", sub="")
# save(rabbitACPtable, file = "./TSS.RESTREND/data/rabbitACPtable.rda")
#
# # check the ACP.table is the right shape
# print(dim(ACP.table))
#Pass the ACP.table and the CTSR.VI to the TSS.RESTREND
results <- TSSRESTREND(CTSR.VI, ACP.table)
print(results$summary)
# plot(results, verbose=TRUE)