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.tablewith columnsRecordID, OwnerID, EventID, StationID(one row per record). Output ofselectRecords().- 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).
Value
data.table with columns
RecordID, OwnerID, EventID, StationID, t, <OCID columns>.
Records whose sidecars are missing are skipped.
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)]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")
#> RecordID OwnerID EventID StationID t H1 H2
#> <char> <char> <char> <char> <num> <int> <int>
#> 1: R1 AAA E1 S1 0.00 1 0
#> 2: R1 AAA E1 S1 0.01 2 1