Replace chondro with faux_cell in hyperSpec.Rmd: Ran into an error with qr.solve
I had to revert my conversion of instances of chondro to faux_cell in hyperSpec.Rmd because this code:
find.max <- function(y, x) {
pos <- which.max(y) + (-1:1)
X <- x[pos] - x[pos[2]]
Y <- y[pos] - y[pos[2]]
X <- cbind(1, X, X^2)
coef <- qr.solve(X, Y)
- coef[2] / coef[3] / 2 + x[pos[2]]
}
bandpos <- apply(chondro[[, , 990 ~ 1020]], 1, find.max, wl(chondro[, , 990 ~ 1020]))
refpos <- find.max(colMeans(chondro[[, , 990 ~ 1020]]), wl(chondro[, , 990 ~ 1020]))
shift1 <- refpos - bandpos
throws an error from qr.solve. I also changed the relevant wavelengths; here is a failing example:
library("hyperSpec")
find.max <- function(y, x) {
pos <- which.max(y) + (-1:1)
X <- x[pos] - x[pos[2]]
Y <- y[pos] - y[pos[2]]
X <- cbind(1, X, X^2)
coef <- qr.solve(X, Y)
- coef[2] / coef[3] / 2 + x[pos[2]]
}
bandpos <- apply(faux_cell[[, , 1150 ~ 1250]], 1, find.max, wl(faux_cell[, , 1150 ~ 1250]))
Looking around a bit, I think it may have to do with the amplitudes and/or noise in faux_cell but I'm not sure, and a little experimentation did not reveal any insights (we are fitting to only 3 data points). Someone with more experience with qr.solve may need to take a look. There's also a note above the code in the vignette to use vanderMonde; I think this refers to X <- cbind(1, X, X^2) but I don't see how using vanderMonde gives an advantage here, except that one could make a hyperSpec object out of it, but that seems like overkill.
Due to this issue, two chunks of code in hyperSpec.Rmd are not functional and are temporary not executed. In the vignette, FIXME tag was added to highlight the issue.