Created
March 20, 2025 12:14
-
-
Save h-a-graham/6ede653074a1fb4e7611b66b0d475047 to your computer and use it in GitHub Desktop.
Minimal reticulate rioxarray dask implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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