nc_grid_to_dt_raw {eurocordexr}R Documentation

Convert a netcdf array to long format as data.table (raw version)

Description

Extracts a variable from netcdf, similar to nc_grid_to_dt, but in a raw version. Requires more manual info, does not convert time units (like 'days since x'), and requires xy variables not dimensions (like a curvilinear grid).

Usage

nc_grid_to_dt_raw(
  filename,
  variable,
  var_t,
  var_x,
  var_y,
  has_time = TRUE,
  icell_raster_pkg = TRUE
)

Arguments

filename

Complete path to .nc file.

variable

Character, name of the variable to extract (required).

var_t

Character, name of the time variable. (recommended if has_time=TRUE)

var_x

(optional) Character, name of the x coordinate variable (not dimension!). If both var_x and var_y are supplied, results will have xy columns, too.

var_y

(optional) Character, name of the y coordinate variable (not dimension!). If both var_x and var_y are supplied, results will have xy columns, too.

has_time

Boolean, if TRUE (default), will read time information from file. Use FALSE, if file has no time dimension/variable.

icell_raster_pkg

Boolean, if TRUE, cell indices will be ordered as if you were extracting the data with the raster package. See also nc_grid_to_dt

Details

Names of netcdf variables can be inquired in a terminal with "ncdump -h", or in R for example using ncdf4::nc_open(filename).

Example use cases: netcdf file has issues with dimensions (no dimvar), time variable is in non-standard format.

Value

A data.table with columns icell (cell index), time (if has_time=T), value. Only if var_x and var_y supplied also x and y. Column names except icell are variable names as in the netcdf file.

See Also

nc_grid_to_dt

Examples

# example data
fn3 <- system.file("extdata", "test3.nc", package = "eurocordexr")
dat <- nc_grid_to_dt_raw(fn3, "tasmax", "Times")
str(dat)

[Package eurocordexr version 0.2.5 Index]