uv2ddff: Convert u and v Wind Components to Wind Speed and Wind...

View source: R/wind_functions.R

uv2ddffR Documentation

Convert u and v Wind Components to Wind Speed and Wind Direction

Description

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

Usage

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.

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.

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.

Author(s)

Reto Stauffer

See Also

ddff2uv

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)
## Use u/v components as two separate vector inputs
ddff <- uv2ddff(data$u, data$v)
cbind(data, ddff)
## Radiant
ddff <- uv2ddff(data, rad = TRUE)
cbind(data, ddff)

## 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)
class(data)
## Calculate dd/ff
ddff <- uv2ddff(data)
head(ddff)
class(ddff)


retostauffer/Rfoehnix documentation built on June 5, 2023, 11:39 p.m.