grid2nc: climate4R grid 2 netCDF export

View source: R/grid2nc.R

grid2ncR Documentation

climate4R grid 2 netCDF export

Description

Export a climate4R grid to NetCDF

Usage

grid2nc(
  data,
  NetCDFOutFile = "out.nc4",
  missval = 1e+20,
  globalAttributes = NULL,
  varAttributes = NULL,
  prec = "float",
  compression = 4,
  shuffle = FALSE,
  verbose = FALSE,
  gridNorthPole = c("39.25", "-162.0"),
  coordBounds = NULL
)

Arguments

data

A climate4R grid data object (http://www.meteo.unican.es/climate4R)

NetCDFOutFile

Name of the file created by the function. (default to "out.nc4")

missval

Missing value codification (default to 1e20)

globalAttributes

Optional. A list of global attributes included in the NetCDF file. Same format as varAttributes.

varAttributes

Optional. List of attributes to be included in the variable written in the NetCDF file. Default to NULL. It has the format list("name_of_attribute1" = attribute1, "name_of_attribute2" = attribute2 etc.

prec

Precision to write the attribute. If not specified, the written precision is given by the variable's corresponding attribute. This can be overridden by specifying the following argument values: "short", "float", "double", or "text".

compression

Integer value between 1 (less compression) and 9 (highest compression), enabling compression for the variable as it is written to the file. Note that turning compression on forces the output file to netcdf v4 format (the default), not compatible with older software that can only handle version 3 files.

shuffle

Logical. Turns on (TRUE) or off (FALSE, the default) the shuffle filter. According to netcdf documentation, turning the shuffle filter on can improve compression for integer variables. Note that turning the shuffle filter on forces the output file to netcdf v4 format (the default), not compatible with older software that can only handle version 3 files.

verbose

Optional. If set to TRUE, switches nc_create to verbose mode

gridNorthPole

Vector with the longitude and latitude. Default is c("39.25","-162.0")

coordBounds

Default is NULL.

Details

netCDF attributes Some attributes are automatically inferred by the function from the climate4R input grid metadata. These can be replaced by user-defined attributes via the global and/or variable attribute lists. It is highly advised that an authoritative attribute convention is followed, such as CF and/or ESIP:

This conventions are indicated by default in the global attributes of the output.

Value

A NetCDF-4 file with the variable and attributes defined in the inputs.

Author(s)

S. Herrera, W. Franssen and J. Bedia

References

  • David Pierce dpierce@ucsd.edu, Interface to Unidata netCDF (version 4 or earlier) format data files, http://dwpierce.com/software

Examples

## Not run: 
library(loadeR.2nc)
data(tx) # A climate4R grid
# Name of output file:
fileName <- "tasmax_WFDEI_JJA_W2001_2010.nc4"
# Including a global attribute:
globalAttributeList <- list("institution" = "SantanderMetGroup, http://www.meteo.unican.es/")
# Including two variable attributes:
varAttributeList <- list(var_attr1 = "one_attribute", var_attr2 = "another_attribute")
# Create file:
grid2nc(data = tx,
        NetCDFOutFile = fileName,
        missval = 1e20,
        prec = "float",
        globalAttributes = globalAttributeList,
        varAttributes = varAttributeList)
# Inspection fo the file: Requires nectcdf-bin installed in your system:
system("ncdump -h tasmax_WFDEI_JJA_W2001_2010.nc4")

## End(Not run)

SantanderMetGroup/loadeR.2nc documentation built on July 4, 2023, 4:28 a.m.