Skip to contents

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

Records root, either relative to the working directory or absolute. 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.

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