readTS: Read parsed time-series records into the shape 'AT2TS()' /...

View source: R/readTS.R

readTSR Documentation

Read parsed time-series records into the shape AT2TS() / VT2TS() / DT2TS() expect.

Description

Stacks ⁠raw/<KIND>.<RID>.csv⁠ from each record in .x, builds the time axis t from dt (in ⁠raw/<KIND>.<RID>.json⁠), and returns a single data.table keyed at ⁠(RecordID, OwnerID, EventID, StationID, t)⁠.

Usage

readTS(.x, path, kind = c("AT", "VT", "DT"))

Arguments

.x

data.table with columns ⁠RecordID, OwnerID, EventID, StationID⁠ (one row per record). Output of selectRecords().

path

Absolute path to the records root. The function reads per-station files under ⁠<path>/<OwnerID>/<EventID>/<StationID>/raw/⁠. Required – no default.

kind

One of "AT", "VT", "DT". Selects the sidecar file prefix (⁠<kind>.<RID>.csv⁠ / ⁠<kind>.<RID>.json⁠).

Details

The sidecar shape produced by extractRecord() is identical across KINDs; KIND only selects the file prefix. The CSV columns are provider OCID values preserved by extractRecord(). Direction labels (H1/H2/UP) live in the JSON sidecar mapping, not in the CSV header. Use the thin wrappers readAT() / readVT() / readDT() at call sites where the KIND is fixed.

Selection <- selectRecords(M, EventID = "...")
TS  <- readTS(.x = Selection, path = "/path/to/records", kind = "VT")
# Sidecar declares units.source as the length base ("mm"); KIND is set by kind=.
TS[, VT2TS(.SD, units.source = "mm"), by = .(RecordID, OwnerID, EventID, StationID)]

Value

data.table with columns ⁠RecordID, OwnerID, EventID, StationID, t, <OCID columns>⁠. Records whose sidecars are missing are skipped.

Examples

root <- file.path(tempdir(), "gmsp-readts-example")
unlink(root, recursive = TRUE)
raw <- file.path(root, "AAA", "E1", "S1", "raw")
dir.create(raw, recursive = TRUE)
data.table::fwrite(
  data.table::data.table(H1 = c(1, 2), H2 = c(0, 1)),
  file.path(raw, "AT.R1.csv")
)
jsonlite::write_json(list(dt = 0.01), file.path(raw, "AT.R1.json"),
                     auto_unbox = TRUE)
selection <- data.table::data.table(
  RecordID = "R1", OwnerID = "AAA", EventID = "E1", StationID = "S1"
)
readTS(selection, path = root, kind = "AT")


gmsp documentation built on July 18, 2026, 5:07 p.m.