I have two raster stack files ur
and vr
with u and v component of wind speed respectively.
How can I calculate average wind speed and direction in each grid cell ?
I know I can calculate wind direction using following equation
windir<-calc(atan2(vwind, uwind) * 360/2/pi) + 180
and average wind using
winav<- ((mean.u^2 + mean.v^2)^0.5)
My problem is how can I implement these equations on each grid cells of ur
and vr
I referred to this question and other links however still stocked in this calculation.
With RasterStack
s vr
and ur
vr <- stack(system.file("external/rlogo.grd", package="raster"))
ur <- flip(vr, 'y')
You can indeed use your formulas:
windir <- atan2(vr, ur) * 180/pi + 180
winav <- (ur^2 + vr^2)^0.5
Alternatively, you can use overlay
windir2 <- overlay(vr, ur, fun=function(x,y) atan2(x,y) *180/pi + 180)
winav2 <- overlay(vr, ur, fun=function(x, y) (x^2 + y^2)^0.5 )