Created
February 17, 2017 23:16
-
-
Save ytmytm/08b265f91029956caf4d71883367082a to your computer and use it in GitHub Desktop.
Mean direction and mean strength of wind by vector addition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# circular means by using vector method #### | |
# from http://math.stackexchange.com/questions/44621/calculate-average-wind-direction | |
circmean <- function(ws,wd,na.rm=TRUE) { | |
V_east = mean(ws*sin(wd * pi/180),na.rm=na.rm) | |
V_north = mean(ws*cos(wd * pi/180),na.rm=na.rm) | |
mean_WD = atan2(V_east, V_north) * 180/pi | |
mean_WD = (360 + mean_WD) %% 360 | |
return(mean_WD) | |
} | |
circlength <- function(ws,wd,na.rm=TRUE) { | |
V_east = mean(ws*sin(wd * pi/180),na.rm=na.rm) | |
V_north = mean(ws*cos(wd * pi/180),na.rm=na.rm) | |
mean_WS = sqrt(V_east^2+V_north^2) | |
return(mean_WS) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input
ws = vector = wind speed (any units)
wd = vector = wind direction (0-359 degrees)
Output:
scalar mean wind direction (0-359 degrees), mean wind speed