1

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.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
Lily Nature
  • 613
  • 7
  • 18
  • Note that calculating an average wind direction is not that straightforward. See e.g. https://math.stackexchange.com/questions/44621/calculate-average-wind-direction – Bart Dec 17 '17 at 09:28

1 Answers1

3

With RasterStacks 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 )
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63