Converts wind direction (dd
) and wind speed (ff
)
information into u
/v
wind components (zonal and
meridional wind component).
ddff2uv(dd, ff = NULL)
only necessary if ff
is a numeric vector. Use NULL if
input ff
is containing both variables (ff
, dd
), else
dd
is a data vector containing the wind direction in degrees (0:
north, 90: east, ...)
numeric
, matrix
, data.frame
, or
zoo
object (see 'Details' section).
Returns a data.frame
or zoo
object (depending on input ff
)
containing the u
and v
components
of the data. In addition, rad
(mathematical representation
of wind direction in radiant) is returned.
Converts data from wind speed and direction into the zonal
and meridional wind components (u
/v
).
Different inputs are allowed:
if ff
is a matrix: requires to contains at least the
two columns "ff"
and "dd"
.
if ff
is a data.frame
or zoo
object:
requires to contains at least the
two variables "ff"
and "dd"
.
if ff
is numeric
: dd
has to be provided
in advance. ff
and dd
have to be of the same length
or one has to be of length 1
(will be recycled).
uv2ddff
## Generate dd and ff variable
set.seed(0)
ff <- floor(abs(rnorm(20))*10)
dd <- sample(seq(0,359),20)
df <- data.frame('ff'=ff,'dd'=dd)
## Using with vectors
print(head(ddff2uv('dd' = dd, 'ff' = ff)))
#> u v rad
#> 1 6.180457 -10.286008 -1.029744
#> 2 -1.968177 -2.264129 3.996804
#> 3 -12.216004 4.446262 2.792527
#> 4 -3.906818 -11.346223 4.380776
#> 5 -2.727993 -2.925415 3.961897
#> 6 4.635255 -14.265848 -1.256637
## Using with data.frame
print(head(ddff2uv(df)))
#> u v rad
#> 1 6.180457 -10.286008 -1.029744
#> 2 -1.968177 -2.264129 3.996804
#> 3 -12.216004 4.446262 2.792527
#> 4 -3.906818 -11.346223 4.380776
#> 5 -2.727993 -2.925415 3.961897
#> 6 4.635255 -14.265848 -1.256637
## Using with matrix
print(head(ddff2uv(as.matrix(df))))
#> u v rad
#> 1 -68.402946 -321.81056 4.502949
#> 2 -2.145774 -40.94381 4.660029
#> 3 -24.744616 -107.18071 4.485496
#> 4 -3.950322 -18.58480 4.502949
#> 5 -2.999528 -42.89525 4.642576
#> 6 -88.516113 -330.34663 4.450590
## Use with zoo
library("zoo")
set.seed(100)
Sys.setenv("TZ" = "UTC")
data <- zoo(data.frame(dd = runif(20, 0, 360), ff = rnorm(20, .2, 2)^2),
as.POSIXct("2019-01-01 12:00") + 0:19 * 3600)
data <- round(data,2)
head(data)
#> dd ff
#> 2019-01-01 12:00:00 110.80 0.14
#> 2019-01-01 13:00:00 92.76 0.15
#> 2019-01-01 14:00:00 198.84 0.04
#> 2019-01-01 15:00:00 20.30 2.82
#> 2019-01-01 16:00:00 168.68 0.20
#> 2019-01-01 17:00:00 174.16 0.02
class(data)
#> [1] "zoo"
## Calculate dd/ff
uv <- ddff2uv(data)
head(uv)
#> u v rad
#> 2019-01-01 12:00:00 -0.130875595 0.049714975 2.778564
#> 2019-01-01 13:00:00 -0.149826000 0.007222869 3.093422
#> 2019-01-01 14:00:00 0.012917060 0.037856962 1.241976
#> 2019-01-01 15:00:00 -0.978358537 -2.644846796 4.358087
#> 2019-01-01 16:00:00 -0.039257686 0.196109240 1.768368
#> 2019-01-01 17:00:00 -0.002035017 0.019896198 1.672724
class(uv)
#> [1] "zoo"