Skip to contents

Function to calculate VoCC-based residence time of isotherms within a polygon after Loaire et al. (2009)

Usage

resTime(pg, vel, areapg = NA)

Arguments

pg

sf object or terra::vect object containing the polygons for which the residence time is to be calculated. The polygons must be on the same coordinate system as vel.

vel

raster with climate velocity (km/year) for the period of interest.

areapg

vector with the area (in km2) of the polygons. Use NA (default) to calculate internally if field not avilable.

Value

a data.frame containing for each polygon its ID, mean velocity (km/yr), diameter of the equivalent circle (km), and residence time (years) as the ratio D/vel.

References

Loarie et al. 2009. The velocity of climate change. Nature, 462, 1052-1055.

See also

Author

Jorge Garcia Molinos

Examples


# Load example Exclusive Economic Zone polygon
if (FALSE) { # \dontrun{
EEZ <- VoCC_get_data("EEZ.gpkg")
HSST <- VoCC_get_data("HSST.tif")

yrSST <- sumSeries(HSST,
  p = "1969-01/2009-12", yr0 = "1955-01-01", l = terra::nlyr(HSST),
  fun = function(x) colMeans(x, na.rm = TRUE),
  freqin = "months", freqout = "years"
)
tr <- tempTrend(yrSST, th = 10)
sg <- spatGrad(yrSST, th = 0.0001, projected = FALSE)
v <- gVoCC(tr, sg)
vel <- v[[1]]

# Calculating area internally
a1 <- resTime(EEZ, vel, areapg = NA)
a1

# Using the area field from the polygon data table
a2 <- resTime(EEZ, vel, areapg = as.numeric(as.numeric(levels(EEZ$Area_km2))[EEZ$Area_km2]))
a2

# Using a user defined polygon
x_coord <- c(-28, -20, -20.3, -25.5)
y_coord <- c(60, 61, 63, 62)
coords <- matrix(c(x_coord, y_coord), ncol = 2)
poly_sf <- sf::st_sf(geometry = sf::st_sfc(sf::st_polygon(list(coords))))
a3 <- resTime(poly_sf, vel, areapg = NA)

terra::plot(vel)
plot(sf::st_geometry(EEZ), add = TRUE)
plot(sf::st_geometry(poly_sf), add = TRUE)
} # }