-
Notifications
You must be signed in to change notification settings - Fork 90
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
caching terra objects #1150
Comments
It is currently not implemented. I think I would copy the file and directly open that with |
You can now specify a path:
|
Thanks for the amazingly fast reply! The problem with just loading the copied source file with |
What you implemented now almost solves our problem, thank you for that! However, we'd want to put a hash in the filename of the copied source files to be in line with our general caching workflow, and also to allow multiple different versions of the same source file to be in our cache at the same time. So instead of passing only a single path to a folder, could we pass a vector of absolute paths including the file names that we want the sources to be copied to? |
We'd also want to cache SpatVector objects in the same way, could |
I have added a new method This does not apply to SpatVector at the moment, because the original file source (if any) is not stored in the wrapped object. It is assumed that all SpatVectors can be handled in memory. There is the SpatVectorProxy class for other cases, but this is not very well developed yet. If you really need this type of functionality, then please open a separate issue for that. |
Thanks for this, and sorry for not following up on it earlier. That is already very useful, also the note about PackedSpatVector not having a reference to source files really helped! I noticed terra::wrapCache has trouble with SpatRaster with NETCDF sources:
When calling
Could you maybe have look if that can be fixed? Thank you so much! |
I just tried passing the filename arg: > a <- terra::wrapCache(x, filename = "/home/pascal/PIK/inputdata/states.nc")
Warning message:
[writeRaster] consider writeCDF to write ncdf files
> a@attributes$sources$source
[1] "/home/pascal/PIK/inputdata/states.nc"
> b <- terra::unwrap(a)
Error: [subset] no (valid) layer selected So I guess if the source file is a netcdf the terra::sources must look like > a <- terra::wrapCache(x, filename = 'NETCDF:"/home/pascal/PIK/inputdata/states.nc":primf') That's actually the interface we'll be using, so for us the |
Thank you for providing a mechanism to deal with this on wrap. My use case is moving e.g., a cache to another machine where the paths may not be known in advance. library(terra)
b <- rast(system.file("ex/elev.tif", package = "terra"))
tf1 <- tempfile(fileext = ".tif")
b1 <- writeRaster(b, filename = tf1)
tf2 <- tempfile(fileext = ".tif")
b2 <- wrapCache(b1, tf2)
unlink(tf1)
identical(tf2, b2@attributes$sources$source) ## TRUE
b3 <- unwrap(b2)
plot(b3)
compareGeom(b, b3)
unlink(tf2) If b2@attributes$sources$source <- "new/path/tf2.tif" Is possible to deal with this on unwrap too/instead? Or perhaps define a method for |
Another thank you for this new mechanism. It makes some things easier. I am noticing, however, what seems like a bug, but perhaps I am expecting incorrectly. If you
|
We would like to cache SpatRaster and SpatVector objects. To do so we use terra::wrap to create a PackedSpatRaster/Vector which we can save as an rds file and in another R session we can use readRDS and unwrap to get the original SpatRaster. However this relies on the original source files (as reported by terra::sources) to still be available. To make our cache folder independent of external files we'd like to copy the source files into the cache folder. When loading a SpatRaster from cache we want it to reference the source file copy in our cache folder instead of the original source file. Now the question is, with the current interface, is this already possible and how? If it is not possible yet, could this be implemented?
One hacky way to do this using unexported API would be the following:
packageVersion('terra'): '1.7.32'
OS: Ubuntu 22.04
The text was updated successfully, but these errors were encountered: