Extract values from one or more TERN datasets at given location(s) over a
given set or range of dates. Returns a data.table with one row per
date/location, and one column per dataset requested. (Note that static
datasets are repeated across all dates for consistency.)
Usage
collect_tern_data(
date_range,
dates,
lon = NULL,
lat = NULL,
xy = NULL,
datasets = NULL,
depth = NULL,
stat = NULL,
smips_collection = NULL,
asc_collection = NULL,
aet_collection = NULL,
soildiv_collection = NULL,
phenology_collection = NULL,
canopy_collection = NULL,
api_key = NULL,
max_tries = NULL,
initial_delay = NULL,
verbose = TRUE,
na.rm = FALSE
)Arguments
- date_range
A
Datevector orcharactervector of length 2,[start_date, end_date], indicating the start and end date which should be used for the TERN dataset retrieval. (If a vector of length greater than 2 is given, this parameter works exactly asdatesdoes.) Omit if specifying exact dates via thedatesargument instead.- dates
A
Datevector orcharactervector, indicating the exact set of dates for which TERN datasets should be retrieved. Takes precedence overdate_rangeif supplied.- lon
Longitude(s) (WGS84, EPSG:4326). Numeric scalar or vector (same length as
lat). Omit if usingxynotation.- lat
Latitude(s) (WGS84, EPSG:4326). Numeric scalar or vector (same length as
lon). Omit if usingxynotation.- xy
Optional: a
data.frame,data.table, ormatrixwith coordinate columns namedlon/latorx/y. Takes precedence overlon/latwhen supplied.- datasets
A
charactervector of dataset aliases to collect. (Default=All datasets.) Options:"SMIPS","ASC","AET","AWC","CLY","SND","SLT","BDW","PHC","PHW","NTO","AVP","PTO","CEC","ECE","DUL","L15","SOILDIV","CANOPY","PHENOLOGY". UseNULL(default) or"all"to specify retrieval of all available datasets.- depth
For SLGA datasets. A
charactervector containing the depth interval(s) for the SLGA soil attributes to collect. (Default=All depths.) Options:"000_005","005_015","015_030","030_060","060_100","100_200". UseNULL(default) or"all"to specify retrieval of all available depths. This parameter is ignored for non-SLGA datasets.- stat
For SLGA datasets. A
charactervector containing the statistic to retrieve for the SLGA datasets. (Default=All statistics.) Options:"EV"(estimated value),"05"(lower, 5th-percentile bound),"95"(upper, 95th-percentile bound); the05and95layers together span a 90% interval. UseNULL(default) or"all"to specify retrieval of all statistics. This parameter is ignored for non-SLGA datasets.- smips_collection
For SMIPS datasets. A
charactervector containing the SMIPS datasets to be retrieved. (Default=All SMIPS datasets.) Options:"totalbucket","SMindex","bucket1","bucket2","deepD","runoff". UseNULL(default) or"all"to specify retrieval of all SMIPS datasets. This parameter is ignored for non-SMIPS datasets.- asc_collection
For ASC datasets. A
charactervector specifying the Australian Soil Classification Map datasets to be retrieved. (Default=All ASC datasets.) Options:"EV"(estimated soil order),"CI"(confusion index). UseNULL(default) or"all"to specify retrieval of all ASC datasets.- aet_collection
For AET datasets. A
charactervector specifying the Actual Evapotranspiration datasets to be retrieved. (Default=All AET datasets.) Options:"ETa","pixel_qa"(quality assurance flags). UseNULL(default) or"all"to specify retrieval of all AET datasets. This parameter is ignored for non-AET datasets.- soildiv_collection
For SOILDIV datasets. A
charactervector specifying the beta soil diversity NMDS axes to be retrieved. (Default=All axes/datasets.) Options:"Bacteria_NMDS1","Bacteria_NMDS2","Bacteria_NMDS3","Fungi_NMDS1","Fungi_NMDS2","Fungi_NMDS3". UseNULL(default) or"all"to specify retrieval of all SOILDIV axes/datasets.- phenology_collection
For PHENOLOGY datasets. A
charactervector specifying the phenology datasets to be retrieved. (Default=All PHENOLOGY datasets.) Options:"SGS","PGS","EGS","LGS","EVI1","EVI2","EVIP","EVII","SGS_month","PGS_month","EGS_month". UseNULL(default) or"all"to specify retrieval of all PHENOLOGY datasets.- canopy_collection
For CANOPY datasets. A
charactervector specifying the OzTreeMap canopy height composite(s) to be retrieved. (Default=All CANOPY datasets.) Options:"best_pick","median". UseNULL(default) or"all"to specify retrieval of all CANOPY datasets. This parameter is ignored for non-CANOPY datasets.- api_key
A
characterstring containing your TERN API key. Seeget_key()for setup.- max_tries
Maximum number of download retries before an error is raised. Default=
NULL, in which case the maximum retry number is resolved from the optionnert.max_triesif that option exists. (Defaults to 3 retries ifnert.max_trieshas not been set.)- initial_delay
Initial retry delay in seconds (doubles with each attempt). Default=
NULL, in which case the initial delay is resolved from the optionnert.initial_delayif that option exists. (Defaults to a 1 second initial delay ifnert.initial_delayhas not been set.)- verbose
Logical. If
TRUE, print progress messages. (Default=TRUE.)- na.rm
Logical. If
TRUE, drop rows where all dataset columns areNA. (Default=FALSE).
Value
A data.table with the following columns:
date:Date.lon,lat: spatial coordinates (always included; constant when a single location is requested).One column per dataset requested. These dataset columns are named with their alias as the prefix (e.g.,
SMIPS,AWC,SOILDIV), followed by any variant information (e.g., depth, statistic, dataset name) after an underscore. For example,SMIPS_totalbucketfor the SMIPS "totalbucket" dataset,CLY_05_000_005for the lower (05) percentile limit of the soil clay at 0-5cm depth, and so on.
Details
Failure handling. Note that if a COG fetch fails (i.e., no
successful download after max_tries), the corresponding column(s)
will be set as NA for the affected rows, and a cli::cli_warn()
warning is emitted.
Examples
if (FALSE) { # interactive()
# Single location, single dataset
dates <- seq(as.Date("2024-01-01"), as.Date("2024-01-05"), by = "day")
d_t <- collect_tern_data(
date_range = dates,
lon = 138.6,
lat = -34.9,
datasets = c("SMIPS", "CLY")
)
head(d_t)
# Multiple locations (vectorised across points within each COG)
d_t_multi <- collect_tern_data(
lon = c(138.6, 139.5),
lat = c(-34.9, -35.5),
date_range = dates,
datasets = c("SMIPS", "CANOPY")
)
# xy data.frame notation
xy <- data.frame(lon = c(138.6, 139.5), lat = c(-34.9, -35.5))
d_t_xy <- collect_tern_data(
xy = xy,
date_range = dates,
datasets = "CLY"
)
}