Skip to content

Commit

Permalink
drafted v 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-berti committed Dec 15, 2022
1 parent be95a61 commit b1fbc06
Show file tree
Hide file tree
Showing 54 changed files with 544 additions and 1,471 deletions.
81 changes: 80 additions & 1 deletion .Rproj.user/E4971820/cpp-definition-cache
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
[]
[
{
"file": "/home/eb97ziwi/Proj/enerscape/src/distance.h",
"file_last_write": 1664895205.0,
"definitions": [
{
"usr": "c:@F@distance#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#d#d#",
"kind": 6,
"parent_name": "",
"name": "distance(Rcpp::NumericVector, double, double)",
"file": "/home/eb97ziwi/Proj/enerscape/src/distance.h",
"line": 11,
"column": 15,
"hidden": false
}
],
"hidden": false
},
{
"file": "/home/eb97ziwi/Proj/enerscape/src/enerscape.cpp",
"file_last_write": 1664895433.0,
"definitions": [
{
"usr": "c:@F@energy#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#S0_#d#d#b#",
"kind": 6,
"parent_name": "",
"name": "energy(Rcpp::NumericVector, Rcpp::NumericVector, double, double, bool)",
"file": "/home/eb97ziwi/Proj/enerscape/src/enerscape.cpp",
"line": 16,
"column": 15,
"hidden": false
},
{
"usr": "c:@F@energyscape#$@N@Rcpp@S@Matrix>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#I#d#d#b#",
"kind": 6,
"parent_name": "",
"name": "energyscape(Rcpp::NumericMatrix, int, double, double, bool)",
"file": "/home/eb97ziwi/Proj/enerscape/src/enerscape.cpp",
"line": 49,
"column": 15,
"hidden": false
}
],
"hidden": false
},
{
"file": "/home/eb97ziwi/Proj/enerscape/src/neighbours.h",
"file_last_write": 1664895233.0,
"definitions": [
{
"usr": "c:@F@neighbours#I#I#I#$@N@Rcpp@S@Matrix>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#",
"kind": 6,
"parent_name": "",
"name": "neighbours(int, int, int, Rcpp::NumericMatrix)",
"file": "/home/eb97ziwi/Proj/enerscape/src/neighbours.h",
"line": 12,
"column": 15,
"hidden": false
}
],
"hidden": false
},
{
"file": "/home/eb97ziwi/Proj/enerscape/src/slope.h",
"file_last_write": 1664895257.0,
"definitions": [
{
"usr": "c:@F@slope#$@N@Rcpp@S@Vector>#VI14#@N@Rcpp@ST>1#T@PreserveStorage#d#d#",
"kind": 6,
"parent_name": "",
"name": "slope(Rcpp::NumericVector, double, double)",
"file": "/home/eb97ziwi/Proj/enerscape/src/slope.h",
"line": 11,
"column": 15,
"hidden": false
}
],
"hidden": false
}
]
2 changes: 1 addition & 1 deletion .Rproj.user/E4971820/pcs/files-pane.pper
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"ascending": true
}
],
"path": "~/enerscape"
"path": "~/Proj/enerscape"
}
12 changes: 6 additions & 6 deletions .Rproj.user/E4971820/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left": {
"splitterpos": 471,
"splitterpos": 337,
"topwindowstate": "HIDE",
"panelheight": 1140,
"windowheight": 1178
"panelheight": 818,
"windowheight": 856
},
"right": {
"splitterpos": 364,
"splitterpos": 431,
"topwindowstate": "NORMAL",
"panelheight": 1140,
"windowheight": 1178
"panelheight": 818,
"windowheight": 856
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/E4971820/pcs/workbench-pane.pper
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"TabSet1": 3,
"TabSet2": 0,
"TabSet2": 3,
"TabZoom": {}
}
4 changes: 2 additions & 2 deletions .Rproj.user/E4971820/persistent-state
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build-last-errors="[]"
build-last-errors-base-dir="~/enerscape/"
build-last-outputs="[{\"type\":0,\"output\":\"==> R CMD INSTALL --no-multiarch --with-keep.source enerscape\\n\\n\"},{\"type\":1,\"output\":\"* installing to library ‘/home/eb97ziwi/R/x86_64-pc-linux-gnu-library/4.1’\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"* installing *source* package ‘enerscape’ ...\\n\"},{\"type\":1,\"output\":\"** using staged installation\\n\"},{\"type\":1,\"output\":\"** R\\n\"},{\"type\":1,\"output\":\"** data\\n\"},{\"type\":1,\"output\":\"*** moving datasets to lazyload DB\\n\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":2,\"output\":\"Warning: /home/eb97ziwi/enerscape/man/enerscape_gridded.Rd:49: unknown macro '\\\\textit'\\n\"},{\"type\":2,\"output\":\"Warning: /home/eb97ziwi/enerscape/man/enerscape_merge.Rd:27: unknown macro '\\\\textit'\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** installing help indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** building package indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\"},{\"type\":1,\"output\":\"* DONE (enerscape)\\n\"},{\"type\":1,\"output\":\"\"}]"
build-last-errors-base-dir="~/Proj/enerscape/"
build-last-outputs="[{\"type\":0,\"output\":\"==> Rcpp::compileAttributes()\\n\\n\"},{\"type\":1,\"output\":\"* Updated R/RcppExports.R\\n\"},{\"type\":1,\"output\":\"\\n\"},{\"type\":0,\"output\":\"==> R CMD INSTALL --preclean --no-multiarch --with-keep.source enerscape\\n\\n\"},{\"type\":1,\"output\":\"* installing to library ‘/home/eb97ziwi/R/x86_64-pc-linux-gnu-library/4.2’\\n\"},{\"type\":1,\"output\":\"* installing *source* package ‘enerscape’ ...\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"g++ -std=gnu++14 -I\\\"/usr/share/R/include\\\" -DNDEBUG -I'/home/eb97ziwi/R/x86_64-pc-linux-gnu-library/4.2/Rcpp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-zYgbYq/r-base-4.2.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c RcppExports.cpp -o RcppExports.o\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** using staged installation\\n\"},{\"type\":1,\"output\":\"** libs\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"g++ -std=gnu++14 -I\\\"/usr/share/R/include\\\" -DNDEBUG -I'/home/eb97ziwi/R/x86_64-pc-linux-gnu-library/4.2/Rcpp/include' -fpic -g -O2 -fdebug-prefix-map=/build/r-base-zYgbYq/r-base-4.2.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c enerscape.cpp -o enerscape.o\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o enerscape.so RcppExports.o enerscape.o -L/usr/lib/R/lib -lR\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"installing to /home/eb97ziwi/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-enerscape/00new/enerscape/libs\\n\"},{\"type\":1,\"output\":\"** R\\n\"},{\"type\":1,\"output\":\"** data\\n\"},{\"type\":1,\"output\":\"*** moving datasets to lazyload DB\\n\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** installing help indices\\n\"},{\"type\":1,\"output\":\"*** copying figures\\n\"},{\"type\":1,\"output\":\"** building package indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** checking absolute paths in shared objects and dynamic libraries\\n\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\"},{\"type\":1,\"output\":\"* DONE (enerscape)\\n\"},{\"type\":1,\"output\":\"\"}]"
compile_pdf_state="{\"tab_visible\":false,\"running\":false,\"target_file\":\"\",\"output\":\"\",\"errors\":[]}"
files.monitored-path=""
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"ignoreCase\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOn\":[],\"matchOff\":[],\"replaceMatchOn\":[],\"replaceMatchOff\":[]},\"running\":false,\"replace\":false,\"preview\":false,\"gitFlag\":false,\"replacePattern\":\"\"}"
Expand Down
14 changes: 14 additions & 0 deletions .Rproj.user/E4971820/sources/prop/INDEX
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
~%2FDocuments%2Fenerscape-bench.R="4584E606"
~%2FProj%2Fenerscape%2FDESCRIPTION="2AA39DB9"
~%2FProj%2Fenerscape%2FNAMESPACE="647D670F"
~%2FProj%2Fenerscape%2Fsrc%2FRcppExports.cpp="062A3DA4"
~%2FProj%2Fenerscape%2Fsrc%2Fdistance.h="AA3B434F"
~%2FProj%2Fenerscape%2Fsrc%2Fenergyscape.cpp="B2EED60C"
~%2FProj%2Fenerscape%2Fsrc%2Fenerscape.cpp="35A69DF3"
~%2FProj%2Fenerscape%2Fsrc%2Fneighbours.h="F5033350"
~%2FProj%2Fenerscape%2Fsrc%2Frcpp_hello_world.cpp="D80A2861"
~%2FProj%2Fenerscape%2Fsrc%2Frcpp_neighbours.cpp="BFA94E37"
~%2FProj%2Fenerscape%2Fsrc%2Fslope.cpp="A0D3343E"
~%2FProj%2Fenerscape%2Fsrc%2Fslope.h="8B842BE7"
~%2FProj%2Fenerscape%2Ftests%2Ftestthat%2Ftest-cpp-functions.R="F7EC2347"
~%2FProj%2Fenerscape%2Ftests%2Ftestthat.R="3FFDA157"
~%2Fenerscape%2FDESCRIPTION="0B233340"
~%2Fenerscape%2FR%2Fdata.R="65E8B01C"
~%2Fenerscape%2FR%2Fenerscape_gridded.R="24BBDC9D"
Expand Down
10 changes: 10 additions & 0 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/home/eb97ziwi/Documents/enerscape-bench.R="D0EAC371"
/home/eb97ziwi/Proj/enerscape/DESCRIPTION="F8FE071B"
/home/eb97ziwi/Proj/enerscape/NAMESPACE="1EE9CDCB"
/home/eb97ziwi/Proj/enerscape/src/RcppExports.cpp="4DCCA75B"
/home/eb97ziwi/Proj/enerscape/src/distance.h="F61D409D"
/home/eb97ziwi/Proj/enerscape/src/enerscape.cpp="E09A4297"
/home/eb97ziwi/Proj/enerscape/src/neighbours.h="DF5E7469"
/home/eb97ziwi/Proj/enerscape/src/slope.h="471F7B9B"
/home/eb97ziwi/Proj/enerscape/tests/testthat.R="945208A1"
/home/eb97ziwi/Proj/enerscape/tests/testthat/test-cpp-functions.R="B788CACF"
/home/eb97ziwi/enerscape/DESCRIPTION="841B0F64"
/home/eb97ziwi/enerscape/R/data.R="7068BE25"
/home/eb97ziwi/enerscape/R/enerscape_gridded.R="05E88254"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
inst/doc
13 changes: 5 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: enerscape
Type: Package
Title: Compute
Energy Landscapes
Version: 0.2.0
Version: 1.0.0
Author: Emilio Berti
Maintainer: Emilio Berti <[email protected]>
Description: Compute energy landscapes using a digital elevation model raster and body mass of animals. Vignette available at: <https://emilio-berti.github.io/enerscape.html>.
Expand All @@ -11,18 +11,15 @@ Encoding: UTF-8
LazyData: true
Imports:
Rcpp,
raster,
gdistance,
rgdal,
rgeos,
sp,
Matrix
methods,
terra
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
LinkingTo: Rcpp
RoxygenNote: 7.1.1
RoxygenNote: 7.2.0
Depends:
R (>= 2.10)
Config/testthat/edition: 3
VignetteBuilder: knitr
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
useDynLib(enerscape, .registration=TRUE)
importFrom(Rcpp, evalCpp)
exportPattern("^[[:alpha:]]+")

importFrom("methods", "is")
importFrom("terra",
"rast", "rasterize", "writeRaster", "aggregate",
"res", "crs", "crs<-", "ext", "ext<-")
51 changes: 43 additions & 8 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

distance <- function(dem, center, res) {
.Call(`_enerscape_distance`, dem, center, res)
#' Spatial distances
#'
#' @param x matrix with values
#' @param center numeric value (double) with the value of the focal cell
#' @param res numeric value (double) of the spatial resolution of the matrix
#' @return Vector with values the distances between x and center
distances <- function(x, center, res) {
.Call(`_enerscape_distances`, x, center, res)
}

#' Energy Landscape
#'
#' @param slope vector with slopes
#' @param distance vector with distances
#' @param mass body mass of species (kg)
#' @param res numeric value (double) of the spatial resolution of the matrix
#' @param kcal (boolean) if to return the result in kCal (true) or J (false)
#' @return Vector with the energy cost of locomotion (EnergyScape)
energy <- function(slope, distance, mass, res, kcal = TRUE) {
.Call(`_enerscape_energy`, slope, distance, mass, res, kcal)
}

energyscape <- function(m, n = 4L, mass = 0, res = 0, kcal = TRUE) {
.Call(`_enerscape_energyscape`, m, n, mass, res, kcal)
#' Energy Landscape
#'
#' @param x matrix with values the elevation.
#' @param n (integer) number of neighbours to consider (either 4 or 8).
#' @param mass body mass of species (kg).
#' @param res numeric value (double) of the spatial resolution of the matrix.
#' @param kcal (boolean) if to return the result in kCal (true) or J (false).
#' @return Matrix with the energy cost of locomotion (EnergyScape).
energyscape <- function(x, n = 4L, mass = 0, res = 0, kcal = TRUE) {
.Call(`_enerscape_energyscape`, x, n, mass, res, kcal)
}

neighbours <- function(i, j, n, m) {
.Call(`_enerscape_neighbours`, i, j, n, m)
#' Neighbours
#'
#' @param i row index
#' @param j column index
#' @param n number of neighbours (4 or 8)
#' @param x matrix with values
#' @return Vector with values the neighours of x
neighbours <- function(i, j, n, x) {
.Call(`_enerscape_neighbours`, i, j, n, x)
}

slope <- function(dem, center, res) {
.Call(`_enerscape_slope`, dem, center, res)
#' Slopes
#'
#' @param x matrix with values
#' @param center numeric value (double) with the value of the focal cell
#' @param res numeric value (double) of the spatial resolution of the matrix
#' @return Vector with values the slopes (degrees) between x and center
slope <- function(x, center, res) {
.Call(`_enerscape_slope`, x, center, res)
}

24 changes: 12 additions & 12 deletions R/circuitscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ circuitscape_skeleton <- function(
path = NULL,
points = NULL
) {
if (is.null(en) | is.null(path) | is.null(points)) {
if (is.null(en) | is.null(points)) {
stop("Missing mandatory input")
}
if (class(points)[1] != "data.frame") {
if (class(points)[1] == "matrix") {
points <- as.data.frame(points)
if (is(points, "data.frame")) {
points <- as.matrix(points)
} else {
stop("points are not data.frame or matrix")
}
}
pr <- raster::rasterize(points, en$rasters$EnergyScape, na.rm = TRUE)
raster::writeRaster(en$rasters$EnergyScape, file.path(path, "/work.tif"),
overwrite = TRUE)
raster::writeRaster(pr, file.path(path, "/loc.tif"),
overwrite = TRUE)
loc <-
if (is.null(path)) path <- getwd()
pr <- rasterize(points, en, na.rm = TRUE)
writeRaster(en,
file.path(path, "EnergyScape.tif"),
overwrite = TRUE)
writeRaster(pr,
file.path(path, "loc.tif"),
overwrite = TRUE)
cs_file <- file(file.path(path, "circuitscape.ini"), open = "w")
if (!isOpen(cs_file)) {
stop("Connection to file cannot be established")
Expand All @@ -41,7 +41,7 @@ circuitscape_skeleton <- function(
"version = 5.0.0",
"",
"[Habitat raster or graph]",
paste0("habitat_file = ", path, "/work.tif"),
paste0("habitat_file = ", path, "/EnergyScape.tif"),
"habitat_map_is_resistances = true",
"",
"[Connection Scheme for raster habitat data]",
Expand Down
5 changes: 5 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
#' #' Pontzer, H. (2016). A unified theory for the energy cost of legged
#' locomotion. Biology Letters, 12(2), 20150935.
"pontzer"

#' Monte Sirente Digital Elevation Model
#'
#' A matrix with the digital elevation mode of the Monte Sirente (Central Italy).
"sirente"
57 changes: 0 additions & 57 deletions R/en_extrapolation.R

This file was deleted.

Loading

0 comments on commit b1fbc06

Please sign in to comment.