Skip to content
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

Bug in addVolumeFraction() for profiles with floating point horizon depths #8

Closed
pierreroudier opened this issue Mar 30, 2016 · 4 comments
Labels

Comments

@pierreroudier
Copy link
Collaborator

There is a bug affecting the addVolumeFraction function, which affects profile which have floating points depths:

sandSiltClay <- new("SoilProfileCollection"
    , idcol = "id"
    , depthcols = c("top", "bottom")
    , metadata = structure(list(depth_units = "cm"), .Names = "depth_units", row.names = c(NA, 
-1L), class = "data.frame")
    , horizons = structure(list(id = c("Clay", "Clay", "Clay", "Clay", "Clay", 
"Sand", "Sand", "Sand", "Sand", "Sand", "Silt", "Silt", "Silt", 
"Silt", "Silt"), name = structure(c(2L, 1L, 4L, 5L, 3L, 2L, 1L, 
4L, 5L, 3L, 2L, 1L, 4L, 5L, 3L), .Label = c("SLFs", "tSLw", "VAl", 
"VLc", "VLl"), class = "factor"), top = c(0, 18.5, 28.5, 46, 
53.5, 0, 18.5, 28.5, 46, 53.5, 0, 18.5, 28.5, 46, 53.5), bottom = c(18.5, 
28.5, 46, 53.5, 101, 18.5, 28.5, 46, 53.5, 101, 18.5, 28.5, 46, 
53.5, 101), percent = c(21.5, 21.5, 17.5, 10, 2.5, 22.5, 22.5, 
30, 55, 90, 56.9, 56, 52.5, 35, 7.5), stones = c(23L, 28L, 48L, 
60L, 63L, 23L, 28L, 48L, 60L, 63L, 23L, 28L, 48L, 60L, 63L)), .Names = c("id", 
"name", "top", "bottom", "percent", "stones"), row.names = c(6L, 
7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 11L, 12L, 13L, 14L, 15L), class = "data.frame")
    , site = structure(list(id = c("Clay", "Sand", "Silt")), .Names = "id", row.names = c(NA, 
-3L), class = "data.frame")
    , sp = new("SpatialPoints"
    , coords = structure(c(0, 0), .Dim = 1:2, .Dimnames = list(NULL, c("coords.x1", 
"coords.x2")))
    , bbox = structure(c(0, 0, 0, 0), .Dim = c(2L, 2L), .Dimnames = list(c("coords.x1", 
"coords.x2"), c("min", "max")))
    , proj4string = new("CRS"
    , projargs = NA_character_
)
)
    , diagnostic = structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame")
)

plot(sandSiltClay)
addVolumeFraction(sandSiltClay, 'stones')

The error message is:

Error in `$<-.data.frame`(`*tmp*`, "val", value = c(NA, NA, NA, NA, 1,  : 
  replacement has 185 rows, data has 180

This bug is due to the rounding of floating point horizon depths in .volume2df, specifically:

d$val <- m[1:cells]

This is due to the rounding of depths in d (line 23):

d <- expand.grid(x=(1:res), y=(1:depth))

where

Browse[1]> 1:depth
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18

for depth = 18.5, so nrow(d) = 180, while on the other hand, length(m) = 185.

@pierreroudier pierreroudier changed the title Bug in addVolumeFraction() Bug in addVolumeFraction() for profiles with floating point horizon depths Mar 30, 2016
@pierreroudier
Copy link
Collaborator Author

Following a quick chat with @dylanbeaudette - the support of floating point horizon depths might actually be a problem with other functions in the package (slab, slice, etc...).

A quick patch could enforce the horizon depths to be integers, while working on a more permanent form of support.

@pierreroudier
Copy link
Collaborator Author

Just confirming that this is also a problem for slice.

@dylanbeaudette
Copy link
Member

Recently added truncation to integer via floor() in 7822c27.

@dylanbeaudette
Copy link
Member

This is actually a much larger problem for all functions that expect integer depths (slice, slab, and any that build on those). I'm going to close this for now, and note for future enhancement in #106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants