interpolate_opts: Generate Transformation Options

View source: R/transform_options.R

interpolate_optsR Documentation

Generate Transformation Options

Description

When reading gridded data, three transformations are available: interpolate, regrid and xsection. Each of these transformations requires their own set of options, and these functions are used to generate those options.

Usage

interpolate_opts(
  stations,
  method = c("nearest", "bilinear", "bicubic", "closest"),
  correct_t2m = TRUE,
  keep_model_t2m = FALSE,
  lapse_rate = 0.0065,
  clim_file = NULL,
  clim_file_format = NULL,
  clim_file_opts = NULL,
  clim_param = "sfc_geo",
  use_mask = FALSE,
  weights = NULL,
  keep_raw_data = FALSE
)

regrid_opts(
  new_domain = NULL,
  method = "nearest",
  clim_file = NULL,
  clim_file_format = NULL,
  clim_file_opts = NULL,
  clim_param = "sfc_geo",
  weights = NULL,
  keep_raw_data = FALSE
)

xsection_opts(
  a,
  b,
  horizontal_res = 2500,
  vertical_res = log(10),
  clim_file = NULL,
  clim_file_format = NULL,
  clim_file_opts = NULL,
  clim_param = "sfc_geo",
  method = "bilinear",
  levels_ascending = TRUE,
  keep_raw_data = FALSE,
  ...
)

subgrid_opts(x1, x2, y1, y2, ...)

Arguments

stations

A data frame of points to interpolate to. Must have the columns 'SID', for a station ID, lat for latitude and lon for longitude.

method

The interpolation method. Can be 'nearest' or 'closest' for nearest neighbour interpolation, 'bilinear', or 'bicubic'. For regrid_opts 'mean' is also available for upscaling.

correct_t2m

Logical. Whether to make a height correction to 2m temperature to account for differences between the model elevation and the station elevation.

keep_model_t2m

Logical. Whether to keep the uncorrected 2m temperature if correct_t2m = TRUE.

lapse_rate

The lapse rate in K/m to use for the 2m temperature heigth correction. The default is the standard moist adiabitic lapse rate of 0.0065 K/m.

clim_file

A file containing model orography or surface geopential on the same grid as the data to be read in so that height corrections to 2m temperature can be made. It will also contain a land sea mask if masked interpolation is to be done. For initialising the domain, any parameter, passed in 'clim_param' can be used.

clim_file_format

The format of the clim_file. If set to NULL, a guess will be made.

clim_file_opts

Options for reading the clim_file, depending on the format of the clim_file.

clim_param

The parameter to read from 'clim_file'. If correct_t2m = TRUE then this should be either surface geopotential or terrain height in meters, otherwise for the purposes of intialising interpolation weights, any paramter that exists in 'clim_file' can be used.

use_mask

Logical. Whether to use a mask in the interpolation. Requires that 'stations' has an 'lsm' column and clim_file includes a land-sea mask.

weights

Interpolation weights if they have already been calculated.

keep_raw_data

Logical. Whether to keep the untransformed full gridded data field. The default is FALSE.

new_domain

A geofield or geodomain object on the grid to which the data should be regridded.

a

A length 2 numeric vector with the longitude and latitude of the left hand edge of the cross section.

b

A length 2 numeric vector with the longitude and latitude of the right hand edge of the cross section.

horizontal_res

The horizontal grid length of the cross section in meters. The default is 2500m.

vertical_res

The vertical grid length of the cross section. For data on pressure levels or model levels this should be in hPa. For data on height levels this should be in meters. The default is log(10).

levels_ascending

The order of the level values. In the output the levels are numbered for simple plotting. Set to TRUE (the default) for the levels to be numbered in ascending order of the level values and FALSE for the numbering to be done in descending order.

x1

left x index of the subdomain

x2

right x index of the subdomain

y1

bottom y index of the subdomain

y2

top y index of the subdomain

Details

interpolate_opts generates options for interpolating gridded data to points, or stations. If no stations are passed, a default list of stations, accessed from the harpIO built in dataset stations_list is used. If 2m temperature is to be read, the deafult behaviour is to attempt to height correct for differences between the model elevation and the elevation at the actual station. The default interpolation method is nearest-neighbour.

regrid_opts generates options to regrid the data from its native grid to a new grid. The new grid is specified either as a geofield or geodomain object. read_grid can be used to read a geofield, or Make.domain can be used to make a geodomain. The default interpolation method is nearest-neighbour.

xsection_opts generates options to extract a vertical cross section from three dimensional gridded data. a and b denote the left and right hand extents of the vertical cross section. By defualt the cross sections are interpolated horizontally to a 2.5 km grid length. In the vertical, if data are on model levels or pressure levels, these are converted to log(pressure) and by default interpolated to to log(10) hPa levels. The default interpolation method is bilinear interpolation.

Value

A list of options that will be used in the transformation.

Examples

interpolate_opts()
if (requireNamespace("Rgrib2", quietly = TRUE) & requireNamespace("harpData", quietly = TRUE)) {
  new_domain = read_grid(
    system.file(
      "grib/AROME_Arctic/2018/07/10/00/fc2018071000+000grib_fp",
      package = "harpData"
    ),
    parameter = "T2m"
  )
  regrid_opts(new_domain = new_domain)
}
xsection_opts(a = c(5.3, 60.5), b = c(10.8, 59.9))

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