read_grid: Read gridded data in various formats

View source: R/read_grid.R

read_gridR Documentation

Read gridded data in various formats

Description

read_grid is a generic function to read gridded data from a file. A transformation can optionally be applied to those data.

Usage

read_grid(
  file_name,
  parameter,
  is_forecast = TRUE,
  dttm = NULL,
  file_format = NULL,
  file_format_opts = list(),
  vertical_coordinate = c("pressure", "model", "height", NA),
  lead_time = NULL,
  members = NULL,
  transformation = c("none", "interpolate", "regrid", "xsection", "subgrid"),
  transformation_opts = list(),
  param_defs = get("harp_params"),
  show_progress = TRUE,
  data_frame = FALSE,
  readable_times = TRUE,
  spread_members = FALSE,
  ...
)

read_grid_interpolate(file_name, parameter, file_format = NULL, ...)

Arguments

file_name

A character string with the (full) file name.

parameter

The parameter to be read.

is_forecast

Logical. If TRUE (the default), data are filtered based on the forecast initialization time and the lead time. If FALSE, the data are filtered on the valid time.

dttm

A vector of date time strings of the form YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss. For forecast data these would be the forecast initialization times. seq_dttm can be used to generate a vector of equally spaced date-time strings.

file_format

The file format. Possible values include grib, netcdf, FA, hdf5... Whatever the value is, it is supposed to correspond to a function "read_XXX" that can deal with the format. If not specified, the format can often be guessed correctly from file extension or the first few bytes.

file_format_opts

Options for the file format as generated by one of the options functions, e.g. netcdf_opts.

vertical_coordinate

The vertical coordinate for upper air data. May be "pressure" for pressure levels, "model" for model levels or "height" for height levels.

lead_time

The lead times to read from a forecast file. If set to NULL, all lead times will be read from the file.

members

For ensemble data, the ensemble members to read from the file. If set to NULL all members will be read.

transformation

The transformation to apply to the gridded data. Can be "none", "interpolate", "regrid" or "xsection".

transformation_opts

Options for the transformation as generated by interpolate_opts, regrid_opts or xsection_opts.

param_defs

A list of parameter definitions that includes the file format to be read. By default the built in list harp_params is used. Modifications and additions to this list can be made using modify_param_def and add_param_def respectively.

show_progress

Show progress when reading large amounts of data.

data_frame

Logical. For compatibility with current version of harpSpatial, make sure only a geofield is returned rather than a data frame when set to FALSE.

readable_times

When data_frame = TRUE, whether to convert times in unix format to a data-time format. The default is TRUE.

spread_members

When data_frame = TRUE, whether to spread the members into a column for each member.

...

All arguments passed to the specified reader function.

Value

A geofield or (possibly) a plain matrix.

Examples

if (requireNamespace("Rgrib2", quietly = TRUE) & requireNamespace("harpData", quietly = TRUE)) {
  read_grid(
    system.file(
      "grib/AROME_Arctic/2018/07/10/00/fc2018071000+000grib_fp",
      package = "harpData"
    ),
    parameter = "T2m"
  )
  read_grid(
    system.file(
      "grib/AROME_Arctic/2018/07/10/00/fc2018071000+000grib_fp",
       package = "harpData"
    ),
    parameter = "S10m"
  )
  read_grid(
    system.file(
      "grib/AROME_Arctic/2018/07/10/00/fc2018071000+000grib_fp",
       package = "harpData"
    ),
    parameter = "tcc"
  )
}

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