Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
meblair authored and cran-robot committed Nov 21, 2022
0 parents commit 1f2c110
Show file tree
Hide file tree
Showing 101 changed files with 4,422 additions and 0 deletions.
42 changes: 42 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,42 @@
Package: changeRangeR
Type: Package
Title: Change Metrics for Species Geographic Ranges
Version: 1.0.0
Authors@R: c(person('Peter J.', 'Galante',email='pgalante@amnh.org',role=c('aut')),
person('Samuel','Chang',email='changalfsam@gmail.com',role=c('aut')),
person('Andrea','Paz',email='paz.andreita@gmail.com',role=c('aut')),
person('Jamie M.','Kass',email='jamie.kass@oist.jp',role=c('aut')),
person('Matthew','Aiello-Lammens',email='maiellolammens@pace.edu',role=c('aut')),
person('Beth','Gerstner',email='gerstn11@msu.edu',role=c('aut')),
person('Bethany','Johnson',email='bjohnso005@citymail.cuny.edu',role=c('aut')),
person('Cory','Merow',email='cory.merow@gmail.com',role=c('aut')),
person('Elkin','Noguera-Urbano',email='enoguera@humboldt.org.co',role=c('aut')),
person('Gonzalo E.','Pinilla-Buitrago',email='gpinillabuitrago@gradcenter.cuny.edu',role=c('aut')),
person('Dan','Rosauer',email='dan.rosauer@anu.edu.au',role=c('aut')),
person('Mary E.','Blair',email='mblair1@amnh.org',role=c('aut','cre')))
Description: Facilitates workflows to reproducibly transform estimates of species’ distributions into metrics relevant for conservation. For example, combining predictions from species distribution models with other maps of environmental data to characterize the proportion of a species’ range that is under protection, calculating metrics used under the IUCN Criteria A and B guidelines (Area of Occupancy and Extent of Occurrence), and calculating more general metrics such as taxonomic and phylogenetic diversity, as well as endemism. Also facilitates temporal comparisons among biodiversity metrics to inform efforts towards complementarity and consideration of future scenarios in conservation decisions. 'changeRangeR' also provides tools to determine the effects of modeling decisions through sensitivity tests.
License: GPL-3
VignetteBuilder: knitr
Encoding: UTF-8
Depends: R (>= 4.0)
Imports: phylobase, raster, dplyr, rangeModelMetadata, rgeos, sf, sp
Suggests: ape, rgdal, tidyverse, rmarkdown, testthat, tinytex, knitr,
picante, wallace, R.utils, tools, dismo
RoxygenNote: 7.2.0
NeedsCompilation: no
Packaged: 2022-11-19 22:42:10 UTC; kass1
Author: Peter J. Galante [aut],
Samuel Chang [aut],
Andrea Paz [aut],
Jamie M. Kass [aut],
Matthew Aiello-Lammens [aut],
Beth Gerstner [aut],
Bethany Johnson [aut],
Cory Merow [aut],
Elkin Noguera-Urbano [aut],
Gonzalo E. Pinilla-Buitrago [aut],
Dan Rosauer [aut],
Mary E. Blair [aut, cre]
Maintainer: Mary E. Blair <mblair1@amnh.org>
Repository: CRAN
Date/Publication: 2022-11-21 11:00:02 UTC
100 changes: 100 additions & 0 deletions MD5
@@ -0,0 +1,100 @@
197437b4c7ccdcdc5c88b1e3d09de8f5 *DESCRIPTION
031af8234ad76481645504ae0569ba78 *NAMESPACE
5b7b0b27caa734faa1b070805421aaf5 *R/PD_from_rasters.R
d6c91a59e549b9b8363582fe00ae5cba *R/SE.R
91ac3633ea49e3b284cc0e1e99d11b82 *R/aooArea.R
0673647f3afba947f1c69d5eccd6123d *R/cRRrmm.R
f9285aa97d16562243ae881171655afc *R/calc_PE.R
07b0d8a3a2fe5eac8b9129f405fb06a6 *R/complementarity.R
31d2082b4e03124686f2b7e90a9fcfc9 *R/envChange.R
d0b7a32c7dcadc44f555689e403e9b87 *R/futureOverlap.R
3afb528b94aad67a09252d555648932f *R/mcp.R
39d4379b2ff4e85835a895be990d9db7 *R/mcpSDM.R
0707842d7a21974001bf64b82c195c1a *R/ratioOverlap.R
e8d8b561ce49545824091b793b8e6f1b *R/startup.r
0c6ad5b3446721162c89589e8077ab1c *build/partial.rdb
9895ba51ceb95f657a62a2c970319fda *build/vignette.rds
2532f5cf08ab60ed0503b446350a9da1 *inst/doc/BiodivMetrics.R
eb9bda58738c3e9477058e94cbfde8cb *inst/doc/BiodivMetrics.Rmd
6dbb635fbe87b600c04bffeaa080af23 *inst/doc/BiodivMetrics.pdf
9206dfb51dc3992aaacdf1a8d1b9fea1 *inst/doc/singleSpeciesMetrics.R
6307f363fac74793a71004a600d9c6db *inst/doc/singleSpeciesMetrics.Rmd
7b31bba1ffb3a134676ade4b3a758939 *inst/doc/singleSpeciesMetrics.pdf
a14a42ce791f75d64918d91876258ba4 *inst/extdata/DemoData/MODIS/2005_olinguito_Modis_coarse.tif
9eec82c48935f313a42e6198e6646efe *inst/extdata/DemoData/MODIS/2006_olinguito_Modis_coarse.tif
4bc032517313e7185ee6cbf86ad08f3f *inst/extdata/DemoData/MODIS/2008_olinguito_Modis_coarse.tif
cbe6d926d800544483fba096cf88b06c *inst/extdata/DemoData/MODIS/2009_olinguito_Modis_coarse.tif
3ba9839bef46d7972ef60bf2bbed58e3 *inst/extdata/DemoData/SDM/Climatically_suitable_projected_coarse.tif
7fb5867439deba6f2af30f76eaeef4a6 *inst/extdata/DemoData/SDM/Forest_suitable_projected_coarse.tif
46581e9b0bee452cc0c7095f2c7f4c41 *inst/extdata/DemoData/SDM/colPrimates_binary/Alouatta_palliata_veg_coarse.tif
e6a5aefccd9516fe27412299a3d9758c *inst/extdata/DemoData/SDM/colPrimates_binary/Alouatta_seniculus_veg_coarse.tif
5a42a6c0af0985caf1258838f912c2d8 *inst/extdata/DemoData/SDM/colPrimates_binary/Aotus_brumbacki_veg_coarse.tif
8142216b2f007c5ed3ab65b0fab5e4e1 *inst/extdata/DemoData/SDM/colPrimates_binary/Aotus_griseimembra_veg_coarse.tif
7be99af643b4cf9d587e17ba52b2960a *inst/extdata/DemoData/SDM/colPrimates_binary/Aotus_lemurinus_veg_coarse.tif
dd61ae35532b72771815bafd8b435842 *inst/extdata/DemoData/SDM/colPrimates_binary/Aotus_nancymaae_veg_coarse.tif
7380d8dccf64c61536ea8a366d149a26 *inst/extdata/DemoData/SDM/colPrimates_binary/Aotus_zonalis_veg_coarse.tif
591d1f3fc3be40560feb3b48217c2393 *inst/extdata/DemoData/SDM/colPrimates_binary/Ateles_belzebuth_veg_coarse.tif
e9cc5681af3546ea727657ffb9e1336c *inst/extdata/DemoData/SDM/colPrimates_binary/Ateles_fusciceps_veg_coarse.tif
c40505d7d906a1588f6d97f1788b7068 *inst/extdata/DemoData/SDM/colPrimates_binary/Ateles_hybridus_veg_coarse.tif
75c9c1a4831397712964aa99ff91a6e1 *inst/extdata/DemoData/SDM/colPrimates_binary/Cacajao_melanocephalus_veg_coarse.tif
510fadb14fa6a388c7d1a6af4541e3b0 *inst/extdata/DemoData/SDM/colPrimates_binary/Callimico_goeldii_veg_coarse.tif
47ce326a71b05961e28664b9a7bd2b34 *inst/extdata/DemoData/SDM/colPrimates_binary/Cebuella_pygmaea_veg_coarse.tif
40bbcf5771e29868fab0c18f2cf3178e *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_albifrons_veg_coarse.tif
e2f394748eea017b075bb8a9de74b000 *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_all_albifrons_veg_coarse.tif
1fdad348de04ca338276688c82fc1ab5 *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_capucinus_veg_coarse.tif
65f2c28d19745a17b5740cd7f5355423 *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_leucocephalus_veg_coarse.tif
ffb60969906fc22531ec355458dfb21b *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_malitiosus_veg_coarse.tif
f1a369468a55e05d6131650f3a05c597 *inst/extdata/DemoData/SDM/colPrimates_binary/Cebus_versicolor_veg_coarse.tif
e1428973e59fe223e3597925b94e3258 *inst/extdata/DemoData/SDM/colPrimates_binary/Cheracebus_lugens_veg_coarse.tif
f0fe30db27ce9e6d739cdf8a160379f3 *inst/extdata/DemoData/SDM/colPrimates_binary/Cheracebus_medemi_veg_coarse.tif
e30d9b799c47fc720e2f6fce9a237c4e *inst/extdata/DemoData/SDM/colPrimates_binary/Lagothrix_lagothricha_veg_coarse.tif
cc85ca0abfddb3caff47a9e8b7a3fcd0 *inst/extdata/DemoData/SDM/colPrimates_binary/Leontocebus_fuscus_veg_coarse.tif
bae0356ab40a980f0a60eed1628c43f5 *inst/extdata/DemoData/SDM/colPrimates_binary/Leontocebus_nigricollis_veg_coarse.tif
dd4580907d56d5eb8c0bcaf4c4cdde34 *inst/extdata/DemoData/SDM/colPrimates_binary/Pithecia_hirsuta_veg_coarse.tif
bc0d4ce6fbbe9292f84a909a28d0109b *inst/extdata/DemoData/SDM/colPrimates_binary/Pithecia_milleri_veg_coarse.tif
d6c1adeda38c08c41857e02d497e1961 *inst/extdata/DemoData/SDM/colPrimates_binary/Plecturocebus_caquetensis_veg_coarse.tif
ce645eb41d87e0e12c331d6b839409af *inst/extdata/DemoData/SDM/colPrimates_binary/Plecturocebus_discolor_veg_coarse.tif
4aea30308c4c38ea17ced82663397a23 *inst/extdata/DemoData/SDM/colPrimates_binary/Plecturocebus_ornatus_veg_coarse.tif
bd42471ed1c637a4a6e90f02cd50f8e7 *inst/extdata/DemoData/SDM/colPrimates_binary/Saguinus_geoffroyi_veg_coarse.tif
5e8a6155ec5c22dc93d8856e1f54e423 *inst/extdata/DemoData/SDM/colPrimates_binary/Saguinus_inustus_veg_coarse.tif
5e07fe0850a8db575e389230d4781ad8 *inst/extdata/DemoData/SDM/colPrimates_binary/Saguinus_leucopus_veg_coarse.tif
a6d4afd2181ddaf8f803aadadb475d53 *inst/extdata/DemoData/SDM/colPrimates_binary/Saguinus_oedipus_veg_coarse.tif
68af494e4a26ed1fd46a58d9b656747d *inst/extdata/DemoData/SDM/colPrimates_binary/Saimiri_cassiquiarensis_veg_coarse.tif
ddc61c8f244d83e790397ac693ab519b *inst/extdata/DemoData/SDM/colPrimates_binary/Sapajus_apella_veg_coarse.tif
9ccaa5542cbcca9a7aeea4e9447c7180 *inst/extdata/DemoData/SDM/franLang/climateOnlyFrancoisi.BCC.2040s.ssp2.tif
066daaac83e62b120b1558fae72be8cc *inst/extdata/DemoData/SDM/franLang/climateOnlyFrancoisi.BCC.2060s.ssp2.tif
ae18cf273ed71716b5a96d93fcd3912a *inst/extdata/DemoData/SDM/olinguitoSDM_coarse.tif
51dff7710a93fb186ff010629cdec36f *inst/extdata/DemoData/locs/10KM_thin_2017.csv
1de7dfdf6ad1ea04cb8dc54599805746 *inst/extdata/DemoData/locs/All_localities_30n.csv
f66d7fc5b099896f0346869adf3dd814 *inst/extdata/DemoData/phyloTree/output.nex
e6e20ca04153be8adc4d9e0e1aa62c22 *inst/extdata/DemoData/shapefiles/WDPA_COL_olinguito_simp.dbf
c742bee3d4edfc2948a2ad08de1790a5 *inst/extdata/DemoData/shapefiles/WDPA_COL_olinguito_simp.prj
f45d75f87a638304468d1d8bce6f64d1 *inst/extdata/DemoData/shapefiles/WDPA_COL_olinguito_simp.shp
3173a0141a7de61e15b9db3a503f893e *inst/extdata/DemoData/shapefiles/WDPA_COL_olinguito_simp.shx
864ac49c4f9491b4979027c0ae2d9c5f *inst/extdata/DemoData/shapefiles/vn/VN_NRs_simp.dbf
c742bee3d4edfc2948a2ad08de1790a5 *inst/extdata/DemoData/shapefiles/vn/VN_NRs_simp.prj
f3779abc0c67c4b692f2b7025a908e17 *inst/extdata/DemoData/shapefiles/vn/VN_NRs_simp.shp
b92e8406f9410975cf5520a15738b709 *inst/extdata/DemoData/shapefiles/vn/VN_NRs_simp.shx
ffc11cd8aca6c81f7a166713c0748968 *man/AOOarea.Rd
77ca09449975b48cd273356e8ed70b72 *man/Species-Endemism.Rd
0949a3f8c87c93ffe29be6629e041ba3 *man/buildRMM.Rd
66d68fa4054b1db1828079c3ed24c69c *man/calc_PE.Rd
53b72c2417d844ed91388774585bf8c4 *man/complementarity.Rd
f4e207dab984136af18a02639fcdd912 *man/envChange.Rd
9b48a03fb827a75d2caa303c6f30e9a4 *man/futureOverlap.Rd
d6e6e64a74e7fb5fb8fca3ccdf52521a *man/mcp.Rd
07f646ccdff7c44fd677a6c44679c2f0 *man/mcpSDM.Rd
ba2cc109998a296b187ffdeb23def02f *man/ratioOverlap.Rd
db598d96daee5ee2ed4092a4af730450 *tests/testthat.R
a5ebe7c56aea27f079658fcd0a5b46f0 *tests/testthat/test_SE.R
d216e6dba01f1d21275654a9b2b340b2 *tests/testthat/test_aooArea.R
5f8eb1a6556c148cd9ed4f4b6f7e1d71 *tests/testthat/test_cRRrmm.R
9840a416cdd38ead8d9e668d8f360e38 *tests/testthat/test_calcPE.R
834e77b2426416e9d8acd31bf75e5641 *tests/testthat/test_complementarity.R
4f594ddce8e27cd966aaeb0b9dc28e81 *tests/testthat/test_envChange.R
479e58226162eaa6b33a92a2d42a6e0a *tests/testthat/test_futureOverlap.R
ae2dad942172359fe4675d1ab02e205e *tests/testthat/test_mcp.R
4aa2e91beedc0f1b5a46caf9ce2e8698 *tests/testthat/test_mcpSDM.R
ddb76735483eae744e0196ac2da1b615 *tests/testthat/test_ratioOverlap.R
eb9bda58738c3e9477058e94cbfde8cb *vignettes/BiodivMetrics.Rmd
6307f363fac74793a71004a600d9c6db *vignettes/singleSpeciesMetrics.Rmd
13 changes: 13 additions & 0 deletions NAMESPACE
@@ -0,0 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(AOOarea)
export(SpeciesEndemism)
export(buildRMM)
export(calc_PE)
export(complementarity)
export(envChange)
export(futureOverlap)
export(mcp)
export(mcpSDM)
export(ratioOverlap)
import(phylobase)
160 changes: 160 additions & 0 deletions R/PD_from_rasters.R
@@ -0,0 +1,160 @@
# ######Phylogenetic diversity from distribution models in tif format and phylogenies in nexus format######
# ###This script applies to any distribution map in raster format changing only the extension type in line 52###
# #############Last updated January 2014 by Andrea Paz#################
#
#
# #Clean workspace
# rm(list=ls())
#
# #Load required packages
# library(maptools)
# library(raster)
# library(rgdal)
# library(picante)
# #####Function to load and crop rasters######
#
# funcion1=function (x, mask=selected_mask,factor=resolution) {
# capa=raster(x)
# capa1=aggregate(capa,factor,fun=max)
# capa2=crop(capa1,extent(mask))
# return(capa2)
# }
#
# ########################################USER DEFINED VARIABLES#########################################
# ######Prompt user to determine location of files and selected geographic areas, resolution etc.########
# #######################################################################################################
#
#
# {print("Remember phylogeny file must be stored in working directory and named phylogeny.nex")
#
# # set working directory
# print("Choose working directory for storage:")
# working_directory<-choose.dir()
# setwd(working_directory)
#
# #Select folder containing distribution maps
# print("Select folder containing distribution maps")
# maps_folder<-choose.dir()
#
# #File containing shape of the area to be analyzed (can be a country, province, ecosystem etc.). It will be treated as a mask
# print("Select working mask (i.e Colombia)")
# working_mask<-file.choose()
#
# #Determine resolution as aggregation factor
# resolution1<-readline("Aggregation factor for model (Integer): ")
# resolution<-as.numeric(resolution1)
# #Determine names for outputs
# PD_map<-readline("Name of phylogenetic diversity raster: Do not use spaces and must include .asc extention (Ex: PD_country.asc): ")
# species_richness<-readline("Name of the species richness map: Do not use spaces and must include .asc extention (Ex: Species_richness_country.asc): ")
#
# #Read distribution files and obtain species names for phylogeny
#
# distribution_files<-list.files(path=maps_folder, pattern= "*.tif$")
# species_names<-sub("_10p_cut.tif","",distribution_files)
# table1<-as.data.frame(species_names)
# colnames(table1)<-"Grid"
# write.table(table1,"species_list.txt",quote=F,row.names=F) #seria bueno que agregara el nombre de la mascara para saber si es colombia o paramo
#
# #Read Shape of the geographic Mask
# selected_mask<-readShapePoly(working_mask)
#
# #########################
# ####START ANALYSES#######
# #########################
# setwd(maps_folder)
# #Create empty raster of the desired area and resolution to assign pixel numbers
# r<-raster(distribution_files[1])
# r=aggregate(r,resolution,fun=max)
# r<-crop(r,extent(selected_mask))
# grid=r
# names(grid)="grid"
# grid[1:ncell(grid)]<-1:ncell(grid)
# grid_list<-list(grid)
# names(grid_list)<-"Grid"
# #Load distribution files, aggregate and crop to Colombia extent
#
# layers<-list()
# for (i in 1:length(distribution_files))
# {
# layers[i]<-funcion1(distribution_files[i])
# print(i)
# }
# #layers<-lapply(distribution_files,funcion1)
#
#
# #assign species names to layers with species distributions
# names(layers)<-as.vector(table1$Grid)
# layers[sapply(layers,is.null)]<-NULL
#
# #Combine distributions with pixel number raster
# complete_list<-c(grid_list,layers)
#
# #Stack all distribution files and pixel numbers for PD computation
# Stack<-stack(complete_list)
#
# #Convert to data frame for storage and posterior analysis
#
# community_data<-as.data.frame(Stack)
#
# #Store
# setwd(working_directory)
# write.table(community_data, file = "communities.txt", append = FALSE,row.names=F,quote=F,sep="\t") #tratar de agregar nombre de mascara
#
#
# #Generate a raster of taxonomic diversity (TD) for comparison
# all_species<-stack(layers)
# TD<-calc(all_species,sum)
# writeRaster(TD,species_richness)
# }
#
# #####This part when the phylogeny is ready#####
#
# #Phylogenetic diversity computation
#
# #Read phylogeny file in nexus format
# ##To read a phylogeny in newick format use read.tree instead of read.nexus
# #In working directory always a file with the same name: phylogeny.nex
#
# user_phylogeny=read.nexus("phylogeny.nex")
#
#
# #In the community data frame NA must be eliminated
# community_data=na.omit(community_data)
# head(community_data)
#
# #III-Phylogenetic diversity computation
# #computes only Faith�s PD others may be added
#
# pd.result <-pd(community_data[,2:ncol(community_data)],user_phylogeny,include.root = TRUE)
#
#
# #Add the pixel PD value to data frame
# community_data$pd<-pd.result[[1]]
#
# #Write the new matrix to a file to avoid rerunning the script for potential further analyses
# write.table(community_data, file = "communities_and_pd.txt", append = FALSE,row.names=F,quote=F,sep="\t")
#
# #IV-Generate a raster containing PD information per pixel
#
# #1-First generate an empty raster using a base model for resolution and area
#
# r<-raster(ncol=1462,nrow=624)
# res(r)<-resolution
# r<-crop(r,extent(selected_mask))
# values(r)<-0
# map<-readOGR(dsn=maps_folder,layer=species_names[[1]])
# r<-rasterize(map,r,map$PRESENCE,update=T)
# r<-mask(r,selected_mask)
# pd_ras<-r
# values(pd_ras)<-NA #Eliminate every value they will be replaced by PD values further down
#
#
# #2- Assign PD values to raster
# pd_ras[community_data$Grid]<-community_data$pd
#
# #3- Save raster to file
#
# writeRaster(pd_ras,PD_map)
#
# #4-Optional plotting map in R (write to pdf?)
# plot(pd_ras)
40 changes: 40 additions & 0 deletions R/SE.R
@@ -0,0 +1,40 @@
#' @name Species Endemism
#' @title Calculate species endemism
#' @description Calculate species endemism as the number of species in a place divided by the total number of places in which those species are found.
#' @param rStack a rasterStack of binary species presences
#' @return Raster object showing species endemism.
#' @author pgalante@@amnh.org
#' @examples
#' # create binary raster
#' r1 <- raster::raster(nrows=108, ncols=108, xmn=-50, xmx=50)
#' raster::values(r1)<- runif(n = (108*108))
#' r1[r1 < 0.5] <- NA
#' r1[r1 > 0.5] <- 1
#' r2 <- raster::raster(nrows=108, ncols=108, xmn=-50, xmx=50)
#' raster::values(r2)<- runif(n = (108*108))
#' r2[r2 < 0.5] <- NA
#' r2[r2 > 0.5] <- 1
#' r3 <- raster::raster(nrows=108, ncols=108, xmn=-50, xmx=50)
#' raster::values(r3)<- runif(n = (108*108))
#' r3[r3 < 0.5] <- NA
#' r3[r3 > 0.5] <- 1
#' rStack <- raster::stack(r1, r2, r3)
#' # calculate SE
#' SpeciesEndemism(rStack)
#' @export


SpeciesEndemism <- function (rStack){
#require(raster)
rStack[rStack == 0] <- NA
p.df <- as.data.frame(raster::rasterToPoints(rStack))
sspTotal <- raster::colSums(p.df, na.rm = T)
ssp.df <- t(p.df[-c(1, 2)]) * (sspTotal[-c(1, 2)])
ssp.PixSum <- raster::rowSums(t(ssp.df), na.rm = T)
spSum <- raster::rowSums(p.df[-c(1, 2)], na.rm = T)
SEvals <- spSum/ssp.PixSum
stackTotal <- sum(rStack, na.rm = T)
stackTotal[stackTotal == 0] <- NA
stackTotal[!is.na(stackTotal)] <- SEvals
return(stackTotal)
}

0 comments on commit 1f2c110

Please sign in to comment.