Skip to content

Commit

Permalink
Update website from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Jul 12, 2024
2 parents 1c929f5 + 7fabea4 commit f752cac
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 91 deletions.
37 changes: 18 additions & 19 deletions data-raw/make_data/create_lacerta_data.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### THIS IS NOW OBSOLETE AS THE DATASETS ARE GENERATED IN THE OVERVIEW VIGNETTE


# download presences
library(rgbif)
# download file
Expand Down Expand Up @@ -50,13 +53,7 @@ land_mask <- crop(land_mask, iberia_poly)
# and mask to the polygon
land_mask <- mask(land_mask, iberia_poly)
gdal(warn = 3)
writeCDF(land_mask, "./inst/extdata/lacerta_land_mask.nc",
compression = 9, split = TRUE, overwrite = TRUE
)
# fix time axis (this is a workaround if we open the file with sf)
nc_in <- ncdf4::nc_open("./inst/extdata/lacerta_land_mask.nc", write = TRUE)
ncdf4::ncatt_put(nc_in, varid = "time", attname = "axis", attval = "T")
ncdf4::nc_close(nc_in)
terra::saveRDS(land_mask, "./inst/extdata/lacerta_land_mask.rds")


climate_vars <- get_vars_for_dataset("WorldClim_2.1_10m")
Expand All @@ -67,13 +64,14 @@ climate_present <- pastclim::region_slice(
crop = iberia_poly
)

writeCDF(climate_present, "./inst/extdata/lacerta_climate_present_10m.nc",
compression = 9, split = TRUE, overwrite = TRUE
)
terra::saveRDS(climate_present, "./inst/extdata/lacerta_climate_present_10m.rds")
#writeCDF(climate_present, "./inst/extdata/lacerta_climate_present_10m.nc",
# compression = 9, split = TRUE, overwrite = TRUE
#)
# fix time axis (this is a workaround if we open the file with sf)
nc_in <- ncdf4::nc_open("./inst/extdata/lacerta_climate_present_10m.nc", write = TRUE)
ncdf4::ncatt_put(nc_in, varid = "time", attname = "axis", attval = "T")
ncdf4::nc_close(nc_in)
#nc_in <- ncdf4::nc_open("./inst/extdata/lacerta_climate_present_10m.nc", write = TRUE)
#ncdf4::ncatt_put(nc_in, varid = "time", attname = "axis", attval = "T")
#ncdf4::nc_close(nc_in)


vars_uncor <- c("bio15", "bio05", "bio13", "bio06")
Expand All @@ -84,13 +82,14 @@ climate_future <- pastclim::region_slice(
dataset = "WorldClim_2.1_HadGEM3-GC31-LL_ssp245_10m",
crop = iberia_poly
)
writeCDF(climate_future, "./inst/extdata/lacerta_climate_future_10m.nc",
compression = 9, split = TRUE, overwrite = TRUE
)
terra::saveRDS(climate_future, "./inst/extdata/lacerta_climate_future_10m.rds")
#writeCDF(climate_future, "./inst/extdata/lacerta_climate_future_10m.nc",
# compression = 9, split = TRUE, overwrite = TRUE
#)
# fix time axis (this is a workaround if we open the file with sf)
nc_in <- ncdf4::nc_open("./inst/extdata/lacerta_climate_future_10m.nc", write = TRUE)
ncdf4::ncatt_put(nc_in, varid = "time", attname = "axis", attval = "T")
ncdf4::nc_close(nc_in)
#nc_in <- ncdf4::nc_open("./inst/extdata/lacerta_climate_future_10m.nc", write = TRUE)
#ncdf4::ncatt_put(nc_in, varid = "time", attname = "axis", attval = "T")
#ncdf4::nc_close(nc_in)

#####
# from the vignette, we save
Expand Down
Binary file modified data/lacerta.rda
Binary file not shown.
Binary file modified data/lacerta_ensemble.rda
Binary file not shown.
Binary file modified data/lacerta_rep_ens.rda
Binary file not shown.
Binary file modified data/lacertidae_background.rda
Binary file not shown.
Binary file removed inst/extdata/lacerta_climate_future_10m.nc
Binary file not shown.
Binary file added inst/extdata/lacerta_climate_future_10m.rds
Binary file not shown.
Binary file removed inst/extdata/lacerta_climate_present_10m.nc
Binary file not shown.
Binary file added inst/extdata/lacerta_climate_present_10m.rds
Binary file not shown.
Binary file added inst/extdata/lacerta_coords.RDS
Binary file not shown.
Binary file removed inst/extdata/lacerta_land_mask.nc
Binary file not shown.
Binary file added inst/extdata/lacerta_land_mask.rds
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test_clamp_predictors.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test_that("clamping_predictor works on SpatRasters",{
# get current climate and subset to 3 variables
climate_present <- terra::rast(system.file("extdata/lacerta_climate_present_10m.nc",
climate_present <- terra::readRDS(system.file("extdata/lacerta_climate_present_10m.rds",
package = "tidysdm"
))
climate_present <- climate_present[[c("bio05","bio13","bio06","bio15")]]
lacerta_env <- bind_cols(terra::extract(climate_present, lacerta[,c(3,2)], ID = FALSE))
# now get future climate
climate_future <- terra::rast(system.file("extdata/lacerta_climate_future_10m.nc",
climate_future <- terra::readRDS(system.file("extdata/lacerta_climate_future_10m.rds",
package = "tidysdm"
))
climate_future <- climate_future [[names(climate_present)]]
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_extrapol_mess.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("mess_predictor works on SpatRasters",{
# now get future climate
climate_future <- terra::rast(system.file("extdata/lacerta_climate_future_10m.nc",
climate_future <- terra::readRDS(system.file("extdata/lacerta_climate_future_10m.rds",
package = "tidysdm"
))
mess_rast <- extrapol_mess(climate_future, training = lacerta_thin, .col= class)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_filter_collinear.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test_that("filter collinear variables with cor_caret", {


# test method on SpatRaster
climate_present <- terra::rast(system.file("extdata/lacerta_climate_present_10m.nc",
climate_present <- terra::readRDS(system.file("extdata/lacerta_climate_present_10m.rds",
package = "tidysdm"
))
cor_spatraster_ken <- filter_collinear(climate_present, cor_type = "kendall")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_overlap_niche.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_that("niche_overlap quantifies difference between rasters",{
climate_present <- terra::rast(system.file("extdata/lacerta_climate_present_10m.nc",
climate_present <- terra::readRDS(system.file("extdata/lacerta_climate_present_10m.rds",
package = "tidysdm"
))

climate_future <- terra::rast(system.file("extdata/lacerta_climate_future_10m.nc",
climate_future <- terra::readRDS(system.file("extdata/lacerta_climate_future_10m.rds",
package = "tidysdm"
))
lacerta_present<-predict_raster(lacerta_ensemble, climate_present)
Expand Down
Loading

0 comments on commit f752cac

Please sign in to comment.