Skip to content

Commit

Permalink
Daniele's transitioning rgdal-terra
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmar committed Oct 5, 2023
1 parent 0457fc9 commit a18c528
Show file tree
Hide file tree
Showing 28 changed files with 344 additions and 304 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: dynamAedes
Version: 2.2.0
Date: 2023-07-31
Version: 2.2.5
Date: 2023-10-05
Title: A Unified Mechanistic Model for the Population Dynamics of Invasive Aedes Mosquitoes
Authors@R: c(person("Matteo", "Marcantonio", role = c("aut", "cre"), email = "marcantoniomatteo@gmail.com"),person("Daniele", "Da Re", role = c("aut"), email = "dare.daniele@gmail.com"))
Depends: R (>= 4.0.0)
Imports: doParallel, dplyr, drc, foreach, geosphere, raster, slam, sp, terra
Imports: parallel, doParallel, foreach, drc, geosphere, terra
BugReports: https://github.com/mattmar/dynamAedes
Description: Generalised model for population dynamics of invasive Aedes mosquitoes. Rationale and model structure are described here: Da Re et al. (2021) <doi:10.1016/j.ecoinf.2020.101180> and Da Re et al. (2022) <doi:10.1101/2021.12.21.473628>.
VignetteBuilder: knitr
Expand All @@ -13,6 +13,6 @@ Language: en-GB
License: GPL(>=2)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Suggests: parallel, rmarkdown, knitr, eesim, ggplot2, gstat, spatstat, rgdal
Suggests: rmarkdown, knitr, eesim, gstat, stats, dplyr, ggplot2, sf
Config/testthat/edition: 3
URL: https://mattmar.github.io/dynamAedes/
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ importFrom("doParallel", "registerDoParallel")
importFrom("foreach", "%dopar%", "foreach", "%do%")
importFrom("utils", "setTxtProgressBar", "txtProgressBar")
importFrom("stats", "dgamma", "dlnorm", "lm", "predict", "rbinom", "rmultinom", "rpois", "sortedXyData", "quantile", "setNames", "glm")
importFrom("slam", "as.simple_sparse_array")
importFrom("drc", "drm")
importFrom("geosphere", "daylength")
importFrom("raster", "stack", "raster", "rasterFromXYZ")
importFrom("terra", "distance")
importFrom("sp", "gridded", "coordinates", "spTransform", "CRS", "SpatialPoints")
importFrom("dplyr", "%>%", "bind_rows", "as_tibble", "mutate")
importFrom("terra", "distance","crds","project","vect")
#####################################
## Export ##
#####################################
Expand Down
15 changes: 9 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# dynamAedes 2.2.5
* Removes definitely rgdal from package
* Clears NAMESPACE

# dynamAedes 2.2.0
* Substitutes `fields::rdist` with terra::distance which solves a bug in active dispersal
* Adds a switch for active dispersal only `pDispersal=FALSE`
* Removes warnings changing Beta function with polynomial for egg survival in aegypti
* Raised 0 hatching rate to 15°C
* Removes warnings changing Beta function with polynomial for egg survival in Aedes aegypti
* Raised 0 hatching rate to 15°C for aegypti
* Other minor cosmetic changes
* Modify verbose option for debugging, now an integer with values 0 (silent), 1 or 2.

# dynamAedes 2.1.2
* Transitioning from 'rgdal' and 'sp' to 'terra'
* Transitioning from 'insol' to 'geosphere'
* Removing block-loading of 'tidyverse' (speeding up loading?)
* Helper functions not anymore exported
* Helper functions not exported any more

# dynamAedes 2.1.1
* Adding rgdal in the description
Expand All @@ -19,12 +23,11 @@
* Adding website with examples for the three scales (pkgdown)
* Coordinates now internally transformed (if not in lat/long) for the derivation of the photoperiod
* Adding option **coords.proj4** to specify coordinate projection (in proj4 format)
* Renaming dynamAedes as dynamAedes
* Renaming dynamAedes as dynamAedes.m

# dynamAedes 2.0.3
* At regional scale now diapause derived pixel by pixel using the photoperiod of input coordinates.
* You can now introduce diapause eggs using dynamAedes argument
"intro.degg"
* You can now introduce diapause eggs using dynamAedes argument "intro.degg"

# dynamAedes 2.0.2
* Minor bug fix for idci and icci functions
Expand Down
5 changes: 3 additions & 2 deletions R/adci_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ adci_sp=function (input_sim = NULL, coords = NULL, eval_date = NULL, stage = 1,
tmp = rate.sp[, y]
tmp = as.data.frame(cbind(coords, tmp))
names(tmp)[1:2] = c("X", "Y")
tmp=rasterFromXYZ(tmp)
tmp=terra::rast(tmp, type="xyz")
names(tmp) = paste0("p", breaks[y])
return(tmp)
})
outr=stack(rb)
outr=return(do.call(c,rb))

})
}
names(myOut)=paste0("d_", eval_date)
Expand Down
4 changes: 2 additions & 2 deletions R/dici.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ dici <- function(input_sim=NULL, coords=NULL, eval_date=NULL, breaks=c(0.25,0.5,
coords1$inv <- 0
coords1$inv[x[[maxdate]]] <- 1
names(coords1)=c("X", "Y", paste0("day",maxdate,"_inv_cells_Iteration"))
coords1 <- rasterFromXYZ(coords1)
coords1 <- terra::rast(coords1, type="xyz")
return(coords1)
})
return(stack(outs))
return(do.call(c,outs))
}
}
}
12 changes: 6 additions & 6 deletions R/dynamAedes.m.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#' @param sparse.output logical. The output matrix is optimised for sparse-matrix algebra (e.g. zeros are indexed).
#' @param compressed.output logical. Default TRUE, if FALSE provide abundance for each model's subcompartiment; if FALSE abundances are summed per compartment.
#' @param suffix character. Model output suffix for output RDS.
#' @param verbose integer. if 1 then an overview of population dynamics is printed in the console, if 2 more information on population dinamycs are printed out. Default is 0 (silent).
#' @param verbose integer. if 1 then an overview of population dynamics is printed in the console, if 2 more information on population dynamics are printed out. Default is 0 (silent).
#' @param seeding logical, default \code{FALSE}, if \code{seeding=TRUE} a fixed seed is applied for result reproducibility.
#' @return Matrix or a list of matrices containing, for each iteration, the number of individuals in each life stage per day (and for each grid cell of the study area if scale="lc" or "rg"). If the argument compressed.output=FALSE (default TRUE), the model returns the daily number of individuals in each life stage sub-compartment.
#' @example inst/examples/dynamAedes.m.R
Expand Down Expand Up @@ -84,7 +84,7 @@ if(scale!="ws") {
if( is.na(coords.proj4) ) {
stop("No proj4 string for input coordinates. Please set 'coords.proj4' option.")
} else {
cells.coords.photo <- as.data.frame(coordinates(spTransform(SpatialPoints(cells.coords, proj4string=CRS(coords.proj4)), CRSobj=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))))
cells.coords.photo <- terra::crds(terra::project(terra::vect(x= cells.coords, type="points", atts=NULL, crs=coords.proj4), "EPSG:4326"), df=TRUE)
}
}
if( maxlat>90 ) {
Expand Down Expand Up @@ -116,7 +116,7 @@ if( is.na(avgpdisp) ) {
if( species!="aegypti" ){
doy <- as.numeric(format(seq(as.POSIXct(startd), as.POSIXct(as.Date(startd)+dayspan), by='day'), "%j"))
if( scale=="rg" ) {
photo.matrix <- lapply(doy, function(x){daylength(lat=cells.coords.photo[,2], doy=x)})
photo.matrix <- lapply(doy, function(x){geosphere::daylength(lat=cells.coords.photo[,2], doy=x)})
photo.matrix <- do.call(cbind,photo.matrix)
} else if( !is.na(lat)&!is.na(long) ) {
dl <- daylength(lat,doy)
Expand All @@ -135,7 +135,7 @@ if(cluster.type=="PSOCK") {
cl <- makeCluster(spec=n.clusters, type=cluster.type, nnodes=n.clusters, outfile="")
} else(message("The only supported `cluster.type` is SOCK"))
## Register the environment
registerDoParallel(cl, cores=n.clusters)
doParallel::registerDoParallel(cl, cores=n.clusters)
if(seeding) parallel::clusterEvalQ(cl, set.seed(2021))
## Define space dimensionality into which simulations occour
space <- nrow(temps.matrix)
Expand All @@ -145,7 +145,7 @@ pb <- txtProgressBar(char = "%", min = 0, max = iter, style = 3)
### End of preamble ###
#%%%%%%%%%%%%%%%%%%%%%#
### Iterations: start parallelised introduction "iteration" ###
rs <- foreach( iteration=1:iter, .packages="foreach", .export = ls(globalenv()) ) %dopar% {
rs <- foreach::foreach( iteration=1:iter, .packages="foreach", .export = ls(globalenv()) ) %dopar% {
## Condition to satisfy to stop the life cycle: sum(pop) == 0, in case the day before extinction has happened
stopit <- FALSE
## Update progress bar
Expand Down Expand Up @@ -471,6 +471,6 @@ if( !is.na(suffix) ) {
saveRDS(rs, paste(suffix,".RDS",sep=""))
} else message("\n\n\n########################################\n## Iterations concluded.##\n########################################\n\n\n")
# Close cluster
stopCluster(cl)
parallel::stopCluster(cl)
return(rs)
}
13 changes: 8 additions & 5 deletions R/psi_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ psi_sp = function(input_sim=NULL,coords=NULL, eval_date=NULL, n.clusters=1) {
my.out=Reduce('+', mylist)/length(input_sim)
#rasterize
}
return(stack(apply(my.out, 2, function(x) {
rateList <- apply(my.out, 2, function(x) {
rate.sp=as.data.frame(cbind(coords, data.frame(x)))
names(rate.sp)=c("X", "Y", "ProbIntro")
rate.sp<-rasterFromXYZ(rate.sp)
return(rate.sp)
})))
#names(rate.sp)=c("X", "Y", "ProbIntro")
rate.sp<-terra::rast(rate.sp, type="xyz")
#return(rate.sp)
})
rateList <-do.call(c, unname(rateList))
names(rateList) <- my_names
return(rateList)
}
}
9 changes: 6 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## 2.1.*
# Multiple introductions for punctual scale: Eva?;
# Implement evaporation function and precipitation input;
# dynamAedes object to store attributes of the scenario;
# Remove gdal from DESCRIPTION and thus vignettes
# Multiple introductions for punctual scale: Emma?
# Implement evaporation function and precipitation input
# dynamAedes object to store attributes of the scenario
# Add new function for adci made by Daniele
# Check if dplyr can be just in suggested

# dynamAedes.m 1.0.0
## package: Add vignettes
Expand Down
8 changes: 4 additions & 4 deletions docs/404.html

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

14 changes: 7 additions & 7 deletions docs/articles/index.html

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

8 changes: 4 additions & 4 deletions docs/authors.html

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

8 changes: 4 additions & 4 deletions docs/index.html

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

27 changes: 21 additions & 6 deletions docs/news/index.html

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

8 changes: 4 additions & 4 deletions docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pandoc: 2.9.2.1
pkgdown: 2.0.7.9000
pkgdown_sha: 7b810a790f04971c32c9fb33b6ed6eab0e5d16a4
articles:
dynamAedes_local: dynamAedes_local.html
dynamAedes_punctual: dynamAedes_punctual.html
dynamAedes_regional: dynamAedes_regional.html
last_built: 2023-07-28T11:29Z
dynamAedes_01_punctual: dynamAedes_01_punctual.html
dynamAedes_02_local: dynamAedes_02_local.html
dynamAedes_03_regional: dynamAedes_03_regional.html
last_built: 2023-10-05T11:15Z

Loading

0 comments on commit a18c528

Please sign in to comment.