calc_direction: Calculate wind or current direction from u and v component...

View source: R/calc_helpers.R

calc_directionR Documentation

Calculate wind or current direction from u and v component vectors

Description

This function calculates wind or current direction from u and v component vector arrays.

Usage

calc_direction(l)

Arguments

l

A list composed of two environmental arrays (u and v component arrays) for a particular day.

Details

Wind or current direction are expressed as the direction (degrees) of mass flow.

Value

The function returns an array comprising wind/current directions for each cell in the original array.

Author(s)

Edward Lavender

See Also

This function can be implemented within compute_field_from_fvcom.

Examples

#### Step 1: Read example u and v files into a list
# Define the path to the u and v files:
path <- system.file("WeStCOMS_files",
                    package = "fvcom.tbx", mustWork = TRUE)
path <- paste0(path, "/")
path_u <- paste0(path, "uwind_speed")
path_v <- paste0(path, "vwind_speed")
# Define the source files:
source_u <- list.files(path_u, full.names = TRUE)[1]
source_v <- list.files(path_v, full.names = TRUE)[1]
# Define a list comprising u and v arrays with one element for each day:
l <- lapply(list(source_u, source_v), function(source){
              R.matlab::readMat(source)$data
           })

#### Step 2: Compute wind direction
wind_direction <- calc_direction(l)
graphics::hist(wind_direction)


edwardlavender/fvcom.tbx documentation built on Nov. 26, 2022, 10:28 p.m.