Skip to content

Instantly share code, notes, and snippets.

@jsta
Last active August 29, 2015 14:02
Show Gist options
  • Save jsta/5739b1bb48ffbd2dde53 to your computer and use it in GitHub Desktop.
Save jsta/5739b1bb48ffbd2dde53 to your computer and use it in GitHub Desktop.
calculate tidal statistics
library(Tides)
#generate date time sequence for 6 sec frequency series
dt<-read.table("clipboard",header=FALSE,colClasses=c("character","character","numeric","numeric"),col.names=c("Date","Time","wlev","stage"))
dt$DateTime<-as.POSIXct(paste(dt$Date,dt$Time),format="%Y%j %H%M")
dt2<-data.frame(dt$DateTime,dt$stage)
names(dt2)<-c("time","h")
dt2<-dt2[complete.cases(dt2),]
TidalCharacteristics(dt2,0.4,dtMax=1680)
plot(dt2$time,dt2$h,type="l",ylab="Stage (m, NAVD88",main="Salt08",xlab="")
abline(h=0.4,col="red")
#calculate monthly statistics
months<-seq(1:12)
months<-data.frame(months)
months<-months[2:12,]
months[12,1]<-c("1")
season<-rep(1:4,each=3)
season<-data.frame(season)
monthseason<-cbind(months,season)
test<-merge(monthseason,dt2,by.x="months",by.y="month",sort=FALSE)
test<-test[order(test$time),]
test$months<-factor(test$months,levels=c("1","2","3","4","5","6","7","8","9","10","11","12"))
test$season<-factor(test$season,levels=c("1","2","3","4"))
boxplot(test$h~test$months)
TidalCharacteristics(subset(test,months==11),0.4,dtMax=1680)
TidalCharacteristics(subset(test,months==12),0.4,dtMax=1680)
monthseason<-monthseason[order(monthseason$months),]
innfreq<-c("22.6","30.9","35.2","48.4","42.6","44.7","27.9","38.7","62.1","65.4","64.0","19.61")
monthseason$innfreq<-innfreq
plot(as.numeric(monthseason$months),monthseason$innfreq,type="b",lwd=1.5,axes=FALSE,ylim=c(0,65),xlab="Months (2003-2012)",ylab="% Innundation")
axis(side=1,at=c(seq(from=1,to=12,by=1)))
axis(side=2,at=c(seq(from=0,to=65,by=5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment