forked from ncss-tech/aqp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new function, minimally tested changes to profile_compare
- Loading branch information
1 parent
c727a90
commit 4fe1261
Showing
5 changed files
with
114 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
Package: aqp | ||
Version: 1.9.5 | ||
Date: 2015-12-31 | ||
Packaged: 2015-12-31; dylan | ||
Version: 1.9.6 | ||
Date: 2016-02-23 | ||
Title: Algorithms for Quantitative Pedology | ||
Author: Dylan Beaudette <[email protected]>, Pierre Roudier <[email protected]> | ||
Maintainer: Dylan Beaudette <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
## TODO: this needs checking / documentation | ||
|
||
## missing data fraction computed on a thickness basis | ||
## this is meant to be run on a single profile at a time | ||
# x: single SPC | ||
# v: variables to consider | ||
# n: horizon designations | ||
# p: inverted pattern matching non-soil horizons | ||
.getMissingDataFraction <- function(x, v, n, p) { | ||
# get horizons | ||
h <- horizons(x) | ||
# get top/bottom | ||
dc <- horizonDepths(x) | ||
# data fraction based on thickness | ||
hz.thick <- h[[dc[2]]] - h[[dc[1]]] | ||
|
||
# get all "soil" horizons, for named variables | ||
soil.hz <- grep(p, h[[n]], ignore.case=TRUE, invert=TRUE) | ||
d <- h[soil.hz, v] | ||
hz.thick <- hz.thick[soil.hz] | ||
hz.with.data <- which(complete.cases(d)) | ||
# compute fraction of data based on thickness | ||
res <- sum(hz.thick[hz.with.data], na.rm=TRUE) / sum(hz.thick, na.rm = TRUE) | ||
|
||
return(res) | ||
} | ||
|
||
|
||
## iterate over profiles | ||
# x: SPC with >=1 profiles | ||
# vars: variables to consider | ||
# name: horizon designations | ||
# p: inverted pattern matching non-soil horizons | ||
evalMissingData <- function(x, vars, name='hzname', p='Cr|R|Cd') { | ||
# apply missing data fraction eval to each profile | ||
md <- profileApply(x, .getMissingDataFraction, v=vars, n=name, p=p) | ||
return(md) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
\name{evalMissingData} | ||
\alias{evalMissingData} | ||
|
||
\title{Evaluate Missing Data} | ||
\description{Evaluate missing data in a SoilProfileCollection object} | ||
\usage{ | ||
evalMissingData(x, vars, name = "hzname", p = "Cr|R|Cd") | ||
} | ||
|
||
\arguments{ | ||
\item{x}{a \code{SoilProfileCollection} object} | ||
\item{vars}{a chatacter vector naming horizon-level attributes in \code{x}} | ||
\item{name}{the name of a horizon-level attribute where horizon designations are stored} | ||
\item{p}{REGEX pattern used to match non-soil horizons} | ||
} | ||
|
||
\details{Data completeness is evaluated by profile, based on the thickness of horizons with complete horizon-level attribute values (specified in \code{vars}) divided by the total thickness. The default REGEX pattern, \code{p}, should catch most non-soil horizons which are excluded from the evaluation.} | ||
|
||
\value{A vector values ranging from 0 to 1, representing the percentage of non-NA data (as specified in \code{vars}) for each profile.} | ||
|
||
\author{D.E. Beaudette} | ||
|
||
|
||
\examples{ | ||
# example data | ||
data(sp2) | ||
# init SPC object | ||
depths(sp2) <- id ~ top + bottom | ||
# compute data completeness | ||
sp2$data.complete <- evalMissingData(sp2, vars = c('r', 'g', 'b'), name = 'name') | ||
# rank | ||
new.order <- order(sp2$data.complete) | ||
# plot along data completeness ranking | ||
plot(sp2, plot.order=new.order) | ||
# add axis, note re-ordering of axis labels | ||
axis(side=1, at=1:length(sp2), labels = round(sp2$data.complete[new.order], 2), | ||
line=-2, cex.axis=0.75) | ||
} | ||
|
||
\keyword{manip} | ||
|