Skip to contents

Two-stage hydration, per owner:

Usage

buildMaster(path, owners = NULL)

Arguments

path

Absolute path to the index root holding the per-owner CSVs. Required – no default.

owners

character vector of OwnerIDs. NULL = every owner with a RawRecordTable.<O>.csv present in path.

Value

data.table keyed at the (RecordID, DIR) level.

Details

Stage 1D (one row per record): inner-joins RawRecordTable.<O>.csv with EventTable.<O>.csv on EventID and StationTable.<O>.csv on StationID. Computes record-level scalars: Repi (haversine, km) and Rhyp (sqrt(Repi^2 + EventDepth^2), km). Future record-level enrichments (geotechnical depth proxies, etc.) belong in this stage.

Stage 3D (three rows per record, one per DIR): inner-joins the Stage-1D output with RawIntensityTable.<O>.csv on RecordID. Brings per-direction intensities (PGA, AI, ARMS, ...), plus per-direction NP, Fs, dt.

Event-level scalars (mag, depth, lat/lon, time, mechanism, region) are consolidated by source precedence: *.owner > *.USGS > *.ISC (and *.STREC for mechanism/region). StationVs30 is already consolidated upstream in StationTable.

Required input files per owner under path: RawRecordTable.<OwnerID>.csv (drives the owner list), EventTable.<OwnerID>.csv, StationTable.<OwnerID>.csv, RawIntensityTable.<OwnerID>.csv. The function errors if any of the joined CSVs is missing; the canonical way to obtain them is to run buildRawRecordTable(), buildRawIntensityTable(), and the provider-specific event / station table builders.

Examples

index <- file.path(tempdir(), "gmsp-master-example")
unlink(index, recursive = TRUE)
dir.create(index)
data.table::fwrite(
  data.table::data.table(RecordID = "R1", EventID = "E1",
                         StationID = "S1", OwnerID = "AAA",
                         NP = 101, Fs = 100, pad = 0),
  file.path(index, "RawRecordTable.AAA.csv")
)
data.table::fwrite(
  data.table::data.table(
    EventID = "E1",
    EventMagnitude.owner = 5.5, EventMagnitude.USGS = 5.4,
    EventMagnitude.ISC = 5.3,
    EventMagnitudeType.owner = "Mw", EventMagnitudeType.USGS = "Mw",
    EventMagnitudeType.ISC = "Mw",
    EventDepth.owner = 10, EventDepth.USGS = 11, EventDepth.ISC = 12,
    EventLatitude.owner = 0, EventLatitude.USGS = 0,
    EventLatitude.ISC = 0,
    EventLongitude.owner = 0, EventLongitude.USGS = 0,
    EventLongitude.ISC = 0,
    EventTimeUTC.owner = "2026-01-01T00:00:00Z",
    EventTimeUTC.USGS = "2026-01-01T00:00:00Z",
    EventTimeUTC.ISC = "2026-01-01T00:00:00Z",
    EventMechanism.owner = "SS", EventMechanism.STREC = "SS",
    EventTectonicRegion.owner = "active",
    EventTectonicRegion.STREC = "active"
  ),
  file.path(index, "EventTable.AAA.csv")
)
data.table::fwrite(
  data.table::data.table(StationID = "S1", StationLatitude = 0.1,
                         StationLongitude = 0.1, StationVs30 = 760),
  file.path(index, "StationTable.AAA.csv")
)
data.table::fwrite(
  data.table::data.table(RecordID = "R1", DIR = "H1",
                         OCID = "H1", PGA = 1),
  file.path(index, "RawIntensityTable.AAA.csv")
)
buildMaster(index, owners = "AAA")
#>    RecordID EventID StationID OwnerID EventMagnitude EventMagnitude.source
#>      <char>  <char>    <char>  <char>          <num>                <char>
#> 1:       R1      E1        S1     AAA            5.5                 owner
#>    MagnitudeType EventDepth EventLatitude EventLongitude EventTimeUTC
#>           <char>      <num>         <num>          <num>       <char>
#> 1:            Mw         10             0              0   2026-01-01
#>    EventMechanism EventTectonicRegion StationLatitude StationLongitude
#>            <char>              <char>           <num>            <num>
#> 1:             SS              active             0.1              0.1
#>    StationVs30     Repi     Rhyp    DIR   OCID   PGA
#>          <int>    <num>    <num> <char> <char> <int>
#> 1:         760 15.72536 18.63563     H1     H1     1