angle - How to calculate wind direction from U and V wind components in R -
i have u , v wind component data , calculate wind direction these values in r.
i end wind direction data on scale of 0-360 degrees, 0° or 360° indicating wind blowing north, 90° indicating wind blowing east, 180° indicating wind blowing south , 270° indicating wind blowing west.
below example data:
> dput(wind) structure(list(u_ms = c(-3.711, -2.2417, -1.8188, -1.6164, -1.3941, -1.0682, -0.57611, -1.5698, -1.4976, -1.3537, -1.0901, -0.60403, -0.70812, -0.49045, -0.39849, 0.17875, 0.48356, 1.5082, 1.4219, 2.5881), v_ms = c(-1.471, -1.6118, -1.6613, -1.7037, -1.7388, -1.8748, -1.8359, -1.6766, -1.6994, -1.7505, -1.4947, -0.96283, -1.1194, -0.6849, -0.7847, -0.80349, -0.19352, -0.97815, -1.0835, -0.81666), u_rad = c(-0.064769155, -0.039125038, -0.031744042, -0.028211496, -0.02433163, -0.018643603, -0.010055014, -0.027398173, -0.026138045, -0.023626517, -0.01902583, -0.01054231, -0.012359023, -0.008559966, -0.006954961, 0.003119775, 0.008439712, 0.02632305, 0.024816831, 0.045170857), v_rad = c(-0.025673788, -0.028131211, -0.028995149, -0.029735168, -0.030347779, -0.032721426, -0.032042493, -0.029262184, -0.029660119, -0.030551982, -0.026087431, -0.01680455, -0.019537212, -0.011953758, -0.013695596, -0.014023543, -0.00337756, -0.017071935, -0.018910639, -0.014253403)), .names = c("u_ms", "v_ms", "u_rad", "v_rad"), class = "data.frame", row.names = c(na, -20l))
i have used following code try , obtain wind direction (column td
), not convinced returned angles want (i.e. 0°/360° indicating wind blowing north, 90° indicating wind blowing east etc…).
u = wind$u_rad # u component in radians v = wind$v_rad # v component in radians d = (180/pi)*(atan2(u,v)) td = as.matrix(d + 180) df = cbind(wind, d, td) > df u_ms v_ms u_rad v_rad d td 1 -3.71100 -1.47100 -0.064769155 -0.02567379 -111.6228 68.37716 2 -2.24170 -1.61180 -0.039125038 -0.02813121 -125.7164 54.28357 3 -1.81880 -1.66130 -0.031744042 -0.02899515 -132.4087 47.59129 4 -1.61640 -1.70370 -0.028211496 -0.02973517 -136.5062 43.49379 5 -1.39410 -1.73880 -0.024331630 -0.03034778 -141.2788 38.72124 6 -1.06820 -1.87480 -0.018643603 -0.03272143 -150.3269 29.67308 7 -0.57611 -1.83590 -0.010055014 -0.03204249 -162.5780 17.42199 8 -1.56980 -1.67660 -0.027398173 -0.02926218 -136.8842 43.11576 9 -1.49760 -1.69940 -0.026138045 -0.02966012 -138.6118 41.38819 10 -1.35370 -1.75050 -0.023626517 -0.03055198 -142.2844 37.71557 11 -1.09010 -1.49470 -0.019025830 -0.02608743 -143.8963 36.10365 12 -0.60403 -0.96283 -0.010542310 -0.01680455 -147.8980 32.10204 13 -0.70812 -1.11940 -0.012359023 -0.01953721 -147.6830 32.31699 14 -0.49045 -0.68490 -0.008559966 -0.01195376 -144.3939 35.60607 15 -0.39849 -0.78470 -0.006954961 -0.01369560 -153.0774 26.92258 16 0.17875 -0.80349 0.003119775 -0.01402354 167.4578 347.45783 17 0.48356 -0.19352 0.008439712 -0.00337756 111.8112 291.81121 18 1.50820 -0.97815 0.026323050 -0.01707193 122.9656 302.96561 19 1.42190 -1.08350 0.024816831 -0.01891064 127.3077 307.30771 20 2.58810 -0.81666 0.045170857 -0.01425340 107.5128 287.51279
i appreciate advice on whether method correct, , if not how correctly obtain desired wind direction values. while calculating wind direction u , v components of wind using lapply or ifelse helpful, code did work data, , sure there easier away obtain wind direction. many thanks!
there 3 problems this:
- you cannot convert m/s radians. in order input wind components
atan2
, must normalize them, don't multiplying m/spi/180
(which didu_rad
,v_rad
). should make column of absolute windspeed (sqrt(u_ms^2 + v_ms^2)
) , takeatan2(u_ms/wind_abs, v_ms/wind_abs)
. (also note atan2 takes y component first - make sure that's want) atan2
give answer in unit circle coordinates, increase counterclockwise , have 0 on x-axis. want answer in cardinal coordinates increase clockwise , have 0 on y-axis. convert unit circle cardinal coordinates, must subtract unit circle angle 90.- you must know whether wind info refers direction wind coming (standard cardinal coordinates) or direction wind blowing (standard trig/vector operations)
if given u_ms = = -3.711
, v_ms = -1.471
(on unit circle blowing down , left, coming northeast), then:
wind_abs = sqrt(u_ms^2 + v_ms^2) wind_dir_trig_to = atan2(u_ms/wind_abs, v_ms/wind_abs) wind_dir_trig_to_degrees = wind_dir_trig_to * 180/pi ## -111.6 degrees
then must convert wind vector meteorological convention of direction wind coming from:
wind_dir_trig_from_degrees = wind_dir_trig_to_degrees + 180 ## 68.38 degrees
then must convert angle "trig" coordinates cardinal coordinates:
wind_dir_cardinal = 90 - wind_dir_trig_from_degrees [1] 21.62284 #from northeast.
Comments
Post a Comment