Skip to content

Commit a498fd3

Browse files
committed
Merge branch 'main' into fvsOLrelease
2 parents 2d4e67f + 1ad3f00 commit a498fd3

32 files changed

Lines changed: 264 additions & 186 deletions

fvsOL/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: fvsOL
22
Title: Forest Vegetation Simulator
3-
Version: 2022.07.01
3+
Version: 2022.09.30
44
Authors@R: c(person("Nicholas", "Crookston", email = "ncrookston.fs@gmail.com",
55
role = c("aut")),
66
person("Michael", "Shettles", email = "michael.a.shettles@usda.gov",

fvsOL/R/componentWins.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ cat ("in PlantNaturalFullWin code, globals$currentCmdDefs=",globals$currentCmdDe
260260
list(
261261
mkScheduleBox("pnDOD",prms,"Schedule the date of disturbance",
262262
globals,input,output),
263-
div(style="background-color: rgb(255,240,240)",
263+
if(full){div(style="background-color: rgb(255,240,240)",
264264
myInlineTextInput("pnYD", "Years following disturbance for site preparation: ",
265265
globals$currentCmdDefs["pnYD"]),
266266
fixedRow(
@@ -269,7 +269,7 @@ cat ("in PlantNaturalFullWin code, globals$currentCmdDefs=",globals$currentCmdDe
269269
column(width=6,
270270
myInlineTextInput("pnPMch", "% mechanically scarified: ",
271271
globals$currentCmdDefs["pnPMch"]))
272-
)),
272+
))},
273273
div(style="background-color: rgb(240,240,255)",
274274
fixedRow(
275275
column(width=5,
@@ -332,15 +332,14 @@ cat ("in PlantNaturalFullWin code, globals$currentCmdDefs=",globals$currentCmdDe
332332

333333
PlantNaturalFullWin.mkKeyWrd <- function(input,output,full=TRUE)
334334
{
335-
kwds = list()
335+
kwds = sprintf("Estab %10s",input$pnDOD)
336336
cat ("in PlantNaturalFullWin.mkKeyWrd\n")
337-
if (full & input$pnPBrn != " ") kwds = sprintf("\nBurnPrep %10s%10s",
338-
as.character(as.numeric(input$pnDOD)+as.numeric(input$pnYD)),input$PBrn)
339-
if (full & input$pnPMch != " ") kwds = if (length(kwds)) paste0(kwds,
340-
sprintf("\nMechPrep %10s%10s",
341-
as.character(as.numeric(input$pnDOD)+as.numeric(input$pnYD)),input$pnPMch)) else
337+
if (full & (!is.null(input$pnPBrn) && input$pnPBrn != " ")) kwds = paste0(kwds,
338+
sprintf("\nBurnPrep %10s%10s",
339+
as.character(as.numeric(input$pnDOD)+as.numeric(input$pnYD)),input$pnPBrn))
340+
if (full & (!is.null(input$pnPMch) && input$pnPMch != " ")) kwds = paste0(kwds,
342341
sprintf("\nMechPrep %10s%10s",
343-
as.character(as.numeric(input$pnDOD)+as.numeric(input$pnYD)),input$pnPMch)
342+
as.character(as.numeric(input$pnDOD)+as.numeric(input$pnYD)),input$pnPMch))
344343
kwds = if (length(kwds)) paste0(kwds,"\n",if (input$pnSprt == "1") "Sprout" else "NoSprout") else
345344
if (input$pnSprt == "1") "Sprout" else "NoSprout"
346345
if (full) kwds = paste0(kwds,"\n",if (input$pnIng == "1") "InGrow" else "NoInGrow")

fvsOL/R/externalCallable.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id$
1+
# $Id: externalCallable.R 4018 2022-07-27 22:59:15Z nickcrookston $
22
#
33
#' Build an FVS run in a project
44
#'
@@ -242,7 +242,7 @@ extnFromRaw = function(x) unserialize(memDecompress(x,type="gzip"))
242242
#' @export
243243
extnListRuns <- function (prjDir=getwd())
244244
{
245-
if (!dir.exists(prjDir)) return(NULL)
245+
if (!dir.exists(prjDir)) return(NULL)
246246
prjDir = normalizePath(prjDir)
247247
db = connectFVSProjectDB(prjDir)
248248
on.exit(dbDisconnect(db))
@@ -279,7 +279,7 @@ extnDeleteRuns <- function (prjDir=NULL,runUUIDs=NULL,delOutput=TRUE)
279279
{
280280
if (is.null(runUUIDs)) stop("runUUIDs must be specified.")
281281
if (is.null(prjDir)) prjDir=getwd()
282-
if (!dir.exists(prjDir)) return(NULL)
282+
if (!dir.exists(prjDir)) return(NULL)
283283
prjDir = normalizePath(prjDir)
284284
db = connectFVSProjectDB(prjDir)
285285
on.exit({
@@ -532,7 +532,7 @@ extnGetComponentKwds <- function(prjDir=getwd(),runUUID,returnType="fvsCmp")
532532
{
533533
if (missing(runUUID)) stop("runUUID required")
534534
if (! returnType %in% c("fvsCmp","raw","character")) stop ("invalid value for 'returnType'")
535-
prjDir = normalizePath(prjDir)
535+
prjDir = normalizePath(prjDir)
536536
db = connectFVSProjectDB(prjDir)
537537
on.exit(dbDisconnect(db))
538538
fvsRun = loadFVSRun(db,runUUID)
@@ -937,7 +937,6 @@ extnSimulateRun <- function(prjDir=getwd(),runUUID,fvsBin="FVSBin",ncpu=detectCo
937937
#for testing:
938938
#prjDir=getwd();runUUID=extnListRuns()[1,1];fvsBin="FVSBin";ncpu=detectCores()
939939
#keyFileName=NULL;wait=FALSE;verbose=TRUE
940-
devVersion <<- "fvsOLdev" %in% (.packages())
941940
curdir=getwd()
942941
if (missing(runUUID)) stop("runUUID required")
943942
setwd(prjDir)

fvsOL/R/fvsRunUtilities.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id$
1+
# $Id: fvsRunUtilities.R 3982 2022-05-10 18:07:19Z mshettles521 $
22

33
loadStandTableData <- function (globals, dbIcon)
44
{
@@ -231,6 +231,7 @@ cat("mkSimCnts, foundStand=",foundStand," start=",start," end=",end,
231231
paste0("length(list)=",length(list)) else sels,"\n")
232232
if (length(fvsRun$stands)) for (i in start:end)
233233
{
234+
if(length(fvsRun$stands) < i) break
234235
## these two lines are needed to deal with old runs that may not have these elements in the stand class
235236
if (class(fvsRun$stands[[i]]$rep )!="numeric") fvsRun$stands[[i]]$rep =0
236237
if (class(fvsRun$stands[[i]]$repwt)!="numeric") fvsRun$stands[[i]]$repwt=1
@@ -852,8 +853,8 @@ mkModMCats <- function(globals)
852853
"Modify Root Disease bark beetles" = "keyword.wrd3.wrd_brk_btl")))
853854
catsel = append(catsel,list(
854855
"Modify Sprouting" = c(
855-
"Turn off Sprouting" = "keyword.estbstrp.NoSprout",
856-
"Adjust Sprouting" = "keyword.estbstrp.Sprout"),
856+
"Turn off Sprouting" = "Estab keyword.estbstrp.NoSprout",
857+
"Adjust Sprouting" = "Estab keyword.estbstrp.Sprout"),
857858
"Modify Percent Canopy Cover" = c(
858859
"Adjust Overlap Correction" = "keyword.base.CCAdj")))
859860
catsel

fvsOL/R/mkInputElements.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id$
1+
# $Id: mkInputElements.R 4001 2022-05-23 15:04:37Z mshettles521 $
22

33
mkeltList <- function (pkeys,prms,globals,input,output,
44
cndflag=FALSE,funcflag=FALSE,comptitle=NULL)
@@ -428,6 +428,7 @@ mkVarList <- function (globals)
428428
varList = c(
429429
" "=" ",
430430
"Age: Age at beginning of an FVS cycle"="Age",
431+
"AgeCmp: Estimated average age for the dominant size class"="AgeCmp",
431432
"Aspect: Aspect in degrees"="Aspect",
432433
"BaDBH: Before thin quadractic mean DBH"="BaDBH",
433434
"BBA: Before thin basal area"="BBA",
@@ -560,10 +561,12 @@ mkFuncList <- function (globals)
560561
"DBHDist: Returns the diameter of the tree corresponding to the nominal percentile in the distribution of one of 11 specific attributes"="DBHDist",
561562
"Decade: Returns the argument the corresponds to the decade the simulation is in"="Decade",
562563
"HTDist: Returns the height of the tree corresponding to the nominal percentile in the trees per acre distribution"="HTDist",
564+
"Index: Returns the value associated with the index specified in the first argument"="Index",
563565
"LinInt: Returns a linear interpolation between points on a simple Y-over-X graph"="LinInt",
564566
"MaxIndex: Returns the argument index corresponding to the largest value"="MaxIndex",
565567
"MinIndex: Returns the argument index corresponding to the smallest value"="MinIndex",
566568
"Normal: Returns a random normal variate given a mean and std. dev"="Normal",
569+
"PointID: Returns the inventory point number corresponding to the FVS sequential point number"="PointID",
567570
"SpMcDBH: Returns the trees, basal area, or one of 10 other attributes for trees of a given species, tree value class, or tree-size range"="SpMcDBH",
568571
"StrStat: Returns the information in the structural statistics report under before or after thinning conditions"="StrStat",
569572
"SumStat: Returns values from the Summary Statistics table"="SumStat",

fvsOL/R/server.R

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mkGlobals <- setRefClass("globals",
110110
specLvl="list",dClsLvl="list",htClsLvl="list",treeLvl="list",tbsFinal="list",
111111
selRuns = "character", selUuids = "character",selAllVars="logical",
112112
explorePass="numeric",lastNewPrj="character",prjFilesOnly="logical",
113-
tableMessage="logical",exploring="logical"))
113+
tableMessage="logical",exploring="logical", RepsDesign='logical'))
114114

115115
isLocal <- function () Sys.getenv('SHINY_PORT') == ""
116116

@@ -146,7 +146,7 @@ zipList <- list(
146146
"Output data base for for all runs" = "outdb",
147147
"Keyword file for current run" = "key",
148148
"FVS output file for current run" = "out",
149-
"SVS output files for current run" = "subdir",
149+
"Visualize output files for current run" = "subdir",
150150
"Input data base FVS_Data.db" = "FVS_Data",
151151
"Spatial data (SpatialData.RData)" = "SpatialData")
152152
selZip <- unlist(zipList[1:4])
@@ -3987,8 +3987,28 @@ cat ("changeind=",globals$changeind,"\n")
39873987
cat("Nulling uiRunPlot at Save and Run\n")
39883988
output$uiRunPlot <- output$uiErrorScan <- renderUI(NULL)
39893989
globals$currentQuickPlot = character(0)
3990-
# timeing checks.
3990+
# timing checks.
39913991
thisYr = as.numeric(format(Sys.time(), "%Y"))
3992+
# First check to see if required start year, end year, or cycle length fields are blank.
3993+
if (input$startyr =="") {
3994+
session$sendCustomMessage(type = "infomessage",
3995+
message = paste0("The common starting year is blank."))
3996+
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
3997+
return()
3998+
}
3999+
if (input$endyr =="") {
4000+
session$sendCustomMessage(type = "infomessage",
4001+
message = paste0("The common ending year is blank."))
4002+
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
4003+
return()
4004+
}
4005+
if (input$cyclelen =="") {
4006+
session$sendCustomMessage(type = "infomessage",
4007+
message = paste0("The growth and reporting interval is blank."))
4008+
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
4009+
return()
4010+
}
4011+
# other start year checks
39924012
for(i in 1:length(globals$fvsRun$stands)){
39934013
if (((input$startyr !="" && ((as.numeric(input$startyr)) > (thisYr + 50))) ||
39944014
((input$startyr !="") && nchar(input$startyr) > 4))){
@@ -4005,14 +4025,8 @@ cat("Nulling uiRunPlot at Save and Run\n")
40054025
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
40064026
return()
40074027
}
4008-
if (input$startyr =="") {
4009-
session$sendCustomMessage(type = "infomessage",
4010-
message = paste0("The common starting year is blank."))
4011-
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
4012-
return()
4013-
}
40144028
}
4015-
# End year checks
4029+
# other end year checks
40164030
for(i in 1:length(globals$fvsRun$stands)){
40174031
if (((input$endyr !="" && ((as.numeric(input$endyr)) >
40184032
(as.numeric(input$cyclelen) * 40 + as.numeric(input$startyr)))) ||
@@ -4031,14 +4045,8 @@ cat("Nulling uiRunPlot at Save and Run\n")
40314045
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
40324046
return()
40334047
}
4034-
if (input$endyr =="") {
4035-
session$sendCustomMessage(type = "infomessage",
4036-
message = paste0("The common ending year is blank."))
4037-
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
4038-
return()
4039-
}
40404048
}
4041-
# Cycle length checks
4049+
# other cycle length check
40424050
if (((input$cyclelen !="" && ((as.numeric(input$cyclelen)) > 50))) ||
40434051
((input$cyclelen !="") && nchar(input$cyclelen) > 4)){
40444052
session$sendCustomMessage(type = "infomessage",
@@ -4047,12 +4055,6 @@ cat("Nulling uiRunPlot at Save and Run\n")
40474055
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
40484056
return()
40494057
}
4050-
if (input$cyclelen =="") {
4051-
session$sendCustomMessage(type = "infomessage",
4052-
message = paste0("The growth interval is blank."))
4053-
updateTabsetPanel(session=session,inputId="rightPan",selected="Time")
4054-
return()
4055-
}
40564058
baseCycles = seq(as.numeric(globals$fvsRun$startyr),as.numeric(globals$fvsRun$endyr),
40574059
as.numeric(globals$fvsRun$cyclelen))
40584060
cycleat = scan(text=gsub(";"," ",gsub(","," ",globals$fvsRun$cycleat)),
@@ -4077,7 +4079,7 @@ cat("Nulling uiRunPlot at Save and Run\n")
40774079
}
40784080
}
40794081
}
4080-
}
4082+
}
40814083
progress <- shiny::Progress$new(session,min=1,
40824084
max=length(globals$fvsRun$stands)+10)
40834085
progress$set(message = "Run preparation: ",
@@ -4173,6 +4175,9 @@ cat ("No climate attributes data found.\n")
41734175
progress$close()
41744176
cat ("exiting, stop fvschild\n")
41754177
try(stopCluster(fvschild))
4178+
Sys.sleep(0.3)
4179+
unlink(paste0(globals$fvsRun$uuid,".db"))
4180+
unlink(paste0(globals$fvsRun$uuid,"_genrpt.txt"))
41764181
})
41774182
clusterEvalQ(fvschild,library(rFVS))
41784183
cmd = paste0("clusterEvalQ(fvschild,fvsLoad('",
@@ -8116,7 +8121,7 @@ cat ("in customRunOps runScript: ",input$runScript,"\n")
81168121
fn=paste0("customRun_",globals$fvsRun$runScript,".R")
81178122
if (!file.exists(fn)) fn=system.file("extdata", fn, package=if (devVersion) "fvsOLdev" else "fvsOL")
81188123
if (!file.exists(fn)) return()
8119-
rtn = try(source(fn))
8124+
rtn = try(source(fn,local=TRUE))
81208125
if (class(rtn) == "try-error") return()
81218126
uiF = try(eval(parse(text=paste0(sub("fvsRun","ui",globals$fvsRun$runScript)))))
81228127
if (class(uiF) != "function") return()

fvsOL/R/ui.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,12 @@ FVSOnlineUI <- fixedPage(
785785
downloadButton("dlFVSRunkey","Keyword file for current run"),h4(),
786786
checkboxGroupInput("dlZipSet","Set contents of FVSProjectData.zip",
787787
zipList,selZip,inline=FALSE),
788-
downloadButton("dlFVSRunZip","Download FVSProjectData.zip")
788+
downloadButton("dlFVSRunZip","Download FVSProjectData.zip"),
789+
HTML(paste0('<p style="font-size:17px;color:darkgreen"><br>',
790+
'The contents of the FVSProjectData.zip file can be uploaded using the ',
791+
'<i>Import runs and other items</i> tab.<br><br>Note: If you need to create ',
792+
'a zip file backup of your entire project, use the "Make a project backup zip file" ',
793+
'utility under the <i>Manage project</i> tab.</p>'))
789794
) #END Downloads tabPanel
790795
) #END tabsetPanel for toolsPan
791796
), ## END Manage Projects

fvsOL/R/writeKeyFile.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ kcpVetting <- function (kcpconts)
8080
commkw <- grep("COMMENT", toupper(kcpconts[j]))
8181
commkw <- length(commkw)
8282
compkw <- toupper(strsplit(kcpconts[j]," ")[[1]][1])=="COMPUTE"
83+
if(!is.na(match("DESIGN", toupper(kcpconts[j]))))RepsDesign=TRUE
8384
# omit comments, lines that continue (supplemental records), parameter-only lines, compute expressions (contains "="), and THEN keywords
8485
if(is.na(!comment && commentflag==0 && !continuation && is.na(numvalue) && !length(expression) && !thenkw)) next
8586
if(!comment && commentflag==0 && !continuation && is.na(numvalue) && !length(expression) && !thenkw){
@@ -498,6 +499,7 @@ writeKeyFile <- function (globals,dbIcon,newSum=TRUE,keyFileName=NULL,verbose=TR
498499
cycleat = sort(union(cycleat,as.numeric(globals$fvsRun$endyr)))
499500
for (std in globals$fvsRun$stands)
500501
{
502+
RepsDesign=FALSE
501503
names(fvsInit) <- toupper(names(fvsInit))
502504
sRows = match (std$sid, fvsInit$STAND_ID)
503505
sRowp = match (std$sid, fvsInit$STANDPLOT_ID)
@@ -563,7 +565,6 @@ writeKeyFile <- function (globals,dbIcon,newSum=TRUE,keyFileName=NULL,verbose=TR
563565
{
564566
if(lastExt != "base") cat ("End\n",file=fc,sep="")
565567
cat ("EndIf\n",file=fc,sep="")
566-
if(lastExt == lastExt) cat (extensPrefixes[exten],"\n",file=fc,sep="")
567568
lastCnd = NULL
568569
}
569570
if (cmp$atag == "c") lastCnd = cmp$uuid
@@ -626,6 +627,7 @@ writeKeyFile <- function (globals,dbIcon,newSum=TRUE,keyFileName=NULL,verbose=TR
626627
}
627628
cat ("!Exten:",cmp$exten," Title:",cmp$title,"\n",
628629
cmp$kwds,"\n",file=fc,sep="")
630+
if(substr(cmp$kwds,1,6) == "Design")RepsDesign=TRUE
629631
}
630632
}
631633
}
@@ -681,7 +683,8 @@ writeKeyFile <- function (globals,dbIcon,newSum=TRUE,keyFileName=NULL,verbose=TR
681683
else {
682684
cat ("!Exten:",cmp$exten," Name:",cmp$kwdName,"\n",
683685
cmp$kwds,"\n",file=fc,sep="")
684-
}
686+
}
687+
if(substr(cmp$kwds,1,6) == "Design")RepsDesign=TRUE
685688
}
686689
if (!is.null(lastCnd) && lastExt != "base") {
687690
cat ("End\n",file=fc,sep="")
@@ -690,15 +693,15 @@ writeKeyFile <- function (globals,dbIcon,newSum=TRUE,keyFileName=NULL,verbose=TR
690693
if (!is.null(lastCnd) && lastExt == "base") cat ("EndIf\n",file=fc,sep="")
691694
if (is.null(lastCnd) && lastExt != "base") cat ("End\n",file=fc,sep="")
692695
# insert modified sampling weight if needed.
693-
if (!is.null(wtofix[[std$sid]]))
696+
if (!is.null(wtofix[[std$sid]]) && !RepsDesign)
694697
{
695698
swt=as.numeric(fvsInit$SAM_WT[sRows])
696699
if (is.na(swt)) swt=1
697700
swt=swt*wtofix[[std$sid]][std$rep]
698701
cswt=sprintf("%10s",as.character(swt))
699702
if (nchar(cswt)>10) cswt=sprintf("%9.5g",swt)
700703
cat ("Design",strrep(" ",53),cswt,"\n",file=fc,sep="")
701-
}
704+
}
702705
cat ("SPLabel\n",file=fc,sep="")
703706
for (i in 1:length(std$grps))
704707
{

0 commit comments

Comments
 (0)