Skip to content

Commit

Permalink
Merge pull request #207 from tghoward/metadataForReviewedModels
Browse files Browse the repository at this point in the history
Metadata for reviewed models
  • Loading branch information
tghoward authored Jan 6, 2020
2 parents 59856db + 4391fcf commit 65a6229
Show file tree
Hide file tree
Showing 5 changed files with 974 additions and 3 deletions.
30 changes: 30 additions & 0 deletions 4c_additMetadComments_rubricUpdate.r
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ sql <- paste0("SELECT Reviewer.EGT_ID, Reviewer.response, Reviewer.date_complete
FROM Reviewer
WHERE (((Reviewer.EGT_ID)= ", ElementNames$EGT_ID, " ));")
reviewerData <- dbGetQuery(cn, sql)

sql <- paste0("SELECT FinalSppList.Scientific_Name, FinalSppList.Common_Name, FinalSppList.ELEMENT_GLOBAL_ID, ",
"ModelCycle.EGT_ID, ModelCycle.model_cycle, SpeciesWorkFlow.cutecode, SpeciesWorkFlow.model_type, ",
"SpeciesWorkFlow.modeled, SpeciesWorkFlow.alternate_method, SpeciesWorkFlow.existing_model ",
"FROM (FinalSppList INNER JOIN ModelCycle ON FinalSppList.ID = ModelCycle.final_spp_list_ID) ",
"INNER JOIN SpeciesWorkFlow ON ModelCycle.ID = SpeciesWorkFlow.model_cycle_ID ",
"WHERE (((FinalSppList.ELEMENT_GLOBAL_ID)= ", ElementNames$EGT_ID, "));")
modelCycleData <- dbGetQuery(cn, sql)

dbDisconnect(cn)
rm(cn)

Expand Down Expand Up @@ -128,6 +137,27 @@ sql <- paste0("update lkpSpeciesRubric set process_review = '", revUpdate$rAttri
"', process_reviewNotes = '", revUpdate$rComments,
"' where EGT_ID = ", ElementNames$EGT_ID, " ;")
dbExecute(db, statement = sql)
## iterative
iterMatrix <- data.frame("iAttribute" = c("C","A"),
"iComments" = c("Model not re-run with new or modified data.",
"Model was re-run with new or modified data."))
nCycles <- nrow(modelCycleData)
maxCycle <- max(modelCycleData$model_cycle)
if(nCycles > 1){
if(nCycles == 2 & "Both" %in% modelCycleData$model_type){
iterAtt <- "C"
} else if(TRUE %in% modelCycleData[modelCycleData$model_cycle == maxCycle, c("alternate_method","existing_model")]){
iterAtt <- "C"
} else {
iterAtt <- "A"
}
}

iterUpdate <- iterMatrix[match(iterAtt, iterMatrix$iAttribute),]
sql <- paste0("update lkpSpeciesRubric set interative = '", iterUpdate$iAttribute,
"', interativeNotes = '", iterUpdate$iComments,
"' where EGT_ID = ", ElementNames$EGT_ID, " ;")
dbExecute(db, statement = sql)

## clean up ----
dbDisconnect(db)
7 changes: 4 additions & 3 deletions MetadataEval_knitr.rnw
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ Table 3. Thresholds {\protect\NoHyper\cite{LiuEtAl2005, LiuEtAl2015}\protect\end
\textbf{Model Evaluation and Intended Use} \\\\
All SDMs are sensitive to data inputs and methodological choices. Table 4 presents scoring of modeling factors based on the model evaluation rubric presented in Sofaer et al. 2019 {\protect\NoHyper\cite{SofaerEtAl2019}\protect\endNoHyper}. \Sexpr{as.character(project_blurb)}
\\

\smallskip
\pagebreak

Expand Down Expand Up @@ -544,14 +545,14 @@ NatureServe and Heritage Network Partners. \Sexpr{format(Sys.Date(), "%Y")}. Spe
\bibitem{LiuEtAl2015} Liu, C., G. Newell, and M. White. 2015. On the selection of
thresholds for predicting species occurrence with presence-only data. Ecology and
Evolution 6:337–348.
\bibitem{SofaerEtAl2019} Sofaer, H. R., C. S. Jarnevich1, I. S. Pearse, R. L. Smyth, S. Auer, G. L. Cook, T. C. Edwards, Jr., G. F. Guala, T. G. Howard, J. T. Morisette, and H. Hamilton. (In press). The development and delivery of species distribution models to inform decision-making. BioScience.
\bibitem{SofaerEtAl2019} Sofaer, H. R., C. S. Jarnevich1, I. S. Pearse, R. L. Smyth, S. Auer, G. L. Cook, T. C. Edwards, Jr., G. F. Guala, T. G. Howard, J. T. Morisette, and H. Hamilton. 2019. The development and delivery of species distribution models to inform decision-making. BioScience 69:544-557.
\end{thebibliography}

\pagebreak
\noindent

\begin{table}
\caption{Appendix 1. Descriptions for environmental variables included in model.}
Appendix 1. Descriptions for environmental variables included in model.
\begin{table}[H]
\resizebox{\textwidth}{!}{
<<tableFour, results="asis", echo = FALSE>>=
# For variable descriptions, get variable name, source, description (3 columns)
Expand Down
42 changes: 42 additions & 0 deletions postReview_0_user_run_SDM.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# File: postReview_0_user_run_SDM.r
# Purpose: recreate metadata after model review and export
# in the Mobi project

library(here)
rm(list=ls())
loc_scripts <- here()

#######
### loop it
######
rootPath <- file.path("H:","spp_models", "_test")

fldrs <- list.dirs(rootPath, recursive = FALSE)

# if you want to run fewer than the full list of folders
# subset here.
#fldrs <- fldrs[c(3,6)]
#



sppVec <- unlist(lapply(strsplit(fldrs, split = "/"), FUN = function(x) x[[4]]))
sppVec

for(sv in 1:length(sppVec)){

loc_model <- fldrs[[sv]]
model_species <- sppVec[[sv]]
load(file.path(loc_model, "outputs","rdata",paste0(model_species,"_runSDM_paths.Rdata")))
# the vars we need
fn_arg_vars <- c("project_overview","model_comments","metaData_comments","modeller","project_blurb","modelrun_meta_data")
for(arg in fn_arg_vars)
assign(arg, fn_args[[arg]])

nm_refBoundaries <- file.path(loc_scripts,"_data","other_spatial","feature", "US_States.shp")
nm_db_file <- file.path(loc_scripts,"_data", "databases", "SDM_lookupAndTracking.sqlite")

source(file.path(loc_scripts,"postReview_createMetadata.r"))

}

Loading

0 comments on commit 65a6229

Please sign in to comment.