Title: | Euclidean Climatch Algorithm |
---|---|
Description: | An interface for performing climate matching using the Euclidean "Climatch" algorithm. Functions provide a vector of climatch scores (0-10) for each location (i.e., grid cell) within the recipient region, the percent of climatch scores >= a threshold value, and mean climatch score. Tools for parallelization and visualizations are also provided. Note that the floor function that rounds the climatch score down to the nearest integer has been removed in this implementation and the “Climatch” algorithm, also referred to as the “Climate” algorithm, is described in: Crombie, J., Brown, L., Lizzio, J., & Hood, G. (2008). “Climatch user manual”. The method for the percent score is described in: Howeth, J.G., Gantz, C.A., Angermeier, P.L., Frimpong, E.A., Hoff, M.H., Keller, R.P., Mandrak, N.E., Marchetti, M.P., Olden, J.D., Romagosa, C.M., and Lodge, D.M. (2016). <doi:10.1111/ddi.12391>. |
Authors: | Justin A. G. Hubbard [aut, cre] , D. Andrew R. Drake [aut], Nicholas E. Mandrak [aut] |
Maintainer: | Justin A. G. Hubbard <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.0.2 |
Built: | 2024-11-02 05:42:54 UTC |
Source: | https://github.com/justinhubbard/euclimatch |
Run climatch in parallel
climatch_par(recipient, source, globvar, biovar = 1:length(globvar), ncores, type = "perc", threshold = 6)
climatch_par(recipient, source, globvar, biovar = 1:length(globvar), ncores, type = "perc", threshold = 6)
recipient |
List of data.frames of the recipient regions |
source |
List of dataf.rames of the source regions |
globvar |
Vector of the global variance of each variable |
biovar |
Vector of the columns (climate variables) to use, default all columns |
ncores |
The number of cores to use in parallel |
type |
Choose between "perc" (default) or "mean" passed to climatch_sum() and "vec" passes to climatch_vec() |
threshold |
The climatch score (0-10) to use in calculating the percentage match, which is the number of grid cells within the recipient region with a climatch >= the threshold (default is 6). |
"perc" and "mean" returns data.frame of climatch within recipients (rows) for each source represented in columns, "vec" returns data.frame of climatch of a recipient (each column corresponds to grid cell), to sources (corresponding to rows)
# Dummy data i1 <- data.frame("clim1" = 1:10, "clim2" = 9:18) # Fake source climate data i <- list(i1, i1) # list the source dataframes j1 <- data.frame("clim1" = 11:20, "clim2" = 16:25) # Fake recipient climate data j <- list(j1, j1) # list the recipient dataframes variance <- c(60, 80) # Fake global variance # Climate matching climatch_par(recipient = j, source = i, globvar = variance, ncores = 1, type = "vec")
# Dummy data i1 <- data.frame("clim1" = 1:10, "clim2" = 9:18) # Fake source climate data i <- list(i1, i1) # list the source dataframes j1 <- data.frame("clim1" = 11:20, "clim2" = 16:25) # Fake recipient climate data j <- list(j1, j1) # list the recipient dataframes variance <- c(60, 80) # Fake global variance # Climate matching climatch_par(recipient = j, source = i, globvar = variance, ncores = 1, type = "vec")
Create a plot or SpatRaster of climatch values within recipient region.
climatch_plot(climdat, recipient, source = NULL, climatch = NULL, provide_SpatRaster = FALSE, xlim = terra::ext(recipient)[1:2], ylim = terra::ext(recipient)[3:4], plg = list(title = "Climatch", size=1), xlab = expression(paste("Longitude (",degree,")")), ylab = expression(paste("Latitude (",degree, ")")), ... )
climatch_plot(climdat, recipient, source = NULL, climatch = NULL, provide_SpatRaster = FALSE, xlim = terra::ext(recipient)[1:2], ylim = terra::ext(recipient)[3:4], plg = list(title = "Climatch", size=1), xlab = expression(paste("Longitude (",degree,")")), ylab = expression(paste("Latitude (",degree, ")")), ... )
climdat |
A SpatRaster, RasterStack or RaterLayer of the climate data to extract. |
recipient |
An object specifying location of where the recipient (i.e., target) region. Can be a SpatialPolygosDataFrame, SpatialPolygons, SpatVector. |
source |
An object, like 'recipient', specifying the location of the source region. |
climatch |
Vector of climatch values to use in creating SpatRaster of recipient. |
provide_SpatRaster |
Logical. If TRUE then function returns SpatRaster object, if FALSE (default) return plot. |
xlim |
Numeric, specify the limits of the x axis. Default is extent of x-axis from recipient SpatRaster. |
ylim |
Numeric, specify the limits of the y axis. Default is extent of y-axis from recipient SpatRaster. |
plg |
A list of parameters for specifying the legend. Default is "Climatch" see 'plot' in 'terra' for more documentation. |
xlab |
Character for x axis label. |
ylab |
Character for y axis label. |
... |
Pass arguments to plot function. |
A plot of the climatch within the recipient region. A SpatRater if provide_SpatRaster is TRUE.
r1 <- data.frame() for(i in 1:100){r1 <- rbind(r1, runif(60))} rclim1 <- terra::rast(as(r1, "matrix")) #Create the RasterLayer # Dummy lon lat mimicking species occurrence records spec_occ <- data.frame("lon" = 1:10, "lat" = 11:20) # Create dummy polygons x_coor <- c(1, 5, 10, 8, 3) y_coor <- c(15, 20, 27, 30, 29) dum_coor <- cbind(x_coor, y_coor) dum_poly <- terra::vect(dum_coor, type = "polygon") # Run and plot the climatch climatch_plot(recipient = dum_poly, source = spec_occ, climdat = rclim1, xlab = "Lon", ylab = "Lat")
r1 <- data.frame() for(i in 1:100){r1 <- rbind(r1, runif(60))} rclim1 <- terra::rast(as(r1, "matrix")) #Create the RasterLayer # Dummy lon lat mimicking species occurrence records spec_occ <- data.frame("lon" = 1:10, "lat" = 11:20) # Create dummy polygons x_coor <- c(1, 5, 10, 8, 3) y_coor <- c(15, 20, 27, 30, 29) dum_coor <- cbind(x_coor, y_coor) dum_poly <- terra::vect(dum_coor, type = "polygon") # Run and plot the climatch climatch_plot(recipient = dum_poly, source = spec_occ, climdat = rclim1, xlab = "Lon", ylab = "Lat")
A summarized climatch score within the recipient region to a source region. Provides the percentage of climate data points in the recipient region equal to or above a specified score (default is 6), or the mean climatch score across the whole recipient region. Note no floor function is used as in Crombie et al. (2008)
climatch_sum(recipient, source, globvar, type = "perc", threshold = 6)
climatch_sum(recipient, source, globvar, type = "perc", threshold = 6)
recipient |
A data.frame or list of data.frames of climatic variables for the recipient region. |
source |
A data.frame or list of data.frames of climatic variables for the source region. |
globvar |
A vector of the global variance of each climate variable. |
type |
Specifies the type of summary score to use. "perc" (default) specifies a percent climatch score representing the number of grid cells above or equal to a given value specified with the 'thershold' argument. "mean" provides the mean climatch score across the recipient region. |
threshold |
The climatch score to use in calculating the percentage match, which is the number of grid cells within the recipient region with a climatch >= the threshold (default is 6). |
A numeric value, vector or data.frame of the percentage of climatch scores within the recipient region(s) >= a threshold value, or the mean climatch score across the region(s).
Predicting invasiveness of species in trade: climate match, trophic guild and fecundity influence establishment and impact of non-native freshwater fishes"<doi:10.1111/ddi.12391>
i <- as.data.frame(matrix(runif(n=180, min=1, max=20), nrow=60)) # Fake source climate data j <- as.data.frame(matrix(runif(n=300, min=10, max=40), nrow=100)) # Fake recipient data variance <- c(600, 800, 450) # Fake global variance climatch_sum(recipient = j, source = i, globvar = variance, type = "perc", threshold = 6)
i <- as.data.frame(matrix(runif(n=180, min=1, max=20), nrow=60)) # Fake source climate data j <- as.data.frame(matrix(runif(n=300, min=10, max=40), nrow=100)) # Fake recipient data variance <- c(600, 800, 450) # Fake global variance climatch_sum(recipient = j, source = i, globvar = variance, type = "perc", threshold = 6)
Vector of the climatch scores within the recipient region
climatch_vec(recipient, source, globvar)
climatch_vec(recipient, source, globvar)
recipient |
A data.frame of climatic variables for the recipient region. |
source |
A data.frame of climatic variables for the source region. |
globvar |
A vector of the global variance of each climate variable, in the same order as the columns of source and recipient region data.frames. |
A vector of climatch scores corresponding to each grid cell within recipient region, i.e., each row in the recipient data.frame.
Crombie, J., Brown, L., Lizzio, J., & Hood, G. (2008). "Climatch user manual"
i <- as.data.frame(matrix(runif(n=180, min=1, max=20), nrow=60)) # Fake source climate data j <- as.data.frame(matrix(runif(n=300, min=10, max=40), nrow=100)) # Fake recipient data variance <- c(600, 800, 450) # Fake global variance climatch_vec(recipient = j, source = i, globvar = variance)
i <- as.data.frame(matrix(runif(n=180, min=1, max=20), nrow=60)) # Fake source climate data j <- as.data.frame(matrix(runif(n=300, min=10, max=40), nrow=100)) # Fake recipient data variance <- c(600, 800, 450) # Fake global variance climatch_vec(recipient = j, source = i, globvar = variance)
Extracts climate data from several types of inputs.
extract_clim_data(climdat, locations, id = FALSE)
extract_clim_data(climdat, locations, id = FALSE)
climdat |
A SpatRaster, RasterStack or RaterLayer of the climate data to extract. |
locations |
An object specifying location of where to extract the climate data from. Can be a SpatialPolygosDataFrame, SpatialPolygons, SpatVector, a single data.frame or a list of data.frames. If data.frame of list of data.frames, must provide only two columns with column names "lon" for longitude and "lat" for latitude. |
id |
Choose to include cell numbers with climate data. 'TRUE' includes cell numbers, the default 'FALSE' does not include cell numbers. Used in the climatch_plot() function. |
A data.frame or list of data.frames of the extracted climate data.
# Create fake climate data in as a SpatRaster object r1 <- data.frame() for(i in 1:100){r1 <- rbind(r1, runif(60))} rclim1 <- terra::rast(as(r1, "matrix")) #Create the RasterLayer rclim2 <- c(rclim1, rclim1) # Create the stack # Dummy lon lat data i.e., species occurrences. Cols must be labelled "lon" and "lat" # Cols must be labelled "lon" and "lat" species.occurr <- data.frame("lon" = 1:10, "lat" = 11:20) # Create dummy polygons x.coor <- c(1, 5, 10, 8, 3) y.coor <- c(15, 20, 27, 30, 29) dummy_coordinates <- cbind(x.coor, y.coor) dummy_polygon <- terra::vect(dummy_coordinates, type = "polygon") dummy_polygon2 <- rbind(dummy_polygon, dummy_polygon) # Extract the dummy data # Extract dummy lon lat data extract_clim_data(climdat = rclim2, locations = species.occurr) # Extract dummy SpatVector with single polygon extract_clim_data(climdat = rclim2, locations = dummy_polygon2)
# Create fake climate data in as a SpatRaster object r1 <- data.frame() for(i in 1:100){r1 <- rbind(r1, runif(60))} rclim1 <- terra::rast(as(r1, "matrix")) #Create the RasterLayer rclim2 <- c(rclim1, rclim1) # Create the stack # Dummy lon lat data i.e., species occurrences. Cols must be labelled "lon" and "lat" # Cols must be labelled "lon" and "lat" species.occurr <- data.frame("lon" = 1:10, "lat" = 11:20) # Create dummy polygons x.coor <- c(1, 5, 10, 8, 3) y.coor <- c(15, 20, 27, 30, 29) dummy_coordinates <- cbind(x.coor, y.coor) dummy_polygon <- terra::vect(dummy_coordinates, type = "polygon") dummy_polygon2 <- rbind(dummy_polygon, dummy_polygon) # Extract the dummy data # Extract dummy lon lat data extract_clim_data(climdat = rclim2, locations = species.occurr) # Extract dummy SpatVector with single polygon extract_clim_data(climdat = rclim2, locations = dummy_polygon2)