Skip to content

Commit

Permalink
replacing sp by sf and spplot by leaflet
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainschmitt committed Oct 19, 2023
1 parent d8152bd commit e03e882
Show file tree
Hide file tree
Showing 29 changed files with 539 additions and 402 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ addons:
- libudunits2-dev

r_packages:
- rgdal
- covr
- devtools

Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Description: Allows to map species richness and endemism based on stacked
License: GPL (>=3) | file LICENSE
LazyData: TRUE
Imports:
sp (>= 1.2.0),
sf (>= 1.0-14),
raster (>= 2.9-5),
methods (>= 3.2.2),
mgcv (>= 1.8.7),
Expand All @@ -42,7 +42,8 @@ Imports:
iterators (>= 1.0.10),
itertools (>= 0.1-3),
parallel (>= 3.5.2),
snow (>= 0.4-3)
snow (>= 0.4-3),
leaflet (>= 2.2.0)
Depends:
R (>= 3.2.2)
Collate:
Expand Down Expand Up @@ -81,11 +82,10 @@ Suggests:
testthat,
knitr,
rmarkdown,
rgdal,
geobuffer,
fasterize,
sdm
RoxygenNote: 6.1.1
RoxygenNote: 7.2.3
VignetteBuilder:
knitr,
rmarkdown
Expand Down
16 changes: 9 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ importFrom(graphics,barplot)
importFrom(graphics,legend)
importFrom(iterators,icount)
importFrom(itertools,isplitVector)
importFrom(leaflet,addLegend)
importFrom(leaflet,addRasterImage)
importFrom(leaflet,addTiles)
importFrom(leaflet,colorNumeric)
importFrom(leaflet,leaflet)
importFrom(leaflet,leafletOutput)
importFrom(leaflet,renderLeaflet)
importFrom(mgcv,gam)
importFrom(mgcv,gam.control)
importFrom(nnet,nnet)
Expand Down Expand Up @@ -96,6 +103,8 @@ importFrom(reshape2,melt)
importFrom(rpart,rpart)
importFrom(rpart,rpart.control)
importFrom(scales,muted)
importFrom(sf,st_as_sf)
importFrom(sf,st_buffer)
importFrom(shiny,actionButton)
importFrom(shiny,brushOpts)
importFrom(shiny,checkboxGroupInput)
Expand Down Expand Up @@ -138,13 +147,6 @@ importFrom(shinydashboard,sidebarMenuOutput)
importFrom(shinydashboard,tabBox)
importFrom(shinydashboard,tabItem)
importFrom(shinydashboard,tabItems)
importFrom(sp,Polygon)
importFrom(sp,Polygons)
importFrom(sp,SpatialPoints)
importFrom(sp,SpatialPolygons)
importFrom(sp,bbox)
importFrom(sp,coordinates)
importFrom(sp,spplot)
importFrom(spThin,thin)
importFrom(stats,aggregate.data.frame)
importFrom(stats,cor)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
NEWS
================

SSDM 0.2.8.9001
===============

bug fixes:
- totally removing rgdal following r-spatial evolution
- moving from sp to sf following r-spatial evolution

SSDM 0.2.8.9000
===============
new/edited:
Expand Down
16 changes: 4 additions & 12 deletions R/PA.select.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @include Algorithm.SDM.R
#' @import methods
#' @importFrom sp Polygon Polygons SpatialPolygons bbox
#' @importFrom sf st_as_sf st_buffer
#' @importFrom raster raster stack extract predict reclassify layerStats calc Which xyFromCell crs
NULL

Expand All @@ -17,17 +17,9 @@ setMethod('PA.select', "Algorithm.SDM", function(obj, Env, PA = NULL, verbose =
# Mask defining
if (PA$strat == 'disk') {
if(verbose) {cat(' disk selection \n')}
circles = list()
for (i in seq_len(length(obj@data$X))) {
x = obj@data$X[i]
y = obj@data$Y[i]
pts = seq(0, 2 * pi, length.out = 100)
xy = cbind(x + 2/60 * sin(pts), y + 2/60 * cos(pts))
circle = Polygon(xy)
circles[i] = circle
}
sc= SpatialPolygons(list(Polygons(circles, 'Circles')))
Mask = mask(Env[[1]], sc)
circles <- st_as_sf(obj@data, coords = c("X", "Y"))
circles <- st_buffer(circles, 2/60)
Mask = mask(Env[[1]], circles)
}
if(PA$strat=='geobuffer'){
if(!is.null(PA$dist)){
Expand Down
1 change: 0 additions & 1 deletion R/SDM.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#' @import methods
#' @importFrom sp Polygon Polygons SpatialPolygons bbox
#' @importFrom raster raster stack extract predict reclassify layerStats calc
#' @importFrom mgcv gam gam.control
#' @importFrom earth earth
Expand Down
1 change: 0 additions & 1 deletion R/evaluate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @importFrom stats aggregate.data.frame cor glm glm.control rbinom runif sd var
#' @importFrom utils lsf.str read.csv read.csv2 tail write.csv
#' @importFrom raster reclassify rasterize extract stack
#' @importFrom sp SpatialPoints coordinates
NULL

#' Evaluate
Expand Down
11 changes: 5 additions & 6 deletions R/mapDiversity.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#' @include Ensemble.SDM.R checkargs.R
#' @importFrom sp Polygon Polygons SpatialPolygons SpatialPoints bbox
#' @importFrom raster raster stack reclassify mask calc overlay values rasterize rasterToPoints values<- Which setValues
#' @importFrom stats lm optim
#' @importFrom poibin dpoibin
Expand Down Expand Up @@ -143,7 +142,7 @@ setMethod("mapDiversity", "Stacked.SDM", function(obj, method, rep.B = 1000,
# helper functions and maximum likelihood function
logit = function(x) {x=ifelse(x<0.0001,0.0001,ifelse(x>0.9999,.9999,x)); ;log(x/(1 - x))}
invlogit = function(x) {exp(x)/(1+exp(x))}

nLL.Calabrese <- function(par,sr,probs) {
bysite <- function(j) {
logit.probs <- logit(as.numeric(probs[j,]))
Expand All @@ -152,16 +151,16 @@ setMethod("mapDiversity", "Stacked.SDM", function(obj, method, rep.B = 1000,
}
- sum(sapply(seq_len(length(sr)),bysite)) # optim performs minimization, so for maximum likelihood we need to invert
}

# find the maximum likelihood estimates for adjustment parameters
adj.par <- optim(par=c(0,0), fn=nLL.Calabrese, sr=obs.sr, probs=pred.prob)
adj.par <- optim(par=c(0,0), fn=nLL.Calabrese, sr=obs.sr, probs=pred.prob)
# adjust the predicted probabilities, transform back with invlogit and stack
corr.sr <- rowSums(apply(pred.prob,2,FUN=function(x){invlogit(logit(x)+adj.par$par[1]*obs.sr+adj.par$par[2])}))
### End of code from Damaris Zurell/Justin Calabrese

diversity.map[ind_notNA] <- corr.sr
}


if (method == "PRR.MEM") {
# Probability ranking with MEM (SESAM, D'Amen et al, 2015)
Expand Down
Loading

0 comments on commit e03e882

Please sign in to comment.