ddff2uv: Convert Wind Speed and Wind Direction to u/v Wind Components

View source: R/wind_functions.R

ddff2uvR Documentation

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

Description

Converts wind direction (dd) and wind speed (ff) information into u/v wind components (zonal and meridional wind component).

Usage

ddff2uv(dd, ff = NULL)

Arguments

dd

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, ...)

ff

numeric, matrix, data.frame, or zoo object (see 'Details' section).

Details

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).

Value

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.

Author(s)

Reto Stauffer

See Also

uv2ddff

Examples

## 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)))

## Using with data.frame
print(head(ddff2uv(df)))

## Using with matrix
print(head(ddff2uv(as.matrix(df))))

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

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