Skip to content

Commit

Permalink
replace reading of dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaMeyer committed Mar 23, 2024
1 parent 38d1c26 commit 43c45e5
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 62 deletions.
4 changes: 2 additions & 2 deletions R/aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
#' library(viridis)
#'
#' # prepare sample data:
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
#' data(cookfarm)
#' dat <- aggregate(cookfarm[,c("VW","Easting","Northing")],by=list(as.character(cookfarm$SOURCEID)),mean)
#' pts <- st_as_sf(dat,coords=c("Easting","Northing"))
#' pts$ID <- 1:nrow(pts)
#' set.seed(100)
Expand Down
4 changes: 2 additions & 2 deletions R/calibrate_aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#' library(latticeExtra)
#'
#' #' # prepare sample data:
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
#' data(cookfarm)
#' dat <- aggregate(cookfarm[,c("VW","Easting","Northing")],by=list(as.character(cookfarm$SOURCEID)),mean)
#' pts <- st_as_sf(dat,coords=c("Easting","Northing"))
#' pts$ID <- 1:nrow(pts)
#' studyArea <- rast(system.file("extdata","predictors_2012-03-25.tif",package="CAST"))[[1:8]]
Expand Down
4 changes: 2 additions & 2 deletions R/geodist.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
#'############Distances in temporal space
#' library(lubridate)
#' library(ggplot2)
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- st_as_sf(dat,coords=c("Easting","Northing"))
#' data(cookfarm)
#' dat <- st_as_sf(cookfarm,coords=c("Easting","Northing"))
#' st_crs(dat) <- 26911
#' trainDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2010,]
#' predictionDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2011,]
Expand Down
4 changes: 2 additions & 2 deletions R/global_validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' @author Hanna Meyer
#' @seealso \code{\link{CreateSpacetimeFolds}}
#' @examples
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- dat[sample(1:nrow(dat),500),]
#' data(cookfarm)
#' dat <- cookfarm[sample(1:nrow(cookfarm),500),]
#' indices <- CreateSpacetimeFolds(dat,"SOURCEID","Date")
#' ctrl <- caret::trainControl(method="cv",index = indices$index,savePredictions="final")
#' model <- caret::train(dat[,c("DEM","TWI","BLD")],dat$VW, method="rf", trControl=ctrl, ntree=10)
Expand Down
6 changes: 3 additions & 3 deletions R/knndm.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@
#' library(ggplot2)
#'
#' ### prepare sample data:
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
#' by=list(as.character(dat$SOURCEID)),mean)
#' data(cookfarm)
#' dat <- aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
#' by=list(as.character(cookfarm$SOURCEID)),mean)
#' pts <- dat[,-1]
#' pts <- st_as_sf(pts,coords=c("Easting","Northing"))
#' st_crs(pts) <- 26911
Expand Down
6 changes: 3 additions & 3 deletions R/nndm.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
#' library(terra)
#'
#' ### prepare sample data:
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
#' by=list(as.character(dat$SOURCEID)),mean)
#' data(cookfarm)
#' dat <- aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
#' by=list(as.character(cookfarm$SOURCEID)),mean)
#' pts <- dat[,-1]
#' pts <- st_as_sf(pts,coords=c("Easting","Northing"))
#' st_crs(pts) <- 26911
Expand Down
3 changes: 2 additions & 1 deletion R/normalize_DI.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#'
#' # prepare sample data:
#' dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
#' dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
#' data(cookfarm)
#' dat <- aggregate(cookfarm[,c("VW","Easting","Northing")],by=list(as.character(cookfarm$SOURCEID)),mean)
#' pts <- st_as_sf(dat,coords=c("Easting","Northing"))
#' pts$ID <- 1:nrow(pts)
#' set.seed(100)
Expand Down
6 changes: 0 additions & 6 deletions data-raw/create-cookfarm.R

This file was deleted.

Binary file removed inst/extdata/Cookfarm.RDS
Binary file not shown.
Binary file removed inst/extdata/bioclim_global.tif
Binary file not shown.
4 changes: 2 additions & 2 deletions man/aoa.Rd

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

4 changes: 2 additions & 2 deletions man/calibrate_aoa.Rd

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

4 changes: 2 additions & 2 deletions man/geodist.Rd

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

4 changes: 2 additions & 2 deletions man/global_validation.Rd

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

6 changes: 3 additions & 3 deletions man/knndm.Rd

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

6 changes: 3 additions & 3 deletions man/nndm.Rd

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

3 changes: 2 additions & 1 deletion man/normalize_DI.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-aoa.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
loaddata <- function() {
# prepare sample data:
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- aggregate(cookfarm[,c("VW","Easting","Northing")],by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- sf::st_as_sf(dat,coords=c("Easting","Northing"))
pts$ID <- 1:nrow(pts)
set.seed(100)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-geodist.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ test_that("geodist works with categorical variables in feature space", {

test_that("geodist works in temporal space", {

dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- sf::st_as_sf(dat,coords=c("Easting","Northing"))
data(cookfarm)
dat <- sf::st_as_sf(cookfarm,coords=c("Easting","Northing"))
sf::st_crs(dat) <- 26911
trainDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2010,]
predictionDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2011,]
Expand All @@ -282,8 +282,8 @@ expect_equal(mean_prediction_to_sample, 4674.37)
})

test_that("geodist works in temporal space and with CV", {
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- sf::st_as_sf(dat,coords=c("Easting","Northing"))
data(cookfarm)
dat <- sf::st_as_sf(cookfarm,coords=c("Easting","Northing"))
sf::st_crs(dat) <- 26911
trainDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2010,]
predictionDat <- dat[dat$altitude==-0.3&lubridate::year(dat$Date)==2011,]
Expand Down
30 changes: 15 additions & 15 deletions tests/testthat/test-knndm.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ test_that("kNNDM yields the expected results with SpatRast modeldomain", {
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand All @@ -214,9 +214,9 @@ test_that("kNNDM works in feature space with kmeans clustering and raster as mod
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand All @@ -238,9 +238,9 @@ test_that("kNNDM works in feature space with hierarchical clustering and raster
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand Down Expand Up @@ -284,9 +284,9 @@ test_that("kNNDM works in feature space with categorical variables and predpoint
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand Down Expand Up @@ -365,9 +365,9 @@ test_that("kNNDM works in feature space with Mahalanobis distance without cluste
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-nndm.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ test_that("NNDM yields the expected results with SpatRast modeldomain", {
set.seed(1234)

# prepare sample data
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- terra::aggregate(dat[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(dat$SOURCEID)),mean)
data(cookfarm)
dat <- terra::aggregate(cookfarm[,c("DEM","TWI", "NDRE.M", "Easting", "Northing","VW")],
by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- dat[,-1]
pts <- sf::st_as_sf(pts,coords=c("Easting","Northing"))
sf::st_crs(pts) <- 26911
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_trainDI.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
loaddata <- function() {
# prepare sample data:
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
data("cookfarm")
dat <- aggregate(cookfarm[,c("VW","Easting","Northing")],by=list(as.character(cookfarm$SOURCEID)),mean)
pts <- sf::st_as_sf(dat,coords=c("Easting","Northing"))
pts$ID <- 1:nrow(pts)
set.seed(100)
Expand Down

0 comments on commit 43c45e5

Please sign in to comment.