###COLLATION OF INFORMATION FROM ## url is http://www.weather.unisys.com/hurricane #data is perhaps used in Webster et al 2005; Emanuel 2005 #this has 5 basins (not SH) ##basin data for Atlantic is collated from 1851-2005; for WPAC from 1945-2003 ##there is uncollated data for individual storms up to date which requires ad hoc collation #Emanuel 2005 used data up to 2004; his reply to Landsea used data up to 2005; 2006 data is also collated here #collated data has following annoying format (uncollated data requires even more ad hoccery as described below) #script below reads into flat format and saves; still experimental #undoubtedly this could be made a little simpler; this has not been optimized in any sense and is a little slow, but since one-off doesn't matter #collated into two files for each basin #hurricane.ATL.tab - one record for each storm #Track.ATL.tab - one record for each measurement; measurements made per quarter day # id year qtr month day lat long wind press #00005 06/25/1851 M= 4 1 SNBR= 1 NOT NAMED XING=1 SSS=1 #00010 06/25*280 948 80 0*280 954 80 0*280 960 80 0*281 965 80 0* #00015 06/26*282 970 70 0*283 976 60 0*284 983 60 0*286 989 50 0* #00020 06/27*290 994 50 0*295 998 40 0*3001000 40 0*3051001 40 0* #00025 06/28*3101002 40 0* 0 0 0 0* 0 0 0 0* 0 0 0 0* #00030 HRBTX1 #00035 07/05/1851 M= 1 2 SNBR= 2 NOT NAMED XING=0 #00040 07/05* 0 0 0 0* 0 0 0 0*222 976 80 0* 0 0 0 0* #00045 HR #00050 07/10/1851 M= 1 3 SNBR= 3 NOT NAMED XING=0 #00055 07/10* 0 0 0 0* 0 0 0 0*120 600 50 0* 0 0 0 0* #00060 TS ##ESTABLISH URLs and IDs loc<-file.path("http://www.weather.unisys.com/hurricane", c("atlantic/tracks.atl","w_pacific/tracks.bwp","e_pacific/tracks.epa", "s_indian/tracks.bsh","indian_oc/tracks.bio") ) basin.id<-c("ATL","WPAC","EPAC","SIO","NIO") ###COLLATE AND SAVE INFORMATION FOR FIVE BASINS for (k in 1:length(loc)){ fred<-readLines(loc[k]) test<-substr(fred,7,8) temp<-as.numeric(test) temp<-is.na(temp); N<-sum(temp);N #1353 #same numner as Emanuel NN<-length(fred) x<-(1:NN)[temp]; y<-c(0,x[1:(N-1)])+1 test<-fred[is.na(match( (1:NN),c(x,y) ))] #length 103 nitem<- (x-y-1); sum(nitem) #10389 id<- 1:N hurricane<-data.frame(id); names(hurricane)<-"id" hurricane$year<-as.numeric(substr(fred[y],13,16)) hurricane$month_start<-as.numeric(substr(fred[y],7,8)) hurricane$day_start<-as.numeric(substr(fred[y],10,11)) hurricane$M<-as.numeric(substr(fred[y],20,21)) ##hurricane$SNBR<-as.numeric(substr(fred[y],31,34)) #same as ID hurricane$name<-substr(fred[y],36,47) hurricane$name<-gsub(" ","",hurricane$name) hurricane$XING<-as.numeric(substr(fred[y],53,53)) hurricane$SSS<-as.numeric(substr(fred[y],59,59)) hurricane$class<-substr(fred[x],7,8) hurricane$state<-substr(fred[x],9,11) hurricane$level<-as.numeric(substr(fred[y],12,12)) #I haven't determined the purpose of some of these fields yet or q.c'ed them Track<-NULL for ( i in 1:N) { test<-fred[ (y[i]+1):(x[i]-1)] M<-length(test) month<-as.numeric(substr(test,7,8)) day<-as.numeric(substr(test,10,11)) test1<-cbind( substr(test,13,28),substr(test,30,45),substr(test,47,62),substr(test,64,79)) test1<-c(t(test1)) track<-data.frame(as.numeric(substr(test1,1,3)));names(track)<-"lat" track$long<-as.numeric(substr(test1,4,7)) track$wind<-as.numeric(substr(test1,8,11)) track$press<-as.numeric(substr(test1,12,16)) track$month<- c(t( array( rep(month,M),dim=c(M,4)))) track$day<- c(t( array( rep(day,M),dim=c(M,4)))) track$qtr<- rep( 1:4, M) track$id<- rep(i,4*M) track$year<-rep(hurricane$year[i],M) track<-track[ !((track$lat==0)&(track$long==0)) ,] Track<-rbind(Track,track) } ##this is a little quality control to remove NA records and temp<-is.na(Track$month);sum(temp) if(sum(temp)>0) Track<-Track[!temp,] Track<-Track[,c(8,9,5,6,7,1,2,3,4)] ##this is an expedient to allocate January hurricanes to prior season if ((k==1)|(k==2)){temp<-(Track$month==1);sum(temp) Track$year[temp]<-Track$year[temp]-1;Track$month[temp]<-Track$month[temp]+12;} save(hurricane,file=file.path("c:/climate/data/hurricane",paste("hurricane",basin.id[k],"tab",sep=".") )) save(Track,file=file.path("c:/climate/data/hurricane",paste("Track",basin.id[k],"tab",sep=".") )) } Track[1,] # id year qtr month day lat long wind press #1 1 1851 1 6 25 280 948 80 0 hurricane[1,] #id year day_start month_start M name XING SSS class state level #1 1 1851 25 6 4 NOTNAMED 1 1 HR BTX NA ############### ##UPDATE AD HOC FOR WPAC AND ATLANTIC ####################### #this is for WPAC2004-2006 and ATL 2006; perhaps others will be done later ###PREIMINARY: #go to sites http://www.weather.unisys.com/hurricane/w_pacific http://www.weather.unisys.com/hurricane/atlantic #there is a table of storms; copy them into a text file labeled WPAC.2006.txt so that they can be read and analysed; messy but possible year0<-c(2004,2005,2006,2006);name0<-c(rep("WPAC",3),"ATL");basin0<-c(rep("w_pacific",3),"atlantic") for (i in 1:4) { load(file.path("c:/climate/data/hurricane",paste("hurricane",name0[i],"tab",sep="."))) K<-nrow(hurricane) test<-scan(file.path("c:/climate/data/hurricane",paste(name0[i],year0[i],"txt",sep=".")),skip=1,what="") temp<-(test=="Storm")|(test=="Typhoon")|(test=="Depression")|(test=="Hurricane");sum(temp) x<-(1:length(test))[temp]+1 id<-test[x] M<-length(id) dummy<-data.frame(array(NA,dim=c(M,11)));names(dummy)<-names(hurricane) dummy$id<- K+ (1:M) dummy$year<- year0[i] dummy$name<-id hurricane<-rbind(hurricane,dummy) save(hurricane,file=file.path("c:/climate/data/hurricane",paste("hurricane",name0[i],"tab",sep="."))) } ###TRACK DATA ## format is http://www.weather.unisys.com/hurricane/w_pacific/2005/KULAP/track.dat #ADV LAT LON TIME WIND PR STAT # 1 6.00 150.30 01/13/21Z 25 - TROPICAL DEPRESSION Track[1,] # id year qtr month day lat long wind press #1 1 1851 1 6 25 280 948 80 0 #little function to tidy " -" and change factor to numeric tidy<-function(x) { if(class(x) == "factor") {levels(x)[levels(x)==" -"] <-NA;tidy<- as.numeric(levels(x))[x]} else tidy<-x; tidy} for (i in 1:4) { load(file.path("c:/climate/data/hurricane",paste("Track",name0[i],"tab",sep="."))) K<-nrow(Track) load(file.path("c:/climate/data/hurricane",paste("hurricane",name0[i],"tab",sep="."))) temp<-(hurricane$year==year0[i]) M<-sum(temp) dummy<-NULL dummy.id<-hurricane$name[temp];dummy.number<-hurricane$id[temp] for (j in 1:M){ loc<-file.path("http://www.weather.unisys.com/hurricane",basin0[i],year0[i],dummy.id[j],"track.dat") test<-read.fwf(loc,widths=c(3,8,7,3,1,2,1,2,1,6,5),skip=3) test<-test[,c(1,2,3,4,6,8,10,11)] dimnames(test)[[2]]<-c("record","lat","long","month","day","qtr","wind","press") temp<-(test$qtr%%6 ==0)&!is.na(test$qtr) test<-test[temp,] test$year<-rep(year0[i],nrow(test)); test$id<-rep(dummy.number[j],nrow(test)) dummy<-test[,c(10,9,4,5,6,2,3,7,8)] dummy[,c("lat","long")]<-10*dummy[,c("lat","long")] #Track is in tenths if(i==4) dummy[,"long"]<- - dummy[,"long"] #keep in same Westings dummy[,"wind"]<-tidy(dummy[,"wind"]);dummy[,"press"]<-tidy(dummy[,"press"] ) #deals with - Track<-rbind(Track,dummy) } save(Track,file=file.path("c:/climate/data/hurricane",paste("Track",name0[i],"tab",sep="."))) } #MAKE TXT FILES k<-1#k<-2 #do this manually write.table(Track,file=file.path("c:/climate/data/hurricane",paste("Track",basin.id[k],"txt",sep=".")),sep="\t",quote=FALSE ) write.table(hurricane,file=file.path("c:/climate/data/hurricane",paste("hurricane",basin.id[k],"txt",sep=".")),sep="\t",quote=FALSE )