raster2ncdf: Converts raster to netCDF

View source: R/conversion_functions.R

raster2ncdfR Documentation

Converts raster to netCDF

Description

This function converts a RasterLayer, RasterStack or a list of these classes to a netCDF file, and exports it to a pre-defined output path.

Usage

raster2ncdf(
  rast_in,
  path_out,
  name,
  unit,
  is_ncdf4 = FALSE,
  prec = "float",
  missing_value = 32000,
  time = NULL,
  origin = "1901-01-01",
  longname = NULL,
  title = NULL,
  author = NULL,
  institute = NULL,
  source = NULL,
  description = NULL,
  axis_names = c("lon", "lat", "time")
)

Arguments

rast_in

an input RasterLayer, RasterStack or a list (see Details)

path_out

character path for the output file with the extension .nc or .nc4 (if is_ncdf4 = TRUE)

name

character variable name(s)

unit

character variable attributes describing the unit

is_ncdf4

logical, if TRUE the output is a netCDF 4 file

prec

character variable type, either integer or float

missing_value

missing value

time

character representation of a Date with format %Y-%m-%d or numeric value

origin

character representation of an origin Date, used to convert character time argument to numeric.

longname

character variable long name(s)

title

character a global attribute

author

character a global attribute

institute

character a global attribute

source

character a global attribute

description

character a global attribute

Details

Inputs can represent a single map (RasterLayer), a stacked map (e.g., with multiple variables; RasterStack), a time-series (list of maps) or a time-series of stacked maps. For each variable, a name must be provided, so the length of the name argument must be equal to the number of stacked layers in the input. In case a time-series is used (e.g., input raster is a list), one shall provide a time argument, either as a numeric vector or as a character vector. In the latter option, the character input will be converted to numeric representing the number of days since a user defined origin. Both the time and origin arguments should be of format %Y-%m-%d. For spatio-temporal data, a list of RasterLayer/RasterStack objects is expected. Each list item stands for a point in time, and each RasterLayer stands for the spatial dimensions and data of a variable. If multiple variable are required, a RasterStack can be used, so each layer stands for a variable. The user must provide the following attributes: name, unit, prec, and missing_value. Other optional attributes include longname (for each variable), or the global variables title, author, institute, source, and description.

Examples

## Not run: 
PUT EXAMPLE HERE

## End(Not run)

dof1985/cwatm4r documentation built on Nov. 8, 2022, 7:30 p.m.