Skip to content

Instantly share code, notes, and snippets.

@h-a-graham
Created March 20, 2025 12:14
Show Gist options
  • Save h-a-graham/6ede653074a1fb4e7611b66b0d475047 to your computer and use it in GitHub Desktop.
Save h-a-graham/6ede653074a1fb4e7611b66b0d475047 to your computer and use it in GitHub Desktop.
Minimal reticulate rioxarray dask implementation
library(reticulate)
py_require(c("dask", "distributed", "rioxarray"))
dask.distributed <- reticulate::import("dask.distributed")
rioxarray <- reticulate::import("rioxarray")
Sys.setenv(GDAL_VRT_ENABLE_PYTHON = "YES")
input_vrt <- "..."
output_tif <- "..."
with(dask.distributed$LocalCluster(n_workers = 5L) %as% cluster, {
with(dask.distributed$Client(cluster) %as% client, {
cli::cli_alert_info("Dask dashboard located at: {client$dashboard_link}")
xds <- rioxarray$open_rasterio(
input_vrt,
chunks = TRUE,
lock = FALSE,
# lock=Lock("rio-read", client=client), # when too many file handles open
)
xds$rio$to_raster(
output_tif,
tiled = TRUE,
lock = dask.distributed$Lock("rio", client = client),
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment