read_point_obs: Read point observations from OBSTABLE files

View source: R/read_point_obs.R

read_point_obsR Documentation

Read point observations from OBSTABLE files

Description

Data are read directly from OBSTABLE files with no modification except in the case of precipitation accumulations. Where possible, observations that are not available for the given accumulation time, they are derived from observations for other accumulation times, either by subtraction or addition.

Usage

read_point_obs(
  dttm,
  parameter,
  obs_path = ".",
  obsfile_template = "obstable",
  gross_error_check = TRUE,
  min_allowed = NULL,
  max_allowed = NULL,
  stations = NULL,
  vertical_coordinate = c(NA_character_, "pressure", "model", "height"),
  start_date = NULL,
  end_date = NULL,
  by = "1h"
)

Arguments

dttm

A vector of date time strings to read. Can be in YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss format. Can be numeric or character. seq_dttm can be used to generate a vector of equally spaced date-time strings. Alternatively valid date-times can be extracted from a forecast data frame or harp_list of forecast data frames using unique_valid_dttm.

parameter

Which parameter to read. This will normally be a harp parameter name.

obs_path

The path to the OBSTABLE files

obsfile_template

The template for the OBSTABLE file name.

gross_error_check

Logical of whether to perform a gross error check.

min_allowed

The minimum value of observation to allow in the gross error check. If set to NULL the default value for the parameter is used.

max_allowed

The maximum value of observation to allow in the gross error check. If set to NULL the default value for the parameter is used.

stations

The stations to retrieve observations for. This should be a vector of station ID numbers. Set to NULL to retrieve all stations.

vertical_coordinate

If upper air for multiple levels are to be read, the vertical coordinate of the data is given here. The default is "pressure", but can also be "model" for model levels, or "height" for height above ground /sea level.

start_date, end_date, by

[Deprecated] The use of start_date, end_date and by is no longer supported. dttm together with seq_dttm should be used to generate equally spaced date-times.

Value

A tibble with columns for valid_dttm, SID and the parameter.

Examples

if (requireNamespace("harpData", quietly = TRUE)) {
  read_point_obs(
    seq_dttm(2019021700, 2019022023),
    "T2m",
    obs_path = system.file("OBSTABLE", package = "harpData")
  )

  # stations can be specified using a vector of station ID numbers
  read_point_obs(
    seq_dttm(2019021700, 2019022023),
    "T2m",
    obs_path = system.file("OBSTABLE", package = "harpData"),
    stations = c(1001, 1010)
  )

  # Gross error checks are done automatically but the allowable values
  # can be changed with min_allowed and max_allowed.
  obs <- read_point_obs(
    seq_dttm(2019021700, 2019022023),
    "T2m",
    obs_path = system.file("OBSTABLE", package = "harpData"),
    min_allowed = 260,
    max_allowed = 280
  )

  # The removed observations are stored in the attribute "bad_obs"
  attr(obs, "bad_obs")

  # For vertical profiles, the vertical coordinate must be specified
  read_point_obs(
    seq_dttm(2019021700, 2019022023),
    "Z",
    obs_path            = system.file("OBSTABLE", package = "harpData"),
    vertical_coordinate = "pressure"
  )
}


andrew-MET/harpIO documentation built on March 7, 2024, 7:48 p.m.