Closed julianoscabral closed 4 years ago
I mean, if you have code to transform an array into a raster stack, let me know
I'm not sure what your point on rds files is. You can save rasters as rds files the same way as any other object in R (mostly true, but irrelevant here where not)...and internally there is no place where the list of environments is saved directly as an rds. They all get mangled into the landscapes.rds format...
As for the dataframe to raster thing: assume # temp <- list(of_data.frames) library(raster)
What format are your data frames?
If they are in the form of x,y,data you can call:
temp <- lapply(temp, rasterFromXYZ)
If they are cell grids you can do this (with a detour over matrices):
temp <- lapply(temp, function(x){raster(as.matrix(x), xmn = 0.5, xmx = 31.5, ymn = 0.5, ymx = 31.5)})
?raster # S4 method for signature 'matrix' # raster(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA, template=NULL) _# note the _mn=0.5, _mx=31.5 boundaries, they put your cell centers at 1:31 instead of 0.5:30.5
My point is that it does not make much sense that the user who creates his/her own landscapes needs to create a list of rasters from a list of data frames (x,y,data) if the create_input() will turn the rasters to a rds file. So, the create_input() should be able to accept a list of data frames directly.
I will try to turn the array of data frames into a list of rasters to check if the function works though.
? I think you are confusing data.frames with the file extension .rds . Data.frames ( or rasters for that matter) are objects within R while .rds is just a convention for how to name the serialized storage of almost any R object. There is no close relationship between these. As such there is no advantage or requirement for a user to create his landscape as data.frames rather than rasters as is currently required...
I agree that we might want to expand the range of accepted input formats at some point, but this is not a priority right now...
This could be solved fairly easly by a internal loop in input_creation, however I am not sure how the col names will withstand the convertion data.frame to rater and back to data.frame
So, I tried to use for the function's argument the list of data frames that I used to produce the rds file before. Then I get this error "unkown landscapes; it has to be a named list of list of either rasters or raster files..." This means I need to transform my data frames into rasters instead of directly providing a list of data frames that can be directly saved into rds. That seems a bit counterproductive. It would be nice if the function would recognize that the list of landscapes is already in the format necessary to write a .rds. Meanwhile I have to check how to transform my arrays into raster stacks then so the function can use them.