Downloads WaPOR or AgERA5 raster data for a specified region and time period, optionally crops/masks to the region boundary, and saves as a GeoTIFF file.
Usage
wapor_map(
region,
variable,
period,
folder,
filename = NULL,
separate_files = FALSE,
unit_conversion = NULL,
seasonal = FALSE,
mask = FALSE,
parallel = FALSE,
batching = TRUE,
batch_size = NULL,
l3_region = NULL,
l3_mode = c("select", "mosaic_all"),
partial = FALSE,
cog = FALSE,
on_batch_done = NULL,
fun = NULL,
processing = c("auto", "memory", "stream", "tiled")
)Arguments
- region
Region definition. One of:
Path to a vector file (shapefile, GeoJSON, GeoPackage)
L3 region code (3 uppercase letters, e.g., "AWA")
Numeric bounding box:
c(xmin, ymin, xmax, ymax)in WGS84
- variable
Character. Variable name following WaPOR/AgERA5 naming convention (e.g., "L1-AETI-D", "L2-NPP-M", "AGERA5-ET0-E").
- period
Character vector or list. Date range as
c(start_date, end_date)in "YYYY-MM-DD" format. Can also be a named or unnamed list of such vectors for multiple seasons.- folder
Character. Output directory path. Will be created if needed.
- filename
Character. Optional output filename. If NULL, a default name is generated based on region and variable.
- separate_files
Logical. If
TRUE, writes each time step as a separate GeoTIFF file instead of a multi-band stack. In seasonal mode, this saves seasonal-plan component rasters into<folder>/<variable>_seasonal/components/. Default isFALSE.- unit_conversion
Character. Public unit-conversion mode. One of:
"unit_conversion"or"none". Default isNULL, which dynamically matches the variable behavior:Dekadal daily-rate products are saved as dekadal totals
Monthly products remain monthly totals
"none"preserves raw API values without temporal conversion
- seasonal
Logical. If
TRUE, downloads and aggregates data for the entire period into a single seasonal raster (sum/mean). Default isFALSE.- mask
Logical. If
TRUEandregionis a vector file or polygon, the output raster is masked to the polygon boundary (pixels outside set to NA). IfFALSE(default), only a rectangular crop to the bounding box is applied. Ignored for bounding box and L3 code regions.- parallel
Logical. If
TRUE, attempts to usefuture.applyfor parallel processing. Default isFALSE.- batching
Logical. If
TRUE(default), processes data in chunks ofbatch_size. IfFALSE, loads all layers at once.- batch_size
Integer. Number of remote files loaded per chunk. Default
NULLletswapor_plan_processing()choose it from the area size and available memory (all layers at once for small areas). Set a number to override.- l3_region
Optional L3 code to use for an L3 variable and spatial AOI.
- l3_mode
L3 coverage policy:
"select"requires one selected L3 code when several regions intersect;"mosaic_all"writes source assets and a coverage-bearing mosaic for every intersecting L3 region.- partial
Logical. If
TRUE, incomplete temporal coverage is allowed and recorded. DefaultFALSEfails the request.- cog
Logical. Write GeoTIFF outputs with
wapor_write_cog(). DefaultFALSE.- on_batch_done
Optional function called after each processed batch with
(batch_index, batch_count). Callback errors are ignored.- fun
Optional seasonal summary function.
NULL(default) preserves variable-aware weighted aggregation. Explicit"sum"remains weighted for accumulative products and is rejected for state/rate products;"mean","std","min","max", and"median"use each overlapping source layer once without scaling partial layers.- processing
One of
"auto"(default),"memory","stream"or"tiled". Controls how many layers are held at once; seewapor_plan_processing().
Value
Character vector of output GeoTIFF paths (one multi-band file, or
one file per time step with separate_files = TRUE); with several
variables, a named list of such vectors. Per-variable run details
(status, failed_layers, chunk counts) are in
attr(x, "wapor_status"). In seasonal mode with separate_files = TRUE,
a list with seasonal_aggregate and seasonal_components.
Details
The function performs the following steps:
Generates download URLs for the specified variable and period
Streams raster data using GDAL virtual file system (/vsicurl/)
Crops to bounding box or masks to vector geometry
Applies temporal-resolution conversion when requested
Writes output as a multi-band GeoTIFF (one band per time step) or separate files
Examples
if (FALSE) { # \dontrun{
# Download dekadal ET for a bounding box (defaults to mm/dekad)
output_file <- wapor_map(
region = c(35.0, 33.0, 36.0, 34.0),
variable = "L1-AETI-D",
period = c("2023-01-01", "2023-01-31"),
folder = "output"
)
# Preserve raw API values without temporal conversion
output_file <- wapor_map(
region = c(35.0, 33.0, 36.0, 34.0),
variable = "L1-AETI-D",
period = c("2023-01-01", "2023-01-31"),
folder = "output",
unit_conversion = "none"
)
# Download with parallel batching for long periods
library(future)
plan(multisession)
output_file <- wapor_map(
region = c(35.0, 33.0, 36.0, 34.0),
variable = "L1-AETI-D",
period = c("2020-01-01", "2023-12-31"),
folder = "output",
parallel = TRUE,
batch_size = 12
)
} # }