data/FrenchGuiana/selecting.data.FG.R

## organizing the FG rainfall data

fg <- read.csv("pluv.csv")

with(fg,table(Day,Year))

## there's a 366th day?  ohh a leap year?

fg[which(fg$Day==366),]

## doesn't matter.  go 60 days from each day 309:
##(from Regis: we will run the experiment from November 6th 2012 (day
## 309 in the xls file) to January 5th (day 5).

which(fg$Day==309)
## 309+365
## 309+365+365
## 309+365+365+366 #2008
## 309+365+365+366+365

## looks OK. We can't use the last start date, because we don't have a
## following year:

starts <- which(fg$Day==309)

starts <- starts[-length(starts)]

ends <- which(fg$Day==3)  ## JAN 3RD!!!!!!
ends <- ends[-1]
ends-starts

## one is too long, because the 5th of November was the 310th day in
## 2008

unique(fg$Year) # the third year

starts[3] <- starts[3]+1

ends-starts

## confused.  add 60 to Nov 6th always gives you Jan 5th:
as.Date("2012-11-06")+59

## but subtracting jan 5th from Nov 6th always gives 61! 

ss <- mapply(seq,from=starts,to=ends,by=1,SIMPLIFY=FALSE)

## I think it has to do with open and closed intervals.
## i have decided to use the dates from 6 Nov to 3 Jan INCLUSIVE (this
## is what seq does above).  note that this produces intervals of 60 days:

lapply(ss,length)



test <- fg[do.call(c,ss),]
table(test$Year)
dim(test)

test2 <- cbind(start.year=rep(unique(fg$Year)[1:4],sapply(ss,length)),test)


test2.list <- split(test2[["Rainfall..mm."]],test2$start.year)

ppt <- do.call(cbind,test2.list)

dim(ppt)

write.csv(ppt,file="Ppt.French.Guiana.csv",row.names=FALSE)


## just out of curosity, lets see the rainfall over the year:
fg.list <- split(fg,fg$Year)

pdf("FG.rain.pdf",height=4)
par(cex=0.5)
layout(mat=matrix(1:6,nrow=2,ncol=3))
lapply(fg.list,function(z){
  plot(z[["Rainfall..mm."]]~z[["Day"]],main=unique(z[["Year"]]),
       xlab="day of year",ylab="precipitation",cex=0.5,type='l')
  lines(lowess(z[["Day"]],z[["Rainfall..mm."]],f=0.05))
  if(unique(z[["Year"]]!=2009)) abline(v=309,col="red")
  if(unique(z[["Year"]]!=2006)) abline(v=3,col="blue")
})
dev.off()
benmarwick/precipitation_experiment_schedule_package documentation built on May 12, 2019, 1:02 p.m.