dankelley / oce

R package for oceanographic processing
http://dankelley.github.io/oce/
GNU General Public License v3.0
145 stars 42 forks source link

inappropriate error with 2x2x2 data #1447

Closed baderstine closed 6 years ago

baderstine commented 6 years ago

Short summary of problem

When attempting to interpolate one point in a very small 2x2x2 grid (e.g., test data), function approx3d throws an error rather than interpolating the value.

Error in if (!equispaced(x)) stop("x values must be equi-spaced") : 
  missing value where TRUE/FALSE needed

What you did

library(oce)
sdf <- expand.grid(x=seq(0,1),y=seq(0,1),z=seq(0,1))
sdf$v <- rep(seq(0,1), each=4)
sdfmat <- array(data = sdf$v, dim = c(length(unique(sdf$x)), length(unique(sdf$y)), length(unique(sdf$z))))
approx3d(x=unique(sdf$x), y=unique(sdf$y), z=unique(sdf$z), f=sdfmat, 
         xout=.5, yout=.5, zout=.5)

What you expected to happen

function should return value = 0.5

Output from sessionInfo()

sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.5

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] oce_0.9-23 gsw_1.0-5 testthat_2.0.0 rgl_0.99.16

loaded via a namespace (and not attached): [1] Rcpp_0.12.17 digest_0.6.15 mime_0.5
[4] R6_2.2.2 xtable_1.8-2 jsonlite_1.5
[7] magrittr_1.5 rlang_0.2.0.9000 miniUI_0.1.1.1
[10] webshot_0.5.0 tools_3.4.4 manipulateWidget_0.10.0 [13] htmlwidgets_0.9 crosstalk_1.0.0 shiny_1.0.5
[16] httpuv_1.3.5 yaml_2.1.16 compiler_3.4.4
[19] htmltools_0.3.6 knitr_1.17

dankelley commented 6 years ago

I think this is fixed in "develop" commit 79ca4e93ddb7a9ec6e41134d2d3ae3f243684848. A simplified test code is below, in which I check for value 1/2. This passes now, in the "develop" branch.

library(oce)
x <- c(0, 1)
y <- c(0, 1)
z <- c(0, 1)
f <- array(c(0, 1), dim=c(2,2,2))
i <- approx3d(x, y, z, f, xout=.5, yout=0.5, zout=0.5)
expect_equal(i, 0.5)

@baderstine -- if you are able to build oce from github, please have a look, and either close this issue or suggest further problems that ought to be addressed. If you cannot easily build from source, please just write a comment to that effect, and I'll wait a few days, in case other developers want to check, and then I'll close it next week, sometime.

Again, thanks for the issue report. We now have a lot more checks in approx3d, and that's a good thing.

baderstine commented 6 years ago

Hey! Sorry I am unable to build at this time. Thanks for the fix!

dankelley commented 6 years ago

In case it helps, if you visit https://www.dropbox.com/sh/awlz31v1jj7w0ct/AACglLhtWga_xG30ThlX6wJHa?dl=0 you'll find built-up versions for macos (or osx) and for microsoft-windows. These are up to date as of today.

dankelley commented 6 years ago

This issue has been closed, since it seems to have been addressed, and since discussion has stalled. The original reporter should feel free to reopen it, though, or to open new issues that might be related. Thanks.

PS. This is a standardized reply.