Hi all!
A researcher asked
me last week about how to compute wind average for an
area using rWind. I wrote a simple function to do this using dplyr
library (following the advice of my friend Javier Fajardo). The function will be added to
rWind package as soon as possible. Meanwhile, you can test the
results... enjoy!
# First, charge the new function
library(dplyr)
wind.region <- function (X){
X[,3] <- X[,3] %% 360
X[X[,3]>=180,3] <- X[X[,3]>=180,3] - 360
avg<-summarise_all(X[,-1], .funs = mean)
wind_region <- cbind(X[1,1],avg)
return(wind_region)
}
Once you have charged the function, let’s do an example...
# Get some wind data and convert it into a raster to be plotted later
library(rWind)
library(raster)
wind_data<-wind.dl(2015,2,12,0,-10,5,35,45)
wind_fitted_data <- wind.fit(wind_data)
r_speed <- wind2raster(wind_fitted_data, type="speed")
Now, you can use the new function to obtain wind average in the study area:
myMean <- wind.region(wind_data)
myMean
# Now, you can use wind.fit to get wind speed and direction.
myMean_fitted <- wind.fit(myMean)
myMean_fitted
# Finally, let's plot the results!
library(rworldmap)
library(shape)
plot(r_speed)
lines(getMap(resolution = "low"), lwd=4)
alpha <- arrowDir(myMean_fitted)
Arrowhead(myMean_fitted$lon, myMean_fitted$lat, angle=alpha,
arr.length = 2, arr.type="curved")
text(myMean_fitted$lon+1, myMean_fitted$lat+1,
paste(round(myMean_fitted$speed,2), "m/s"), cex = 2)
Hi,
ResponderEliminaram I correct that wind.fit converts the original wind direction (where wind is coming from) to where wind is blowing to, i.e. adding 180 degrees?
Cheers,
Le
Hi Le!
ResponderEliminarWell, not exactly.
With wind.dl you obtain wind parameters in a vectorial way (the formal way to express wind values) in two components (vectors) U and V. With wind.fit function, you transform this U and V components through trigonometry into wind direction and wind speed. This direction and speed means "where the wind is blowing to".
Don't know if this is enough for your question... here there are some documentation about this kind of transformations:
http://colaweb.gmu.edu/dev/clim301/lectures/wind/wind-uv
http://tornado.sfsu.edu/geosciences/classes/m430/Wind/WindDirection.html
Cheers