calculate_depth_share: Calculate Water Layer Thicknesses Within a Vector

View source: R/Spatial utilities.R

calculate_depth_shareR Documentation

Calculate Water Layer Thicknesses Within a Vector

Description

This function calculates the thickness of the water layer around each point in a vector. These thicknesses are needed to calculate weighted averages across a depth window.

Usage

calculate_depth_share(depths, min_depth = min(depths), max_depth = max(depths))

Arguments

depths

A numeric vector of increasing depths.

min_depth

The shallowest depth in the depth window. (defaults to minimum depth in the vector)

max_depth

The deepest depth in the depth window. (defaults to minimum depth in the vector)

Details

The function calculates the midpoints between values in a vector and an optional set of boundary depths. The differences between these midpoints are calculated to return the thickness of a depth layer centered on each point in the original vector. In the absence of boundary depths, the maximum and minimum depths are used.

If a depth falls outside the target window it gets a thickness of 0. If all depths fall outside the window the function returns an all 0 vector. If this is passed to 'weighted.mean' the result will be NaN.

Value

A vector of water layer thicknesses to match the length of the original vector.

See Also

Other NEMO-MEDUSA spatial tools: calculate_proximity_weight(), netcdf_scheme_helpers, scheme_column(), scheme_interp_slice(), scheme_strathE2E(), stratify(), voronoi_grid(), xyindex_to_nindex()

Examples

# Get a vector of depths
depths <- seq(0, 100, by = 10)

# Water layer thickness within the vector
calculate_depth_share(depths)

# Water layer thickness using limits of a depth window
calculate_depth_share(depths, min_depth = 25, max_depth = 75)

# Special case when the depth vector falls outside the target depth window
calculate_depth_share(depths, min_depth = 400, max_depth = 600)

Jack-H-Laverick/nemomedusR documentation built on Dec. 12, 2022, 5:21 a.m.