-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
122 lines (82 loc) · 5 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
output: md_document
---
<!-- badges: start -->
[![R-CMD-check](https://github.com/ncss-tech/jNSMR/workflows/R-CMD-check/badge.svg)](https://github.com/ncss-tech/jNSMR/actions)
[![Codecov test coverage](https://codecov.io/gh/ncss-tech/jNSMR/branch/main/graph/badge.svg)](https://codecov.io/gh/ncss-tech/jNSMR?branch=main)
[![html-docs](https://img.shields.io/badge/docs-HTML-informational)](https://ncss-tech.github.io/jNSMR/)
<!-- badges: end -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# {jNSMR}
R interface for the 'Java Newhall Simulation Model' (jNSM) -- "A Traditional Soil Climate Simulation Model"
Provides methods to create input, read output, and run the routines from the legacy Java Newhall Simulation Model (jNSM).
## Install {jNSMR}
First, install the development version of the R package. This will install the latest version of the Java Newhall model JAR (in the {jNSMR} folder of your package library).
```{r, eval = FALSE}
# install.packages('remotes')
remotes::install_github('ncss-tech/jNSMR')
```
## Run batches of models
The jNSM has a defined CSV (comma-separated value) batch file format. Examples of batch inputs are included in the [official download](https://www.nrcs.usda.gov/resources/education-and-teaching-materials/java-newhall-simulation-model-jnsm). The main function for running multiple instances of the model is `newhall_batch()`.
`newhall_batch()` takes either a character vector of CSV batch file paths, a data.frame, a SpatRaster or RasterStack/Brick object as input.
### GeoTIFF/SpatRaster Input
```{r, spatraster-ex}
library(jNSMR)
library(terra)
x <- terra::rast(system.file("extdata", "prism_issr800_sample.tif",
package = "jNSMR"))
x$elev <- 0 # elevation is not currently used by the model directly
y <- newhall_batch(x) ## full resolution
par(mfrow = c(1, 2))
terra::plot(y$annualWaterBalance,
cex.main = 0.9, main = "Annual Water Balance (P-PET)")
terra::plot(y$waterHoldingCapacity,
cex.main = 0.9, main = "Water Holding Capacity")
terra::plot(y$temperatureRegime, main = "Temperature Regime")
terra::plot(y$moistureRegime, main = "Moisture Regime")
terra::plot(y$numCumulativeDaysDryOver5C,
cex.main = 0.75, main = "# Cumulative Days Dry over 5 degrees C")
terra::plot(y$numConsecutiveDaysMoistInSomePartsOver8C,
cex.main = 0.75, main = "# Consecutive Days Moist\nin some parts over 8 degrees C")
par(mfrow = c(1, 1))
```
Now let's try again with 'Daymet' monthly climate data at 1 km resolution. 'Daymet' takes a different approach to prediction of temperature and precipitation so we may expect to see some differences--but ideally we have good general agreement between the two models.
```{r, spatraster-ex-daymet}
library(jNSMR)
library(terra)
x2 <- terra::rast(system.file("extdata", "daymet_issr800_sample.tif",
package = "jNSMR"))
x2$elev <- 0 # elevation is not currently used by the model directly
y2 <- newhall_batch(x2) ## full resolution
par(mfrow = c(1, 2))
terra::plot(y2$annualWaterBalance, range = c(-750, 1500),
cex.main = 0.9, main = "Annual Water Balance (P-PET)")
terra::plot(y2$waterHoldingCapacity,
cex.main = 0.9, main = "Water Holding Capacity")
terra::plot(y2$temperatureRegime, main = "Temperature Regime")
terra::plot(y2$moistureRegime, main = "Moisture Regime")
terra::plot(y2$numCumulativeDaysDryOver5C,
cex.main = 0.75, main = "# Cumulative Days Dry over 5 degrees C")
terra::plot(y2$numConsecutiveDaysMoistInSomePartsOver8C,
cex.main = 0.75, main = "# Consecutive Days Moist\nin some parts over 8 degrees C")
par(mfrow = c(1, 1))
```
### CSV File Input
Selected example input files have been included in `inst/extdata` directory of this package.
```{r}
pathname <- system.file("extdata/All_PA_jNSM_Example_Batch_Metric.csv", package = "jNSMR")[1]
res <- data.table::data.table(newhall_batch(pathname, toString = FALSE, verbose = FALSE))
head(res)
```
## License information
**This package uses a modified version of the Newhall model v1.6.1 (released 2016/02/10) of the jNSM (official download here: https://www.nrcs.usda.gov/resources/education-and-teaching-materials/java-newhall-simulation-model-jnsm)**. The compiled JAR and source code are distributed in this R package under the "New" (3-Clause) BSD License. See _LICENSE_ for more information. Modifications to the JAR relative to legacy version facilitate higher throughput and access to additional data elements.
## System requirements
The system requirements of the extraction and installation tools (Windows .EXE archive) at the official download link may not be met on your system, but the core Java class files are stored in a platform-independent format (a Java JAR file e.g _newhall-1.6.1.jar_)--a core dependency in this package.
As long as you have a modern Java Runtime Environment (you probably do), you will be able to run jNSM with only minimal setup.