calc_speed: Calculate wind or current speed from u and v component...

View source: R/calc_helpers.R

calc_speedR Documentation

Calculate wind or current speed from u and v component vectors

Description

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

Usage

calc_speed(l)

Arguments

l

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

Details

In each cell, speed (m/s) is given by Pythagoras' Theorem.

Value

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

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){
              print(source)
              out <- R.matlab::readMat(source)$data
              print(utils::str(out))
              return(out)
           })

#### Step 2: Compute wind speed
wind_speed <- calc_speed(l)
hist(wind_speed)


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