Skip to content

Commit

Permalink
Merge pull request #253 from danlwarren/develop
Browse files Browse the repository at this point in the history
Many small bug fixes
  • Loading branch information
danlwarren authored Jan 15, 2024
2 parents 5bc3e88 + d82062d commit 6b210e6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ benchmarks/*
wc5/*
docs
inst/doc

wc10/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: ENMTools
Type: Package
Title: Analysis of Niche Evolution using Niche and Distribution Models
Version: 1.1.1
Date: 2023-04-11
Date: 2024-01-10
Encoding: UTF-8
Authors@R: c(person(given = "Dan", family = "Warren", role = c("aut", "cre"), email = "dan.l.warren@gmail.com", comment = c(ORCID = "0000-0002-8747-2451")),
person(given = "Russell", family = "Dinnage", role = "aut", email = "r.dinnage@gmail.com", comment = c(ORCID = "0000-0003-0846-2819")))
Expand Down
8 changes: 4 additions & 4 deletions R/check.species.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ check.species <- function(this.species, env = NA, trim.dupes = FALSE){
}


if(!is.logical(this.species$presence.points) || !is.na(this.species$presence.points)){
if(!is.logical(this.species$presence.points) || !all(is.na(this.species$presence.points))){
this.species$presence.points <- check.points(this.species$presence.points, "presence.points")
}
if(!inherits(this.species$presence.points, "SpatVector")){
if(!is.na(this.species$presence.points)){
if(!all(is.na(this.species$presence.points))){
"Species presence points require an object of or coercible to class SpatVector"
}
}

if(!is.logical(this.species$background.points) || !is.na(this.species$background.points)){
if(!is.logical(this.species$background.points) || !all(is.na(this.species$background.points))){
this.species$background.points <- check.points(this.species$background.points, "background.points")
}
if(!inherits(this.species$background.points, "SpatVector")){
if(!is.na(this.species$background.points)){
if(!all(is.na(this.species$background.points))){
"Species background points require an object of or coercible to class SpatVector"
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/enmtools.ecospat.bg.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' }
#' }

enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers = NULL, test.type = "asymmetric", th.sp=0, th.env=0, R=100, nback = 1000, bg.source = "default", verbose = FALSE, ...){
enmtools.ecospat.bg <- function(species.1, species.2, env, nreps = 99, layers = NULL, test.type = "symmetric", th.sp=0, th.env=0, R=100, nback = 1000, bg.source = "default", verbose = FALSE, ...){

assert.extras.this.fun()

Expand Down
7 changes: 6 additions & 1 deletion R/enmtools.species.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ enmtools.species <- function(range = NA, presence.points = NA, background.points
}
}

# We were thinking to require this to be done by hand, but it can still
# be super convenient to do this on the fly when species.from.file is called
if(inherits(presence.points, "data.frame")){
presence.points <- check.points(presence.points)
}

if(!inherits(presence.points, "SpatVector")){
if(!is.na(presence.points)){
if(!all(is.na(presence.points))){
stop("Argument presence.points requires an object of class SpatVector")
}
}
Expand Down
32 changes: 17 additions & 15 deletions R/interactive.plot.enmtools.species.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ interactive.plot.enmtools.species <- function(x, map.provider = "Esri.WorldPhysi
labels <- NULL
colors <- NULL

if(inherits(raster::raster(x$range), "RasterLayer")){
m <- m %>%
leaflet::addRasterImage(raster::raster(x$range), function(y) ifelse(is.na(y), "#00000000", "#00000090"),
group = "Range", maxBytes = max.bytes)
overlays <- c(overlays, "Range")
labels <- c(labels, "Range raster")
colors <- c(colors, "black")
if(!isTRUE(is.na(x$range))){
if(inherits(raster::raster(x$range), "RasterLayer")){
m <- m %>%
leaflet::addRasterImage(raster::raster(x$range), function(y) ifelse(is.na(y), "#00000000", "#00000090"),
group = "Range", maxBytes = max.bytes)
overlays <- c(overlays, "Range")
labels <- c(labels, "Range raster")
colors <- c(colors, "black")
}
}


if(class(x$background.points) %in% c("SpatVector")){
background.points <- terra::as.data.frame(x$background.points, geom = "XY")
m <- m %>%
leaflet::addCircleMarkers(~x, ~y, color = "red",
data = background.points, stroke = FALSE, fillOpacity = 0.5,
radius = 8, group = "Background points")
data = background.points, stroke = FALSE, fillOpacity = 0.5,
radius = 8, group = "Background points")
overlays <- c(overlays, "Background points")
labels <- c(labels, "Background points")
colors <- c(colors, "red")
Expand All @@ -54,14 +56,14 @@ interactive.plot.enmtools.species <- function(x, map.provider = "Esri.WorldPhysi
if(cluster.points) {
m <- m %>%
leaflet::addCircleMarkers(~x, ~y, color = "green",
stroke = FALSE, fillOpacity = 0.5, radius = 8,
data = presence.points, clusterOptions = leaflet::markerClusterOptions(),
group = "Occurrence points")
stroke = FALSE, fillOpacity = 0.5, radius = 8,
data = presence.points, clusterOptions = leaflet::markerClusterOptions(),
group = "Occurrence points")
} else {
m <- m %>%
leaflet::addCircleMarkers(~x, ~y, color = "green",
data = presence.points, stroke = FALSE, fillOpacity = 0.5,
radius = 8, group = "Occurrence points")
data = presence.points, stroke = FALSE, fillOpacity = 0.5,
radius = 8, group = "Occurrence points")
}
overlays <- c(overlays, "Occurrence points")
labels <- c(labels, "Occurrence points")
Expand All @@ -77,7 +79,7 @@ interactive.plot.enmtools.species <- function(x, map.provider = "Esri.WorldPhysi

m <- m %>%
leaflet::addLegend("bottomright", colors = colors,
labels = labels)
labels = labels)

m

Expand Down
7 changes: 7 additions & 0 deletions R/raster.standardize.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ raster.standardize <- function(x, verbose=FALSE){
print(paste("Starting standardize on", x, "at", Sys.time()))
}

minval <- terra::minmax(x)[1]

if(minval < 0){
x <- x - minval + 1e-20
}


return(x/as.numeric(terra::global(x, "sum", na.rm = TRUE)))
}
1 change: 1 addition & 0 deletions R/species.from.file.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ species.from.file <- function(filename, species.col = "species"){

# More than one species in the file, create and return a list of enmtools.species objects
for(i in sp.names){
print(i)
this.species <- enmtools.species(species.name = i,
presence.points = input.df[input.df[,species.col] == i,])
this.species <- check.species(this.species)
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ check.points <- function(pts, name = "input") {
warning(sprintf('%s are not the expected SpatVector class (instead, it is of class %s). ENMTools will attempt to coerce using terra::vect(as.matrix(...), crs = "EPSG:4326"), but we cannot guaranteed the correctness of the result. Please consider using SpatVector format directly in the future, to minimize unexpected results.',
name,
cls))
pts <- format.latlon(pts)
pts <- terra::vect(as.matrix(pts), crs = "EPSG:4326")
}
pts
Expand Down
2 changes: 1 addition & 1 deletion man/enmtools.ecospat.bg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b210e6

Please sign in to comment.