-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpull_hist_weather.R
39 lines (30 loc) · 1.52 KB
/
pull_hist_weather.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
library(RCurl)
startdate = as.Date("2014/03/01")
enddate = as.Date("2014/04/30")
firstpart = "https://www.wunderground.com/history/airport/EGFF/"
lastpart = "/DailyHistory.html?req_city=Cardiff&req_state=&req_statename=United+Kingdom&reqdb.zip=00000&reqdb.magic=1&reqdb.wmo=03717&format=1"
##weather_data = read.csv(paste(firstpart,date,lastpart))
hist_weather_data = list()
load("hist_weather_data.Rdata")
start = i
for (i in start:(enddate-startdate)) {
print(i)
date2 = gsub("-","/", startdate+i)
met.url = paste(firstpart,date2,lastpart,sep="")
# system(paste0("cd met; wget ",met.url))
x = getURL(met.url)
hist_weather_data[[i+1]] = read.csv(text=x)
save(i,hist_weather_data,file="hist_weather_data.Rdata")
}
hist_wind = unlist(sapply(hist_weather_data,function(x){x$Wind.SpeedMPH},simplify = TRUE))
hist_pres = unlist(sapply(hist_weather_data,function(x){x$Sea.Level.PressureIn},simplify = TRUE))
hist_pres[hist_pres < 5] = NA
dateUTC = unlist(sapply(hist_weather_data,function(x){x$DateUTC},simplify = TRUE))
day = strptime(sub(pattern = "<br />","",as.character(dateUTC)),format="%Y-%m-%d %T")
#met = Reduce(function(...) merge(...,all=TRUE),weather_data)
jpeg(file="~/SURGE/web/HistoricalWindSpeed.jpg")
plot(day,hist_wind, ylab="Wind Speed (mph)", xlab="Date", main="Historical Wind Speed in Cardiff, UK",type='l')
dev.off()
jpeg(file="~/SURGE/web/HistoricalSeaLevelPressure.jpg")
plot(day,hist_pres, ylab="Sea Level Pressure (in)", xlab="Date", main="Historical Sea Level Pressure in Cardiff, UK",type='l')
dev.off()