Skip to content

Commit

Permalink
Improve code for bulk density and coarse fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
heleenderoo committed Mar 5, 2024
1 parent db9852b commit a59d4ba
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/functions/harmonise_layer_to_depths.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ harmonise_layer_to_depths <- function(limit_sup,
mode <- match.arg(mode)

assertthat::assert_that(!is.null(df_sub_selected) ||
(!is.null(bulk_density) &&
!is.null(variab) &&
(!is.null(variab) &&
!is.null(upper_depths) &&
!is.null(lower_depths)))

Expand All @@ -86,7 +85,14 @@ harmonise_layer_to_depths <- function(limit_sup,

if (is.null(df_sub_selected)) {

if (is.null(coarse_fragment_vol_frac)) {
if (is.null(bulk_density)) {
df_sub_selected <-
data.frame(bulk_density = rep(1, length(variab)),
horizon_limit_up = upper_depths,
horizon_limit_low = lower_depths,
variab = variab)
} else
if (is.null(coarse_fragment_vol_frac)) {
df_sub_selected <-
data.frame(bulk_density = bulk_density,
horizon_limit_up = upper_depths,
Expand All @@ -110,6 +116,17 @@ harmonise_layer_to_depths <- function(limit_sup,
parameter_name
}

# If "coarse_fragment_vol_frag" is unknown but "coarse_fragment_vol"
# is known:

if ("coarse_fragment_vol" %in% names(df_sub_selected) &&
!"coarse_fragment_vol_frac" %in% names(df_sub_selected)) {

df_sub_selected <- df_sub_selected %>%
mutate(coarse_fragment_vol_frac = 0.01 * coarse_fragment_vol)
}


# If no "bulk_density_total_soil" is present
# and if "coarse_fragment_vol_frac" is known:
# Calculate the bulk density of the total soil (not only the fine earth)
Expand Down

0 comments on commit a59d4ba

Please sign in to comment.