R/wsm.R

Defines functions read.wsm

Documented in read.wsm

#' Read data generated by the World Stress Map API
#'
#' @details
#' Stress regime defined in the following manner:
#' TF: thrust faulting SH>Sh>SV
#' TS: thrust with strike-slip component
#' SS: strike-slip SH>SV>Sh
#' NS: normal with strike-slip component
#' NF: normal faulting SV>SH>Sh
#' U: unknown
#'
#' Type of plate boundary according to the global plate model PB2002 from Bird (2003):
#' CTF=Continental Transform Fault
#' CRB=Continental Rift Boundary
#' CCB=Continental Collision Boundary
#' OTF=Oceanic Transform Fault
#' OSR=Oceanic Spreading Ridge
#' OCB=Oceanic Collision Boundary
#' SUB=Subduction zone
#'
#' @references
#' Heidbach, O., Tingay, M., Barth, A., Reinecker, J., Kurfess, D., and Mueller, B. (2008),
#' \emph{The World Stress Map database release 2008},
#' \url{http://dx.doi.org/10.1594/GFZ.WSM.Rel2008}
#'
#' Heidbach, O., and J. Hohne (2008),
#' \emph{CASMI - a tool for the visualization of the World Stress Map data base},
#' Computers and Geosciences, 34 (7), 783-791,
#' \url{http://dx.doi.org/10.1016/j.cageo.2007.06.004}
#'
#' @param request.id character; the id assigned to the dataset
#' @param data.dir character; the location of the data from \code{request.id}
#' @param ... additional parameters to \code{\link{read.table}}
#' @export
#'
read.wsm <- function(request.id, data.dir=file.path(request.id), ...){
  release <- c("2008") # this will become an option if new versions are released
  rid <- as.character(request.id)
  dat.fi <- paste0(rid, '.dat')
  full.dat.path <- file.path(data.dir, dat.fi)
  # may want to account for possible variations in output format by testing for column numbers
  wsm <- read.table(full.dat.path, sep=";",
             header=FALSE,
             na.strings = c("NA",999),
             ...)
  if (ncol(wsm) == 10){
    names(wsm) <- c("Latitude","Longitude","SHazimuth","Type","Quality","Regime","Depth","Site",'No','PB')
  } else {
    stop('unclear what column names should be. check input format of ', rid)
  }
  # Values are [0,180] restrict to [0,180)
  dplyr::mutate(wsm, SHazimuth = SHazimuth %% 180) -> wsm
  attr(wsm, 'wsm.params') <- list(id=rid, local.source=full.dat.path, release=release)
  class(wsm) <- c('wsm','data.frame')
  return(wsm)
}
abarbour/stress documentation built on Oct. 5, 2019, 11:20 a.m.