dt_to_netcdf {SeaVal}R Documentation

Write a netcdf from a long data table

Description

This function writes a netcdf from a long data table, the usual data format in SeaVal. If not specified, it guesses (based on column names) which columns contain dimension variables and which contain variables. The function currently does not support writing netcdfs with multiple variables that have different sets of dimension variables!

It allows to store character columns in netcdfs (essentially labelling them as integers and storing a legend). This legend is automatically interpreted when the netcdf is read with netcdf_to_dt(), but is also humanly readable.

Usage

dt_to_netcdf(
  dt,
  nc_out,
  vars = NULL,
  units = NULL,
  dim_vars = dimvars(dt),
  dim_var_units = NULL,
  check = interactive(),
  description = NULL
)

Arguments

dt

a data.table

nc_out

File name (including path) of the netcdf to write.

vars

names of columns in dt containing variables. If this is NULL, the function guesses and asks for confirmation.

units

character vector containing the units for vars (in the same order). If this is NULL (default), the user is prompted for input.

dim_vars

names of columns in dt containing dimension variables. If this is NULL, the function guesses and asks for confirmation.

dim_var_units

character vector containing the units for dim_vars (in the same order). If this is NULL (default), the user is prompted for input (except for lon/lat).

check

If check is TRUE, the function asks the user whether an existing file should be overwritten, and whether the correct dimvars have been guessed.

description

For adding a global attribute 'Description' as a string.

Value

none.

Examples

example_dt = data.table(lon = 1:3, month = 4:6, prec = 7:9)
file_name = tempfile()
dt_to_netcdf(dt = example_dt, nc_out = file_name,
             vars = "prec", units = "mm",
             dim_vars = c("lon","month"), dim_var_units = c("degree longitude","month"))




[Package SeaVal version 1.2.0 Index]