Skip to content

Instantly share code, notes, and snippets.

View h-a-graham's full-sized avatar

Hugh Graham h-a-graham

View GitHub Profile
@h-a-graham
h-a-graham / sp_block_bootstrap.md
Last active January 8, 2025 15:29
Spatial block bootstrap with clustered folds to estimate a global statistic (and CIs) for a raster.
suppressPackageStartupMessages({
  library(terra)
  library(ggplot2)
  library(spatialsample)
  library(rsample)
  library(sf)
  library(dplyr)
})
@h-a-graham
h-a-graham / vrt_composite.R
Last active February 16, 2025 07:21
create a composite raster using gdal's VRT and warp via {gdalraster}
#' Create a composite raster with a VRT pixel function
#' @param src_files a character vector with the paths to the source rasters.
#' @param outfile a character path to the output raster.
#' @param fun a character with the pixel function to apply.
#' @param t_srs a character with the target SRS. If empty string "", the spatial
#' reference of src_files[1] will be used.
#' @param vrt_options a character vector with additional options to pass to the
#' gdalbuildVRT command.
#' @param warp_options a character vector with additional options to pass to the
#' gdalwarp command.
@h-a-graham
h-a-graham / major-tom-embeds.R
Last active March 17, 2025 13:47
Download Major-Tom geospatial embeddings
#' Download geospatial embeddings for Major-TOM datsets
#' @param bbox numeric vector of length 4 representing the bounding box in
#' longitude and latitude coordinates (WGS84). Ordered as c(xmin, xmax, ymin,
#' ymax).
#' @param embed character vector of length 1 representing the embedding to
#' download.
#' @param limit integer vector of length 1 representing the maximum number of
#' rows to return. Useful for testing, if NULL then all rows within the bbox
#' are returned.
@h-a-graham
h-a-graham / rio_xarray_dask_inout.R
Created March 20, 2025 12:14
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")
@h-a-graham
h-a-graham / vrtility-DEA-GEOMAD.R
Last active July 3, 2025 20:50
get Digital Earth Africa L8/L9 GEOMAD with {vrtility}
# how to get at Digital Eath Africa GeoMAD datasets
library(vrtility)
mirai::daemons(10)
bbox <- gdalraster::bbox_from_wkt(
wkt = "POINT (46.33 -15.9)",
extend_x = 0.15,
extend_y = 0.2
)
@h-a-graham
h-a-graham / s2-cdse-vrtility.R
Last active July 7, 2025 11:15
Copernicus Dataspace Ecosystem (CDSE) Access with vrtility
library(vrtility)
# only use 4 daemons - this is limit for concurrent requests: https://documentation.dataspace.copernicus.eu/Quotas.html
mirai::daemons(4)
Sys.setenv(
AWS_VIRTUAL_HOSTING = "FALSE",
AWS_ACCESS_KEY_ID = Sys.getenv("CDSE_ACCESS_KEY"),
AWS_SECRET_ACCESS_KEY = Sys.getenv("CDSE_SECRET_KEY"),
AWS_S3_ENDPOINT = "eodata.dataspace.copernicus.eu"