Calculate Water Layer Thicknesses Within a Vector
calculate_depth_share.Rd
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.
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.
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)
#> [1] 5 10 10 10 10 10 10 10 10 10 5
# Water layer thickness using limits of a depth window
calculate_depth_share(depths, min_depth = 25, max_depth = 75)
#> [1] 0 0 0 10 10 10 10 10 0 0 0
# Special case when the depth vector falls outside the target depth window
calculate_depth_share(depths, min_depth = 400, max_depth = 600)
#> [1] 0 0 0 0 0 0 0 0 0 0 0