Function to calculate model wind direction
Examples
times <- seq(as.POSIXct('2024-01-01',tz = 'UTC'),
as.POSIXct('2024-01-02',tz = 'UTC'),
by = 'hour')
U10 = data.frame(times = times,
test1 = c(3.29,2.07,1.96,2.82,3.73,
4.11,4.96,6.33,7.39,7.59,
7.51,7.22,6.81,6.43,5.81,
4.02,3.03,2.68,2.40,2.20,
2.09,1.95,1.66,1.39,1.4),
test2 = c(6.29,4.87,6.16,7.12,8.77,
10.16,10.85,11.45,11.21,11.04,
11.09,10.67,10.48,10.00,8.96,
6.36,5.62,5.83,5.83,5.25,
4.11,3.08,2.26,1.14,-0.10))
V10 = data.frame(times = times,
test1 = c(-8.87,-4.23,-2.81,-2.59,-4.58,
-4.80,-5.33,-5.86,-6.12,-6.13,
-6.11,-5.76,-5.91,-5.60,-5.09,
-3.33,-2.50,-2.29,-2.14,-2.07,
-1.95,-1.97,-2.04,-2.03,-1.9),
test2 = c(11.80,5.88,5.74,5.56,6.87,
8.39,8.68,8.33,7.90,7.42,
6.96,6.87,6.36,5.61,5.16,
4.16,4.25,4.59,4.51,3.90,
2.97,1.98,1.04,-0.08,-0.44))
uv2wd(u = U10, v = V10)
#> calculating wind direction...
#> times test1 test2
#> 1 2024-01-01 00:00:00 339.6495 208.05988
#> 2 2024-01-01 01:00:00 333.9246 219.63262
#> 3 2024-01-01 02:00:00 325.1039 227.02136
#> 4 2024-01-01 03:00:00 312.5656 232.01376
#> 5 2024-01-01 04:00:00 320.8403 231.92654
#> 6 2024-01-01 05:00:00 319.4282 230.45054
#> 7 2024-01-01 06:00:00 317.0593 231.34019
#> 8 2024-01-01 07:00:00 312.7920 233.96370
#> 9 2024-01-01 08:00:00 309.6297 234.82658
#> 10 2024-01-01 09:00:00 308.9258 236.09490
#> 11 2024-01-01 10:00:00 309.1312 237.88793
#> 12 2024-01-01 11:00:00 308.5823 237.22408
#> 13 2024-01-01 12:00:00 310.9528 238.74768
#> 14 2024-01-01 13:00:00 311.0532 240.70757
#> 15 2024-01-01 14:00:00 311.2208 240.06267
#> 16 2024-01-01 15:00:00 309.6369 236.81178
#> 17 2024-01-01 16:00:00 309.5254 232.90242
#> 18 2024-01-01 17:00:00 310.5131 231.78639
#> 19 2024-01-01 18:00:00 311.7223 232.27500
#> 20 2024-01-01 19:00:00 313.2562 233.39293
#> 21 2024-01-01 20:00:00 313.0153 234.14708
#> 22 2024-01-01 21:00:00 315.2923 237.26477
#> 23 2024-01-01 22:00:00 320.8639 245.28920
#> 24 2024-01-01 23:00:00 325.5994 274.01418
#> 25 2024-01-02 00:00:00 323.6156 12.80427