Takes u/v wind components (zonal and meridional wind components) as input and returns wind speed and meteorological wind direction.

uv2ddff(u, v = NULL, rad = FALSE)

Arguments

u

numeric vector with u components or a data.frame or zoo object containing a column named u and a column named v.

v

NULL (default) or numeric vector. If input u is a single vector v has to be specified.

rad

logical, default is FALSE. Returns wind direction in radiant rather than degrees.

Value

Returns a data.frame or zoo object (depending on input u) with two columns named dd

and ff containing wind speed (same physical unit as input u/v) and wind direction. Wind direction is either in meteorological degrees (0 from North, from 90 East, 180 from South, and 270 from West) or in mathematical radiant if input rad = TRUE.

Details

Note: if both, u and v are provided they do have to be of the same length OR one of them has to be of length 1. The one with length 1 will be recycled.

See also

ddff2uv

Author

Reto Stauffer

Examples

## Generate data.frame with u/v components for all 4 main wind directions
data <- data.frame(name = c("N","E","S","W"),
                   u    = c( 0, -1 , 0,  1 ),
                   v    = c(-1,  0,  1,  0 ))
## Use data.frame input
ddff <- uv2ddff(data)
cbind(data, ddff)
#>   name  u  v  dd ff
#> 1    N  0 -1 360  1
#> 2    E -1  0  90  1
#> 3    S  0  1 180  1
#> 4    W  1  0 270  1
## Use u/v components as two separate vector inputs
ddff <- uv2ddff(data$u, data$v)
cbind(data, ddff)
#>   name  u  v  dd ff
#> 1    N  0 -1 360  1
#> 2    E -1  0  90  1
#> 3    S  0  1 180  1
#> 4    W  1  0 270  1
## Radiant
ddff <- uv2ddff(data, rad = TRUE)
cbind(data, ddff)
#>   name  u  v       dd ff
#> 1    N  0 -1 6.283185  1
#> 2    E -1  0 1.570796  1
#> 3    S  0  1 3.141593  1
#> 4    W  1  0 4.712389  1

## Use with zoo
library("zoo")
set.seed(100)
Sys.setenv("TZ" = "UTC")
data <- zoo(data.frame(u = rnorm(20, 2, 5), v = rnorm(20, 0, 4)),
            as.POSIXct("2019-01-01 12:00") + 0:19 * 3600)
head(data)
#>                              u         v
#> 2019-01-01 12:00:00 -0.5109618 -1.752360
#> 2019-01-01 13:00:00  2.6576558  3.056242
#> 2019-01-01 14:00:00  1.6054146  1.047845
#> 2019-01-01 15:00:00  6.4339240  3.093618
#> 2019-01-01 16:00:00  2.5848564 -3.257516
#> 2019-01-01 17:00:00  3.5931504 -1.753802
class(data)
#> [1] "zoo"
## Calculate dd/ff
ddff <- uv2ddff(data)
head(ddff)
#>                            dd       ff
#> 2019-01-01 12:00:00  16.25589 1.825335
#> 2019-01-01 13:00:00 221.00966 4.050155
#> 2019-01-01 14:00:00 236.86774 1.917116
#> 2019-01-01 15:00:00 244.32039 7.139037
#> 2019-01-01 16:00:00 321.56782 4.158473
#> 2019-01-01 17:00:00 296.01682 3.998319
class(ddff)
#> [1] "zoo"