| Title: | Geo-Point Environmental and Agricultural-Economics Data Collector |
|---|---|
| Description: | A uniform, point-keyed interface for retrieving climate, weather, vegetation-index, soil, elevation and agricultural-economics data for a geographic coordinate from many free data sources. Each source is wrapped as an optional adapter behind one request and response contract with mandatory provenance; the package builds and checks with no source package installed. The data-collector member of the ORCHESTRA. |
| Authors: | Max Moldovan [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-9680-8474>) |
| Maintainer: | Max Moldovan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0.9000 |
| Built: | 2026-10-15 23:24:42 UTC |
| Source: | https://github.com/max578/terroir |
The single entry point of the C6 contract. Dispatches a
geo_point_request() to its registered source adapter and returns a verified
geo_point_series, or a structured
refusal when the source is unknown or its package is not
installed.
collect_point( request, retrieved_at = NULL, offline = getOption("terroir.offline", FALSE) )collect_point( request, retrieved_at = NULL, offline = getOption("terroir.offline", FALSE) )
request |
A |
retrieved_at |
Optional character scalar timestamp (provenance). Defaults to the current time. Ignored in offline mode (a replayed series keeps the fixture's recorded timestamp). |
offline |
Logical scalar. When |
collect_point() performs network input/output, so it stamps retrieved_at
with the current time by default; pass retrieved_at for reproducible runs.
In offline mode (offline = TRUE, or globally via
options(terroir.offline = TRUE)) the request is answered from a recorded
fixture with no network egress at all: the matching cached series is replayed
with its provenance marked replayed = TRUE and its original retrieved_at
preserved (see is_replayed()). This lets a sovereign-coordinate trial run
with zero upstream contact, and makes a pipeline reproducible bit-for-bit.
When no recorded fixture answers the request, offline mode returns a
structured refusal rather than silently falling back to the network. The
fixture directory is the terroir.fixture_dir option if set, otherwise the
installed package's fixtures/ directory.
A geo_point_series, or a terroir_refusal – including when the
returned values fail the value-plausibility conformer (an implausible
NDVI/EVI or temperature reading), which is refused rather than aborted so
one bad cell does not stop a multi-site collection.
geo_point_request(), list_sources(), verify_geo_series(),
is_replayed()
req <- geo_point_request( lon = 138.6, lat = -34.92, start = "2020-01-01", end = "2020-01-10", variables = c("T2M", "PRECTOTCORR"), source = "nasapower" ) # offline = TRUE answers from the shipped fixture -- no network egress series <- collect_point(req, offline = TRUE) series is_replayed(series) # an unknown source returns a structured refusal, never an error out <- collect_point(geo_point_request(0, 0, source = "not_a_source")) is_refusal(out)req <- geo_point_request( lon = 138.6, lat = -34.92, start = "2020-01-01", end = "2020-01-10", variables = c("T2M", "PRECTOTCORR"), source = "nasapower" ) # offline = TRUE answers from the shipped fixture -- no network egress series <- collect_point(req, offline = TRUE) series is_replayed(series) # an unknown source returns a structured refusal, never an error out <- collect_point(geo_point_request(0, 0, source = "not_a_source")) is_refusal(out)
Batch/panel form of collect_point(). Stacks the results of every request
in requests into one long data.table, one row per (request x date x variable) for a successful collection or exactly one row for a refused
request. Every per-request refusal path of collect_point() (unknown
source, missing package, out-of-extent point, implausible value) applies
identically.
collect_points( requests, retrieved_at = NULL, offline = getOption("terroir.offline", FALSE) )collect_points( requests, retrieved_at = NULL, offline = getOption("terroir.offline", FALSE) )
requests |
A non-empty list of |
retrieved_at, offline
|
As for |
Requests are grouped by source. A source registered with a batch function
(see register_source()) receives all of its requests in one call, so a
raster is read once for many points. Other sources are called one request at
a time. Offline mode always answers one request at a time from fixtures.
A refusal is never dropped from the stack: it contributes one row with
status == "refused" and reason set to the refusal's message, so a
40-site collection with two dead sources still returns 40 requests' worth
of accounting, not 38.
A data.table with a leading request_index (position in
requests) and status ("ok" or "refused") column, a reason
column (NA_character_ for an "ok" row, the refusal message
otherwise), followed by the fixed C6 geo_point_series columns. lon,
lat and source are populated on a refused row from the request itself
(the values known even when nothing was collected); the remaining C6
columns are NA on a refused row. A final call column carries the
upstream call recorded in each series' provenance.
collect_point(), geo_point_request(), is_refusal()
reqs <- list( geo_point_request(138.6, -34.9, "2020-01-01", "2020-01-31", source = "nasapower"), geo_point_request(0, 0, source = "no_such_source") ) out <- suppressWarnings(collect_points(reqs, offline = TRUE)) out$statusreqs <- list( geo_point_request(138.6, -34.9, "2020-01-01", "2020-01-31", source = "nasapower"), geo_point_request(0, 0, source = "no_such_source") ) out <- suppressWarnings(collect_points(reqs, offline = TRUE)) out$status
Build a request for environmental or agricultural-economics data at a single
geographic point. The request is the input half of the constellation's C6
geo_point_series contract; pass it to collect_point().
geo_point_request( lon, lat, start = NULL, end = NULL, variables = NULL, source, sovereign = FALSE, coarsen = NULL )geo_point_request( lon, lat, start = NULL, end = NULL, variables = NULL, source, sovereign = FALSE, coarsen = NULL )
lon, lat
|
Numeric scalars. Longitude and latitude in WGS84 decimal
degrees (EPSG:4326). |
start, end
|
Character scalars (ISO-8601 |
variables |
Character vector of source-native variable names, or |
source |
Character scalar. The id of one registered source adapter (see
|
sovereign |
Logical scalar. When |
coarsen |
Coordinate-coarsening policy applied to |
An object of class geo_point_request. When coarsening is applied,
lon/lat hold the coarsened coordinate (what is sent upstream) and
lon_raw/lat_raw hold the exact requested coordinate (kept on the host
for provenance); coarsen_policy records the policy as a string.
collect_point(), list_sources()
geo_point_request(138.6, -34.92, "2020-01-01", "2020-01-31", variables = c("T2M", "PRECTOTCORR"), source = "nasapower") # A sovereign point: the exact GPS is coarsened to ~1 km before any call. geo_point_request(138.63124, -34.92871, "2020-01-01", "2020-01-31", source = "nasapower", sovereign = TRUE)geo_point_request(138.6, -34.92, "2020-01-01", "2020-01-31", variables = c("T2M", "PRECTOTCORR"), source = "nasapower") # A sovereign point: the exact GPS is coarsened to ~1 km before any call. geo_point_request(138.63124, -34.92871, "2020-01-01", "2020-01-31", source = "nasapower", sovereign = TRUE)
Returns the ten column names every geo_point_series carries, in contract order. Column order is part of contract C6, so a sibling package typing against terroir's output should read the schema from here rather than hard-coding it.
geo_point_schema()geo_point_schema()
A character vector of column names.
geo_point_schema()geo_point_schema()
Is an object a terroir refusal?
is_refusal(x)is_refusal(x)
x |
An object. |
Logical scalar.
Reports whether a geo_point_series was produced by
the offline replay path (collect_point(request, offline = TRUE)) rather
than a live upstream call. A replayed series carries replayed = TRUE in its
provenance and keeps the recording's retrieved_at rather than a fresh
timestamp, so a consumer can always tell a cached series from a live one.
is_replayed(x)is_replayed(x)
x |
A |
Logical scalar; TRUE only for a replayed series.
List registered data sources
list_sources()list_sources()
A data.table with one row per registered source.
list_sources()list_sources()
geo_point_series from a long-format tableAdapter-facing constructor. Coerces a long table to the fixed C6 schema,
attaches mandatory provenance, and stamps the geo_point_series class. Most
users call collect_point() rather than this directly.
new_geo_point_series( dt, lon, lat, source, source_version, license, retrieved_at, call )new_geo_point_series( dt, lon, lat, source, source_version, license, retrieved_at, call )
dt |
A |
lon, lat
|
Numeric scalars echoed onto every row. |
source, source_version, license
|
Character scalars (provenance). |
retrieved_at |
Character scalar retrieval timestamp. |
call |
Character scalar describing the upstream call (provenance). |
A geo_point_series (a data.table) with provenance attached.
Adds a source adapter to the registry. Enforces the data-collector role's free-only rule: an adapter that does not reach a free source is refused.
register_source( id, fun, package, free, description = "", extent = NULL, batch = NULL )register_source( id, fun, package, free, description = "", extent = NULL, batch = NULL )
id |
Character scalar. Unique source id (used as |
fun |
A function |
package |
Character scalar. The upstream package the adapter needs
(declared in |
free |
Logical scalar. Must be |
description |
Character scalar. One-line description. |
extent |
Optional numeric |
batch |
Optional function |
Invisibly, the registered id.
toy_adapter <- function(request, retrieved_at) { dt <- data.frame(date = request$start, variable = "toy", value = 1) new_geo_point_series( dt, lon = request$lon, lat = request$lat, source = "toy", source_version = "1.0", license = "CC0", retrieved_at = retrieved_at, call = "toy_adapter()" ) } register_source("toy", toy_adapter, package = "base", free = TRUE, description = "Illustrative in-memory adapter") "toy" %in% list_sources()$idtoy_adapter <- function(request, retrieved_at) { dt <- data.frame(date = request$start, variable = "toy", value = 1) new_geo_point_series( dt, lon = request$lon, lat = request$lat, source = "toy", source_version = "1.0", license = "CC0", retrieved_at = retrieved_at, call = "toy_adapter()" ) } register_source("toy", toy_adapter, package = "base", free = TRUE, description = "Illustrative in-memory adapter") "toy" %in% list_sources()$id
Enumerates every fact terroir asserts about an external data authority (MODIS product / band / scale, SILO variable codes, ABARES farm-data layer names, Sentinel-2 band mapping) together with its grounding provenance. A fact is grounded only when it has been diffed against the authority that owns it on a recorded date; until then it is ungrounded. The catalogue-diff oracle test grounds them at check time.
terroir_external_facts()terroir_external_facts()
A data.table keyed by source, fact_family, with columns
asserted_value, oracle_kind (the authority that grounds the fact),
verified_on (Date or NA), evidence_path, and a derived grounding
token ("grounded" / "ungrounded").
facts <- terroir_external_facts() facts[fact_family == "scale_factor"]facts <- terroir_external_facts() facts[fact_family == "scale_factor"]
One row per (source, fact_family) with the count of grounded vs unverified
asserted values – a glance-able audit of how much of terroir's external-fact
surface has been checked against its authorities.
terroir_fact_status()terroir_fact_status()
A data.table with source, fact_family, n_facts,
n_grounded, n_unverified.
geo_point_series against contract C6Checks the fixed schema, units column, and mandatory provenance. Fails loudly (the constellation never silently accepts a malformed series).
verify_geo_series(x)verify_geo_series(x)
x |
An object to verify. |
Invisibly TRUE on success; otherwise an error.
req <- geo_point_request( lon = 138.6, lat = -34.92, start = "2020-01-01", end = "2020-01-10", variables = c("T2M", "PRECTOTCORR"), source = "nasapower" ) series <- collect_point(req, offline = TRUE) verify_geo_series(series)req <- geo_point_request( lon = 138.6, lat = -34.92, start = "2020-01-01", end = "2020-01-10", variables = c("T2M", "PRECTOTCORR"), source = "nasapower" ) series <- collect_point(req, offline = TRUE) verify_geo_series(series)