Skip to content

Commit

Permalink
Merge pull request #65 from ncss-tech/may2023_style_changes
Browse files Browse the repository at this point in the history
Anticipated changes in OSD Style for #64 item 1
  • Loading branch information
brownag authored Apr 26, 2023
2 parents ffd01c2 + 43fd407 commit e97d2ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
12 changes: 8 additions & 4 deletions R/parseOSD_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
}


# s.lines: result of getOSD()

#' @importFrom stringi stri_match_all
.extractHzData <- function(tp) {

Expand All @@ -303,12 +303,16 @@
# "O" = "0"
# "l" = "1"
## ideas: http://stackoverflow.com/questions/15474741/python-regex-optional-capture-group


## TODO: it isn't clear if the new files will be in
# expect em dashes (\u2014) used after horizon designation as of May 2023
# https://github.com/ncss-tech/SoilKnowledgeBase/issues/64

# detect horizons with both top and bottom depths
hz.rule <- "([\\^\\'\\/a-zA-Z0-9]+)\\s*[-=]+\\s*([Ol0-9.]+)\\s*?(to|-)?\\s+?([Ol0-9.]+)\\s*?(in|inches|cm|centimeters)"
hz.rule <- "([\\^\\'\\/a-zA-Z0-9]+)\\s*[-=\u2014]+\\s*([Ol0-9.]+)\\s*?(to|-)?\\s+?([Ol0-9.]+)\\s*?(in|inches|cm|centimeters)"

# detect horizons with no bottom depth
hz.rule.no.bottom <- "([\\^\\'\\/a-zA-Z0-9]+)\\s*[-=]+?\\s*([Ol0-9.]+)\\s*(to|-)?\\s*([Ol0-9.]+)?\\s*?(in|inches|cm|centimeters)"
hz.rule.no.bottom <- "([\\^\\'\\/a-zA-Z0-9]+)\\s*[-=\u2014]+?\\s*([Ol0-9.]+)\\s*(to|-)?\\s*([Ol0-9.]+)?\\s*?(in|inches|cm|centimeters)"

## TODO: this doesn't work when only moist colors are specified (http://casoilresource.lawr.ucdavis.edu/sde/?series=canarsie)
## TODO: these rules will not match neutral colors: N 2.5/
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/test-OSD-parsing.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ context("OSD Parsing")
## NOTE: the first line must be "TYPICAL PEDON"


# https://github.com/ncss-tech/SoilKnowledgeBase/issues/64
# anticipate expected / possible changes to OSDs starting May 2023
test_that("May 2023 changes to OSD style", {

lines <- strsplit("Typical Pedon:
Gamma silt loam with a north-facing, linear, 1 percent slope in an alfalfa field at an elevation of 210 meters. (Colors are for dry soil unless otherwise noted.)
Ap—0 to 15 centimeters; grayish brown (10YR 5/2) silt loam, very dark grayish brown (10YR 3/2) moist; weak fine granular structure; slightly hard, friable; neutral (pH 6.7 in 1:1 water); abrupt smooth boundary. (10 to 23 centimeters thick)
C—15 to 33 centimeters; stratified grayish brown (10YR 5/2) and light brownish gray (10YR 6/2) silt loam, very dark grayish brown (10YR 3/2) and dark grayish brown (10YR 4/2) moist; massive with evident bedding planes; slightly hard, friable; few fine prominent reddish brown (5YR 4/4) masses of oxidized iron in the soil matrix; neutral (pH 6.7 in 1:1 water); abrupt smooth boundary. (15 to 30 centimeters thick)
Cg1—33 to 48 centimeters; stratified dark gray (10YR 4/1) and grayish brown (10YR 5/2) silt loam, very dark gray (10YR 3/1) and dark grayish brown (10YR 4/2) moist; massive with evident bedding planes; slightly hard, friable; few fine prominent reddish brown (5YR 4/4) masses of oxidized iron in the soil matrix; neutral (pH 6.8 in 1:1 water); abrupt smooth boundary. (10 to 25 centimeters thick)
Cg2—48 to 81 centimeters; stratified grayish brown (10YR 5/2) and light brownish gray (10YR 6/2) silt loam, very dark grayish brown (10YR 3/2) and dark grayish brown (10YR 4/2) moist; massive with evident bedding planes; slightly hard, friable; few fine prominent reddish brown (5YR 4/4) masses of oxidized iron in the soil matrix; neutral (pH 6.9 in 1:1 water); abrupt smooth boundary. (25 to 51 centimeters thick)
Agb1—81 to 112 centimeters; dark gray (10YR 4/1) silt loam, very dark gray (10YR 3/1) moist; massive; hard, friable; neutral (pH 6.8 in 1:1 water); gradual wavy boundary. (0 to 38 centimeters thick)
Agb2—112 to 153 centimeters; dark gray (N 4/) silt loam, black (N 2.5/) moist; massive; hard, friable; neutral (pH 6.8 in 1:1 water).
", split = '\n')[[1]]

z <- SoilKnowledgeBase:::.extractHzData(lines)

expect_equal(nrow(z), 6)
expect_equal(z$top, c(0, 15, 33, 48, 81, 112))

})






test_that("horizon depths (with unit conversion) and designation", {

# MENDEL
Expand Down

0 comments on commit e97d2ac

Please sign in to comment.