-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add accumulateDepths()
#235
Conversation
Thanks for pushing this forward, this is critical functionality that has been a long time coming. The "depth accumulation" method makes sense and is intuitive. Overall, I like the approach but have some minor concerns about the function name and bundling of functionality. There appear to be three distinct things happening here: 1. vertical shifts, 2. flipping + shifting, 3. "fixing" problematic depths. Vertical Shifting of ProfilesThe basic interface for datum / z-axis shifts is intuitive and nicely vectorized. I'd suggest different terminology like "depth" for the manual pages, but that is minor. I'm on the fence about the use of datum, even though it is probably the best fit here. For this specific task, the function name is a little hard to guess / find. Fixing / Flipping Old-Style O horizonsExcellent: the pattern-matching on horizon name with a For the purposes of flipping old-style O horizons, the function name may be hard to find. Fixing Horizon Depths (NA or equal)I can see how this is related to the problems encountered with or caused by old-style O horizons. However, including this functionality reduces the modularity of the code. Also, 2/3 of this functionality exists in What do you think about the following?
|
Thanks for reviewing this and all of the thoughtful suggestions.
I don't think that "datum" is the wrong word to use here.
@jskovlin can be thanked for that! I would not have come up with it on my own.
This should now be addressed/addressable with the changes that came from #237
This original routine that became this function preceded the
I think it would be easy to define one of these as a wrapper/alias of
Again I think these could be an alias. I like "reflect" over "flip" but don't really care what the alias would be called.
This would be fine. Is this something that must be implemented in order to merge the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge.
A generic function for dealing with old-style O horizons and other changes in datum for soil surface.
I developed this routine originally at request of @jskovlin and refined it with ideas of @dylanbeaudette. It has been idling in the /misc/ folder. This is a PR to get some discussion going on the function. I added tests, docs, examples etc. but am happy to adjust this function in any way. @smroecker I know has worked on similar things. I would welcome any comments!
I anticipate it will be useful in these two related issues downstream of aqp, so would like to move forward with it
Example
Linear Z-axis datum shift by profile ID
Running the function on a valid SPC allows you to do datum shifts up or down, either in bulk for whole SPC or by profile
Treat reversed top depth/bottom depth as horizons above datum (e.g. old style O horizons)
Treat reversed top and bottom depths as depths above datum. This is a special interpretation of source data that could have become that way for a variety of data entry related reasons other than datum.
accumulateDepths()
Accumulate horizon depths, and reflect reversed depths, relative to new datum
Fix old-style organic horizon depths, or depths with a non-standard datum, by the "depth accumulation" method.
The "depth accumulation" method calculates thicknesses of individual horizons and then cumulative sums them after putting them in
id
+ top depth order. The routine tries to determine context based onhzname
andpattern
. The main transformation is if a top depth is deeper than the bottom depth, the depths are reflected on the Z-axis (made negative). The data are thenid
+ top depth sorted again, the thickness calculated and accumulated to replace the old depths.This function uses several heuristics to adjust data before transformation and thickness calculation:
Regex matching of horizon designation patterns and similar
pattern
where both top and bottom depthNA
->[0,1]
[top,bottom]
depthpattern
where both top and bottom depthsNA
Over-ride
hzname
handling with the sequence column argumentseqnum
seqnum
column specified "first record withNA
hzname
" is considered apattern
match ifseqnum == 1
Trigger "fixing" with the
fix
argument:NA
bottom depthNA
top depth and bottom depth0
Parameters:
x
-- Adata.frame
orSoilProfileCollection
id
-- unique profile ID. Default:NULL
, ifx
is a SoilProfileCollectionidname(x)
hzdepths
-- character vector containing horizon top and bottom depth column names. Default:NULL
, ifx
is a SoilProfileCollectionhorizonDepths(x)
hzname
-- character vector containing horizon designation or other label column names. Default:NULL
, ifx
is a SoilProfileCollectionhzdesgnname(x)
hzdatum
-- a numeric constant to add to accumulated depths. Default:0
seqnum
-- Optional: character vector containing record "sequence number" column name; used in-lieu ofhzname
(whenNA
) to identify "first" record in a profilepattern
-- pattern to search for inhzname
to identify matching horizons to append the profile tofix
-- apply adjustments to missing (NA
) depths and expand 0-thickness horizons? Default:TRUE
Returns: A horizon-level
data.frame
, suitable for promoting to SPC withdepths<-
, or aSoilProfileCollection
, depending on the class ofx
.