Closed VLucet closed 4 years ago
Thanks for the comment, Vincent - it's really useful to have someone looking into the code. Could you confirm that the dynamic variables in your ExpVarRasterList object contains a layer for each timestep? I think this restriction is documented, although I would agree it's annoying - in the experimental version of lulcc (simonmoulds/r_lulcc2) I have removed this requirement.
If your ExpVarRasterList object is valid in the above sense then I would agree a fix is required. Your proposal (3) would seem sensible, but I would like to investigate the problem a bit further myself before going ahead - can you share a MWE?
Thanks for the reply, Simon. I can confirm my that the dynamic variables in my ExpVarRasterList object contains a layer for each timestep - I think I followed the naming guidelines properly. Here is a small example I created to confirm my doubts:
library(lulcc)
lu1 = raster(matrix(1:2, 80, seq(50, 80, 10)))
lu2 = raster(matrix(1:2, 80, seq(50, 80, 10)))
stackoflu = stack(lu1,lu2)
va1.1 = raster(matrix(1:10, 80, seq(50, 80, 10)))
va1.2 = raster(matrix(10:19, 80, seq(50, 80, 10)))
var2 = raster(matrix(50:59, 80, seq(50, 80, 10)))
stackofvar = stack(va1.1,va1.2, var2)
names(stackofvar) = c("di_01_000", "di_01_010","cli_02")
lustack = ObsLulcRasterStack(x = stackoflu,
categories = c(1,2),
labels = c("Built", "Cropland"),
t = c(0,6)) # modify this value for testing purposes
varstack = ExpVarRasterList(stackofvar)
part = partition(x = lustack[[1]], size = 0.01, spatial = TRUE)
train = getPredictiveModelInputData(obs=lustack,
ef=varstack,
cells=part[["train"]],
t=1) # modify this value for testing purposes
train
I am happy to work on a change on this if it is agreed that it needs to be fixed! 😃
Valentin, I agree that a fix is required. If you have time to work on one I would be most grateful!
I have forked the repo to write a patch. But for some reason I have been unable to re-document and re-build from source to be able to test my changes. Ive never worked with packages having compiled code, and I think the problem comes from the DLLs. I will try to work around that by sourcing the modified files instead. Any advice on building and testing locally? Here is one of the error I keep getting when documenting/building:
Error in dyn.load(dllfile) : unable to load shared object '/Users/vlucet/Documents/DocumentsMBP/GitHub/r_lulcc/lulcc/src/lulcc.so': dlopen(/Users/vlucet/Documents/DocumentsMBP/GitHub/r_lulcc/lulcc/src/lulcc.so, 6): no suitable image found.
Did find: /Users/vlucet/Documents/DocumentsMBP/GitHub/r_lulcc/lulcc/src/lulcc.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
/Users/vlucet/Documents/DocumentsMBP/GitHub/r_lulcc/lulcc/src/lulcc.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
Hi Valentin,
I'm not 100% sure, but you may have better luck if you delete all the shared object (src/*.so) files before attempting to build the package.
For building and testing I use the devtools package; specifically devtools::check() and devtools::build().
Let me know how you get on!
Simon
Well this is a little embarrassing... it took a year for me to find the time (but more importantly to build my understanding of how S4 and more generally how R packages work...) to get back to this, but I have generated a pull request for you to review.
I ended up not implementing (3) because in the case of a rank being equal to a timestep that is not in this rank, the input becomes ambiguous and requires the need to set up an additional argument rank in getPredictiveModelInputData
. I.e. when t = c(0,2,4)
the ranks are c(0,1,2)
and we get into trouble. See #3
I believe there is a flexibility issue when it comes to handling requests of data inputs at different timesteps.
According to the tutorial, the function
getPredictiveModelInputData
takes on timestept
as an argument. If I understand the code and the documentation correctly it passest
toas.data.frame.ObsLulcRasterStack
andas.data.frame.ExpVarRasterList
which then calls the hidden function.getExpVarRasterList
. This functions works by indexing the layers of the different stacks of variables inExpVarRasterList
objects.The tutorial seems to suggest that if the timesteps I inputed when creating my
ObsLulcRasterStack
object are0, 6, 12
, I could also input them in my call togetPredictiveModelInputData
, such as:This results is a message error (from
.getExpVarRasterList
) :The problems comes from the fact that
.getExpVarRasterList
looks up the index of the layers in therasterStack
withindex <- t + 1
andmaps[[i]] <- s[[index]]
. The call to the function above won't work with instances oft
that do not correspond to the index of the rasterstacks.Changing the function call to match the stacks indices...
...generates the appropriate error message from
as.data.frame.ObsLulcRasterStack
:Am I missing something of do you agree this should be fixed? I see three ways:
t
, i.e.rank(maps@t)
; and modify.getExpVarRasterList
so it matches the rank of the layers in the rasterstacks with the rank in the timesteps. Indeally, we could add a slot in the object definition ofObsLulcRasterStack
objects that stores that rank (or index).t = c(1,2,3)
when they define theirObsLulcRasterStack
objects, but we loose the original intent to be able to keep the number of years (or months, or whatever) between timesteps as an implicit input.t = c(0,1,2)
andt = c(0,6,12)
works regardless (which would be a mix of the solutions above and my preferred solution)In addition we could consider having the fact that
getPredictiveModelInputData
takes on timestept
as an argument to be documented in theman
page. Also the fact that the data corresponding to the first timestep is the default output.I'd love to be able to contribute and offer a fix but I do not feel completely confident yet in about if this is indeed recognized as an issue and about which solution should be favored.