diff --git a/DESCRIPTION b/DESCRIPTION index c0362035..4cf7c42d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rSOILWAT2 -Version: 5.3.3 +Version: 5.4.0 Title: An Ecohydrological Ecosystem-Scale Water Balance Simulation Model -Description: Access to the C-based SOILWAT2 v6.6.0 and functionality for +Description: Access to the C-based SOILWAT2 v6.7.0 and functionality for SQLite-database of weather data. Authors@R: c( person( diff --git a/NEWS.md b/NEWS.md index 610523f0..d0e44fec 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,21 @@ +# rSOILWAT2 v5.4.0 +* `SOILWAT2` is updated to v6.7.0 which fixed vegetation establishment. +* This version produces identical simulation output + as the previous release under default values + (i.e., vegetation establishment is turned off). + +* Functionality to calculate and output establishment/recruitment of species + now works and is covered by tests (issue #225, @dschlaep). + Note that this functionality assesses yearly the chances of + species to recruit/establish based on simulated daily conditions; + however, establishment/recruitment outcomes are not utilized to inform the + simulation. + +## Changes to interface +* Class `swEstabSpecies` gains new slot `"vegType"` to specify vegetation type + of a species establishment parameters (issue #225, @dschlaep). + + # rSOILWAT2 v5.3.3 * This version produces identical simulation output as the previous release. * `get_soiltemp()` now correctly locates soil temperature output for all diff --git a/R/I_swEstab.R b/R/I_swEstab.R index 532c142f..c9fee11c 100644 --- a/R/I_swEstab.R +++ b/R/I_swEstab.R @@ -46,6 +46,7 @@ #' @name swEstabSpecies-class #' @export setClass("swEstabSpecies", slot = c(fileName = "character", Name = "character", + vegType = "integer", estab_lyrs = "integer", barsGERM = "numeric", barsESTAB = "numeric", min_pregerm_days = "integer", max_pregerm_days = "integer", min_wetdays_for_germ = "integer", max_drydays_postgerm = "integer", diff --git a/data-raw/prepare_testInput_objects.R b/data-raw/prepare_testInput_objects.R index 1408724f..a5d16948 100755 --- a/data-raw/prepare_testInput_objects.R +++ b/data-raw/prepare_testInput_objects.R @@ -21,7 +21,7 @@ dir_in <- file.path("inst", "extdata") dir_backup <- sub("extdata", "extdata_copy", dir_in, fixed = TRUE) dir_out <- file.path("tests", "test_data") -tests <- 1:5 +tests <- 1:6 examples <- paste0("example", tests) @@ -119,6 +119,20 @@ for (it in seq_along(tests)) { substr(fin[line], 1, 3) <- "-45" writeLines(fin, con = ftemp) +# example6: vegetation establishment + ftemp <- file.path(dir_in, examples[6], "Input", "estab.in") + fin <- readLines(ftemp) + line <- grep("calculate and output establishment", fin, fixed = TRUE) + stopifnot(length(line) == 1, line > 0, line < length(fin)) + substr(fin[line], 1, 1) <- "1" + writeLines(fin, con = ftemp) + + ftemp <- file.path(dir_in, examples[6], "Input", "outsetup.in") + fin <- readLines(ftemp) + line <- grep("establishment results", fin, fixed = TRUE) + stopifnot(length(line) == 1, line > 0, line < length(fin)) + fin[line] <- sub("OFF", "AVG", fin[line], fixed = TRUE) + writeLines(fin, con = ftemp) diff --git a/data/sw_exampleData.rda b/data/sw_exampleData.rda index 10c022ff..63e10f26 100644 Binary files a/data/sw_exampleData.rda and b/data/sw_exampleData.rda differ diff --git a/inst/extdata/example1/Input/estab.in b/inst/extdata/example1/Input/estab.in index d702c509..644438fe 100644 --- a/inst/extdata/example1/Input/estab.in +++ b/inst/extdata/example1/Input/estab.in @@ -11,6 +11,7 @@ # soil moisture and timing parameters required for the # species to establish in a given year. # There is no limit to the number of files in the list. +# File names with paths relative to the SOILWAT2 working directory (-d flag) -Input/bouteloua.estab -Input/bromus.estab +Input/estab/bouteloua.estab +Input/estab/bromus.estab diff --git a/inst/extdata/example1/Input/bouteloua.estab b/inst/extdata/example1/Input/estab/bouteloua.estab similarity index 51% rename from inst/extdata/example1/Input/bouteloua.estab rename to inst/extdata/example1/Input/estab/bouteloua.estab index 90d6eacd..43662ab2 100644 --- a/inst/extdata/example1/Input/bouteloua.estab +++ b/inst/extdata/example1/Input/estab/bouteloua.estab @@ -1,18 +1,19 @@ -bogr # 4-char name of species +bogr # 4-char name of species +3 # Vegetation type of species (0, trees; 1, shrubs; 2, forbs; 3 grasses) # soil layer parameters 2 # number of layers affecting establishment 10. # SWP (bars) requirement for germination (top layer) 15. # SWP (bars) requirement for establishment (average of top layers) # timing parameters in days 60 # first possible day of germination -180 # last possible day of germination +180 # last possible day of germination 2 # min number of consecutive "wet" days for germination to occur -40 # max number of consecutive "dry" days after germination allowing estab +40 # max number of consecutive "dry" days after germination allowing estab 5 # min number of consecutive "wet" days after germination before establishment -15 # min number of days between germination and establishment -75 # max number of days between germination and establishment +15 # min number of days between germination and establishment +75 # max number of days between germination and establishment # temperature parameters in C -5. # min temp threshold for germination -20. # max temp threshold for germination -0. # min temp threshold for establishment -20. # max temp threshold for establishment +5. # min temp threshold for germination +20. # max temp threshold for germination +0. # min temp threshold for establishment +20. # max temp threshold for establishment diff --git a/inst/extdata/example1/Input/bromus.estab b/inst/extdata/example1/Input/estab/bromus.estab similarity index 89% rename from inst/extdata/example1/Input/bromus.estab rename to inst/extdata/example1/Input/estab/bromus.estab index 3ae2beeb..5fe06103 100644 --- a/inst/extdata/example1/Input/bromus.estab +++ b/inst/extdata/example1/Input/estab/bromus.estab @@ -1,4 +1,5 @@ brte # 4-char name of species +3 # Vegetation type of species (0, trees; 1, shrubs; 2, forbs; 3 grasses) # soil layer parameters 3 # number of layers affecting establishment - 45 cm Harris and Hulbert 10. # SWP (bars) requirement for germination (top layer) - Harris @@ -7,7 +8,7 @@ brte # 4-char name of species 200 # first possible day of germination - Hulbert and Harris 365 # last possible day of germination - Hulbert 6 # min number of consecutive "wet" days for germination to occur - Hurlbert and Harris -45 # max number of consecutive "dry" days after germination allowing estab - Harris (longtime) +45 # max number of consecutive "dry" days after germination allowing estab - Harris (longtime) 6 # min number of consecutive "wet" days after germination before establishment - Harris 15 # min number of days between germination and establishment - Hulbert 90 # max number of days between germination and establishment - Harris and Hulbert @@ -15,4 +16,4 @@ brte # 4-char name of species 10. # min temp threshold for germination - Hulbert and Harris 30. # max temp threshold for germination - Hulbert and Harris 3. # min temp threshold for establishment - Harris -30. # max temp threshold for establishment - Harris and Hulbert +30. # max temp threshold for establishment - Harris and Hulbert diff --git a/src/SOILWAT2 b/src/SOILWAT2 index 436bfeb6..0a11f713 160000 --- a/src/SOILWAT2 +++ b/src/SOILWAT2 @@ -1 +1 @@ -Subproject commit 436bfeb6f5d03b7dd0e616015a6227988aa7d329 +Subproject commit 0a11f713f9eb3359d10da1e774c54ca5a4046e29 diff --git a/src/rSW_Output.c b/src/rSW_Output.c index acc3c26e..81b04948 100644 --- a/src/rSW_Output.c +++ b/src/rSW_Output.c @@ -59,9 +59,7 @@ void onSet_SW_OUT(SEXP OUT) { int *use, *timePeriods, *sumtype, *first_orig, *last_orig; // mykey and myobj are currently unused: // int *mykey, *myobj; - char - stub[10], - msg[200]; // message to print + char msg[200]; // message to print #ifdef RSWDEBUG int debug = 0; #endif @@ -89,19 +87,14 @@ void onSet_SW_OUT(SEXP OUT) { last_orig = INTEGER(GET_SLOT(OUT, install("last_orig"))); PROTECT(outfile = GET_SLOT(OUT, install("outfile"))); - if (use[eSW_Estab]) { - sumtype[eSW_Estab] = eSW_Sum; - first_orig[eSW_Estab] = 1; - timePeriods[eSW_Estab + 0 * SW_OUTNKEYS] = eSW_Year; - ForEachOutPeriod(i) { - timePeriods[eSW_Estab + i * SW_OUTNKEYS] = eSW_NoTime; - } - last_orig[eSW_Estab] = 366; - } - ForEachOutKey(k) { - msg_type = SW_OUT_read_onekey(k, sumtype[k], stub, first_orig[k], - last_orig[k], msg); + msg_type = SW_OUT_read_onekey( + k, + sumtype[k], + first_orig[k], + last_orig[k], + msg + ); if (msg_type > 0) { LogError(logfp, msg_type, "%s", msg); diff --git a/src/rSW_VegEstab.c b/src/rSW_VegEstab.c index 9d4ab2df..d096e7db 100644 --- a/src/rSW_VegEstab.c +++ b/src/rSW_VegEstab.c @@ -49,15 +49,23 @@ SEXP onGet_SW_VES(void) { SEXP VES; SEXP use; SEXP count; + PROTECT(swEstab = MAKE_CLASS("swEstab")); PROTECT(VES = NEW_OBJECT(swEstab)); - PROTECT(use = NEW_LOGICAL(1)); + PROTECT(count = NEW_INTEGER(1)); INTEGER(count)[0] = SW_VegEstab.count; + + PROTECT(use = NEW_LOGICAL(1)); LOGICAL(use)[0] = SW_VegEstab.use; + + SET_SLOT(VES, install("count"), count); SET_SLOT(VES, install("useEstab"), use); - if (SW_VegEstab.use) + + if (SW_VegEstab.use) { onGet_SW_VES_spps(VES); + } + UNPROTECT(4); return VES; } @@ -71,6 +79,7 @@ void onSet_SW_VES(SEXP VES) { PROTECT(use = GET_SLOT(VES,install("useEstab"))); PROTECT(count = GET_SLOT(VES,install("count"))); + if (LOGICAL(use)[0] == FALSE) { //LogError(logfp, LOGNOTE, "Establishment not used.\n"); SW_VegEstab.use = FALSE; @@ -82,7 +91,7 @@ void onSet_SW_VES(SEXP VES) { } else { SW_VegEstab.use = TRUE; for (i = 0; i < nSPPS; i++) - onSet_SW_VES_spp(VES, i); + onSet_SW_VES_spp(VES, i); // sets `SW_VegEstab.count` incrementally } } @@ -100,11 +109,12 @@ void onSet_SW_VES(SEXP VES) { void onGet_SW_VES_spps(SEXP SPP) { int i; SW_VEGESTAB_INFO *v; - SEXP fileName, name, estab_lyrs, barsGERM, barsESTAB, min_pregerm_days, max_pregerm_days, min_wetdays_for_germ, max_drydays_postgerm, min_wetdays_for_estab, min_days_germ2estab, + SEXP fileName, name, vegType, estab_lyrs, barsGERM, barsESTAB, min_pregerm_days, max_pregerm_days, min_wetdays_for_germ, max_drydays_postgerm, min_wetdays_for_estab, min_days_germ2estab, max_days_germ2estab, min_temp_germ, max_temp_germ, min_temp_estab, max_temp_estab; PROTECT(fileName = allocVector(STRSXP,SW_VegEstab.count)); PROTECT(name = allocVector(STRSXP,SW_VegEstab.count)); + PROTECT(vegType = NEW_INTEGER(SW_VegEstab.count)); PROTECT(estab_lyrs = NEW_INTEGER(SW_VegEstab.count)); PROTECT(barsGERM = allocVector(REALSXP,SW_VegEstab.count)); PROTECT(barsESTAB = allocVector(REALSXP,SW_VegEstab.count)); @@ -124,6 +134,7 @@ void onGet_SW_VES_spps(SEXP SPP) { v = SW_VegEstab.parms[i]; SET_STRING_ELT(fileName, i, mkChar(v->sppFileName)); SET_STRING_ELT(name, i, mkChar(v->sppname)); + INTEGER(vegType)[i] = v->vegType; INTEGER(estab_lyrs)[i] = v->estab_lyrs; REAL(barsGERM)[i] = v->bars[0]; REAL(barsESTAB)[i] = v->bars[1]; @@ -141,6 +152,7 @@ void onGet_SW_VES_spps(SEXP SPP) { } SET_SLOT(SPP, install("fileName"), fileName); SET_SLOT(SPP, install("Name"), name); + SET_SLOT(SPP, install("vegType"), vegType); SET_SLOT(SPP, install("estab_lyrs"), estab_lyrs); SET_SLOT(SPP, install("barsGERM"), barsGERM); SET_SLOT(SPP, install("barsESTAB"), barsESTAB); @@ -156,7 +168,7 @@ void onGet_SW_VES_spps(SEXP SPP) { SET_SLOT(SPP, install("min_temp_estab"), min_temp_estab); SET_SLOT(SPP, install("max_temp_estab"), max_temp_estab); - UNPROTECT(16); + UNPROTECT(17); } void onSet_SW_VES_spp(SEXP SPP, IntU i) { @@ -167,6 +179,7 @@ void onSet_SW_VES_spp(SEXP SPP, IntU i) { count = _new_species(); v = SW_VegEstab.parms[count]; + v->vegType = INTEGER(GET_SLOT(SPP, install("vegType")))[i]; v->estab_lyrs = INTEGER(GET_SLOT(SPP, install("estab_lyrs")))[i]; v->bars[SW_GERM_BARS] = REAL(GET_SLOT(SPP, install("barsGERM")))[i]; v->bars[SW_ESTAB_BARS] = REAL(GET_SLOT(SPP, install("barsESTAB")))[i]; diff --git a/tests/test_data/Ex1_input.rds b/tests/test_data/Ex1_input.rds index b05d9159..5f8b280c 100644 Binary files a/tests/test_data/Ex1_input.rds and b/tests/test_data/Ex1_input.rds differ diff --git a/tests/test_data/Ex1_output.rds b/tests/test_data/Ex1_output.rds index 004ee1e2..24e52bf1 100644 Binary files a/tests/test_data/Ex1_output.rds and b/tests/test_data/Ex1_output.rds differ diff --git a/tests/test_data/Ex2_input.rds b/tests/test_data/Ex2_input.rds index 0730a105..a41b1241 100644 Binary files a/tests/test_data/Ex2_input.rds and b/tests/test_data/Ex2_input.rds differ diff --git a/tests/test_data/Ex3_input.rds b/tests/test_data/Ex3_input.rds index 6c0a3ede..ecb94ceb 100644 Binary files a/tests/test_data/Ex3_input.rds and b/tests/test_data/Ex3_input.rds differ diff --git a/tests/test_data/Ex3_output.rds b/tests/test_data/Ex3_output.rds index 80402105..b4c536ec 100644 Binary files a/tests/test_data/Ex3_output.rds and b/tests/test_data/Ex3_output.rds differ diff --git a/tests/test_data/Ex4_input.rds b/tests/test_data/Ex4_input.rds index dd783787..b9f018ef 100644 Binary files a/tests/test_data/Ex4_input.rds and b/tests/test_data/Ex4_input.rds differ diff --git a/tests/test_data/Ex4_output.rds b/tests/test_data/Ex4_output.rds index 4ded758e..11178d67 100644 Binary files a/tests/test_data/Ex4_output.rds and b/tests/test_data/Ex4_output.rds differ diff --git a/tests/test_data/Ex5_input.rds b/tests/test_data/Ex5_input.rds index 17954b7f..6a2b8c21 100644 Binary files a/tests/test_data/Ex5_input.rds and b/tests/test_data/Ex5_input.rds differ diff --git a/tests/test_data/Ex5_output.rds b/tests/test_data/Ex5_output.rds index d24f7ffc..90d3b9c1 100644 Binary files a/tests/test_data/Ex5_output.rds and b/tests/test_data/Ex5_output.rds differ diff --git a/tests/test_data/Ex6_input.rds b/tests/test_data/Ex6_input.rds new file mode 100644 index 00000000..e65a10b0 Binary files /dev/null and b/tests/test_data/Ex6_input.rds differ diff --git a/tests/test_data/Ex6_output.rds b/tests/test_data/Ex6_output.rds new file mode 100644 index 00000000..254bc1d5 Binary files /dev/null and b/tests/test_data/Ex6_output.rds differ diff --git a/tests/test_data/Ex6_weather.rds b/tests/test_data/Ex6_weather.rds new file mode 100644 index 00000000..8d1b14d9 Binary files /dev/null and b/tests/test_data/Ex6_weather.rds differ