Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use correct template raster and run 1 disturbance at a time #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions tests/spatial_integration_test/run_spatial_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

## It is important to set the virtual environment when calling Python scripts
## from R. This does it:

library(reproducible) #install from CRAN if missing
#you will need googledrive
library(googledrive)
library(reticulate)
virtualenv_list()
#[1] "r-reticulate"
Expand All @@ -16,15 +20,15 @@ reticulate::import("sys")$executable

## This imports the libcbm Python scripts maintained by Scott Morken for the
## CAT and checks the version.
libcbm <- reticulate::import("libcbm")
print(reticulate::py_get_attr(libcbm, "__version__"))
# libcbm <- reticulate::import("libcbm")
# print(reticulate::py_get_attr(libcbm, "__version__"))
#'2.6.0'

## Scott modified a version of libcbmr that also needs to be loaded. This does
## it.
install.packages("remotes")
remotes::install_github("smorken/libcbmr")
library(libcbmr)
# install.packages("remotes")
# remotes::install_github("smorken/libcbmr")
devtools::load_all(".")

## Modifications to find inputs to the stand alone version CBM_core provided to
## Scott from CBoisvenue
Expand All @@ -42,7 +46,11 @@ disturbance_rasters <- {
rasts
}

ldsp_test_area <- terra::rast(file.path(inputsScott,"ldSp_TestArea.tif"))
ldsp_test_area <- reproducible::prepInputs(url = "https://drive.google.com/file/d/1eqRaj3txJBQHnMJ_WWLnUY-Gx5XAW69S/view?usp=drive_link",
destinationPath = "tests/spatial_integration_test/")
#this object is actually 30 x 30 metres and has the correct number of pixels to match spatialDT
disturbance_rasters <- reproducible::postProcess(disturbance_rasters, rasterToMatch = ldsp_test_area,
method = "near")

#extract the growth increments from the nested environments
gc_df <- NULL
Expand Down Expand Up @@ -153,7 +161,7 @@ colnames(spinup_parameter_redup) <- c("spinup_record_idx", "pixelGroup")
growth_increment_pre_merge <- data.frame(
pixelGroup = spatial_inv_gc_merge$pixelGroup,
gcid = spatial_inv_gc_merge$growth_curve_id,
sw_hw = as.integer(spatial_inv_gc_merge$is_sw)
sw_hw = as.integer(spatial_inv_gc_merge$is_sw) #this is already in spinup paramters
)
growth_increment_pre_merge <- growth_increment_pre_merge[
!duplicated(growth_increment_pre_merge$pixelGroup),
Expand Down Expand Up @@ -238,12 +246,13 @@ cbm_simulation_records$cbm_record_id <- as.integer(
rownames(cbm_simulation_records)
)

#TODO: figure out which pixelGroups are disturbed on the annual basis.
cbm_simulation_records <- cbm_simulation_records[
c(
"ldSp_TestArea",
"1998",
"1999",
"2000",
# "1999",
# "2000",
"cbm_record_id",
"spinup_record_idx"
)
Expand All @@ -259,9 +268,9 @@ cbm_simulation_records_expand <- merge(
spatial_data_merge,
by = c(
"ldSp_TestArea",
"1998",
"1999",
"2000"
"1998"#,
# "1999",
# "2000"
),
all.y = TRUE
)
Expand Down