--- title: "Using Legacy Newhall v1.6.1 Routines" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Using Legacy Newhall v1.6.1 Routines} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( # skip 1.6.1 vignette in R CMD check on GHA eval = FALSE, collapse = TRUE, comment = "#>" ) ``` This vignette demonstrates setting a custom `jNSMR.JAR_SUFFIX` to force use of the legacy Java Newhall Model (version 1.6.1; released 2016/02/10). See official download here: https://www.nrcs.usda.gov/resources/education-and-teaching-materials/java-newhall-simulation-model-jnsm. Before we load the library, set the `jNSMR.JAR_SUFFIX` option to indicate which JAR to load. The attach message indicates the JAR version loaded. ```{r setup, eval=FALSE} options(jNSMR.JAR_SUFFIX = "-1.6.1") library(jNSMR) ``` ### Run the BASIC simulation model Create a _NewhallDataset_ with `xml_NewhallDataset()` or `NewhallDataset()` and associated _NewhallDatasetMetadata_ with `NewhallDatasetMetadata()`. ```{r, eval=FALSE} library(jNSMR) # read single-station XML file (NewhallDataset + NewhallDatasetMetadata) input_xml_file <- system.file("extdata/WILLIAMSPORT_1930_1930_input.xml", package = "jNSMR")[1] input_xml <- xml_NewhallDataset(input_xml_file) # or specify inputs directly to the constructor input_direct <- NewhallDataset(stationName = "WILLIAMSPORT", country = "US", lat = 41.24, lon = -76.92, elev = 158.0, allPrecipsDbl = c(44.2,40.39,113.54,96.77,95.0,98.55, 66.04,13.46,54.86,6.35,17.53,56.39), allAirTempsDbl = c(-2.17,0.89,3.72,9.11,16.28,21.11, 22.83,21.94,19.78,10.5,5.33,-1.06), pdbegin = 1930, pdend = 1930, smcsawc = 200.0) # set minimal _NewhallDatasetMetadata_ for our constructed _NewhallDataset_ input_direct$setMetadata(NewhallDatasetMetadata(stationName = "WILLIAMSPORT")) ``` ### Run single model from file or R object ```{r} # run single model (from XML file--only with v1.6.1 JAR) output_xml <- newhall_simulation(input_xml) # run single model (from direct input) output <- newhall_simulation(input_direct) ``` ### Access references to Java objects containing results Here we demonstrate how to use the `NewhallResults` object from `newhall_simulation()` to get various formatted statistics, calendars and other output from a single run of the model. #### Moisture and temperature regime statistics ```{r, eval=FALSE} cat(output$getFormattedStatistics()) ``` #> Number of Cumulative Days that the Moisture Control Section (MCS) is: #> During one year is: #> Dry: 67 #> MoistDry: 88 #> Moist: 205 #> When soil temp is above 5°C: #> Dry: 48 #> MoistDry: 58 #> Moist: 118 #> Highest number of consecutive days that the MCS is: #> Moist in some parts: #> Year: 293 #> Temp over 8°C: 166 #> Dry after summer solstice: 22 #> Moist after winter solstice: 105 #### Moisture calendar ```{r, eval=FALSE} cat(output$getFormattedMoistureCalendar()) ``` #> 222222222222222333333333333333 #> 333333333333333333333333333333 #> 333333333333333333333333333333 #> 333333333333333333333333333333 #> 333333333333333333333333333333 #> 333333333333333333333333333333 #> 333333333333333333333333333333 #> 333333333322222222222222222222 #> 222222222222222222222222222222 #> 222222221111111111111111111111 #> 111111111111111111111111111111 #> 111111111111111222222222222222 #### Temperature calendar ```{r} cat(output$getFormattedTemperatureCalendar()) ``` #> ------------------------------ #> ------------------------------ #> ------------------------------ #> ------------555555555588888888 #> 888888888888888888888888888888 #> 888888888888888888888888888888 #> 888888888888888888888888888888 #> 888888888888888888888888888888 #> 888888888888888888888888888888 #> 888888888888888888888888888888 #> 88888888888888555555555555---- #> ------------------------------ ### Support for Newhall XML format for input and output `newhall_XMLStringResultsExporter()` returns a character vector with XML based on an input and an output object. ```{r, eval=FALSE} # inspect XML result format cat(newhall_XMLStringResultsExporter(input_xml, output)) ``` #> #> #> #> #> HCN #> WILLIAMSPORT #> #> 158.0 #> PA #> US #> #> #> #> 0 #> #> #> #> FirstName #> LastName #> Researcher #> #> My Organization #> #>
#> #> #> #> #> #> #> #> #> #> gaps filled by interpolation of neighboring stations #> #> 20230723 #> 1.6.1 #> english #> #> #> #> 41.24 #> -76.92 #> DD #> #> #> normal #> 1930 #> 1930 #> #> #> 44.2 #> 40.39 #> 113.54 #> 96.77 #> 95.0 #> 98.55 #> 66.04 #> 13.46 #> 54.86 #> 6.35 #> 17.53 #> 56.39 #> #> #> -2.17 #> 0.89 #> 3.72 #> 9.11 #> 16.28 #> 21.11 #> 22.83 #> 21.94 #> 19.78 #> 10.5 #> 5.33 #> -1.06 #> #> 200.0 #> #> 0.66 #> 1.2 #> #> #> #> Ustic #> Mesic #> Wet Tempustic #> 13.12 #> -218.22 #> #> #> 67 #> 88 #> 205 #> 48 #> 58 #> 118 #> #> #> 293 #> 166 #> 22 #> 105 #> #> #> #> 0.0 #> 1.49 #> 11.44 #> 38.55 #> 90.93 #> 127.6 #> 142.1 #> 126.57 #> 96.94 #> 39.95 #> 14.39 #> 0.0 #> #> #> #> #> 1 #> 102 #> #> #> 103 #> 112 #> #> #> 113 #> 314 #> #> #> 315 #> 326 #> #> #> 327 #> 360 #> #> #> #> #> 1 #> 15 #> #> #> 16 #> 220 #> #> #> 221 #> 278 #> #> #> 279 #> 345 #> #> #> 346 #> 360 #> #> #> #> #> #> ### XML File Output This writes the "direct" input _NewhallDataset_ (`input_direct`) and result _NewhallResult_ (`output`) to an XML file with format as above. ```{r, eval=FALSE} # write XML results to file newhall_XMLResultsExporter(dataset = input_direct, result = output, pathname = "misc/WILLIAMSPORT_1930_1930_export.xml") ``` ### Graphical User Interface for individual runs via _newhall-1.6.1.jar_ `newhall_GUI()` is convenience method to open the Newhall GUI (single runs in v1.6.1 only) with the R package. ```{r, eval=FALSE} newhall_GUI() ``` ## Detaching the Package If you need to switch back and forth between different versions of the model JAR file within a single R session, you will need to `detach()` the package and unset any options such as `jNSMR.JAR_SUFFIX` before reloading with a new JAR. ```{r, eval=FALSE} detach("package:jNSMR") options(jNSMR.JAR_SUFFIX = NULL) ```