-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add taget factory for splitting raster into tiles #76
Conversation
Note to self: clean up the tiles files on disk (not in _targets)? Either write them to a tempfile to begin with or add a final target to remove them? (but then won't the files target always be invalidated? hmm...) |
Ok, it is "working" now (not passing check, but there is a test that should work now to give you an idea of what it does). Here's what the manifest looks like: library(targets)
tar_script({
library(targets)
library(geotargets)
# devtools::load_all()
library(terra)
list(
tar_target(
my_file,
system.file("ex/elev.tif", package="terra"),
format = "file"
),
tar_terra_rast(
my_map,
terra::rast(my_file)
),
tar_terra_tiles(
name = rast_split,
raster = my_map,
template = terra::rast(ncols = 2, nrows = 2),
tiles_dir = "tiles_test"
)
)
})
targets::tar_manifest(callr_function = NULL)
#> terra 1.7.71
#> # A tibble: 5 × 3
#> name command pattern
#> <chr> <chr> <chr>
#> 1 my_file "system.file(\"ex/elev.tif\", package = \"terra\")" <NA>
#> 2 my_map "terra::rast(my_file)" <NA>
#> 3 rast_split_tile "geotargets:::make_tiles(raster = my_map, template =… <NA>
#> 4 rast_split_files "rast_split_tile" map(ra…
#> 5 rast_split "rast(rast_split_files)" map(ra… Created on 2024-05-24 with reprex v2.1.0 |
…akeTiles() is more transparent to user in tar_manifest()
Just pushed a fairly major improvement:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small changes, this is looking really nice!
#' @param gdal character. GDAL driver specific datasource creation options | ||
#' passed to [terra::makeTiles()] | ||
#' | ||
#' @param ... additional arguments not yet used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @param ... additional arguments not yet used | |
#' @param ... additional arguments. Not yet used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was for consistency with other functions ...
arg and I think it is probably grammatically correct as is, although could be "additional arguments which are not yet used". Either way, I'll keep it as-is for now and if we want to change it we can change it for all functions in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that makes sense!
R/tar_terra_tiles.R
Outdated
#' SpatRaster in place, returns a new SpatRaster leaving the original unchanged. | ||
#' | ||
#' @param raster A SpatRaster object | ||
#' @param window A SpatExtent object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @param window A SpatExtent object | |
#' @param window A SpatExtent object. The window of interest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with:
#' @param raster a SpatRaster object
#' @param window a SpatExtent object defining the area of interest
just because I like it when the @param descriptions can be a single phrase or sentence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that reads great!
Co-authored-by: Nicholas Tierney <[email protected]>
Co-authored-by: Nicholas Tierney <[email protected]>
Co-authored-by: Nicholas Tierney <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I took a shot at creating a
tar_terra_tiles()
which is a target factory that creates three targets:y
argument ofterra::makeTiles()
), splits the raster into tiles, saves them to disk, and returns a vector of file paths.makeTiles()
using a target with format = "file" or "file_fast"This downstream target is a pattern that is ready to use in further targets with
pattern = map()
and starts to address #74.This is heavily inspired by
tarchetypes::tar_files()
The main downside to this pattern is that it basically duplicates the tiles on disk—once saved in a directory defined by the
tiles_dir
argument and again in the targets store when those files are read back in. Deleting those files would invalidate the files target, but not the upstream target that creates them, so I'm forced to have the upstream target always re-run withcue = tar_cue("always")
. This is not ideal as making tiles is often a computationally expensive step. I've left#TODO
comments with questions and aspirations about how this might work better and would love feedback.