SaveExp: Save a multidimensional array with metadata to data in NetCDF...

View source: R/CST_SaveExp.R

SaveExpR Documentation

Save a multidimensional array with metadata to data in NetCDF format

Description

This function allows to save a data array with metadata into a NetCDF file, allowing to reload the saved data using Start function from StartR package. If the original 's2dv_cube' object has been created from CST_Load(), then it can be reloaded with Load().

Usage

SaveExp(
  data,
  destination = "./",
  Dates = NULL,
  coords = NULL,
  varname = NULL,
  metadata = NULL,
  Datasets = NULL,
  startdates = NULL,
  dat_dim = "dataset",
  sdate_dim = "sdate",
  ftime_dim = "time",
  var_dim = "var",
  memb_dim = "member",
  drop_dims = NULL,
  single_file = FALSE,
  extra_string = NULL
)

Arguments

data

A multi-dimensional array with named dimensions.

destination

A character string indicating the path where to store the NetCDF files.

Dates

A named array of dates with the corresponding sdate and forecast time dimension.

coords

A named list with elements of the coordinates corresponding to the dimensions of the data parameter. The names and length of each element must correspond to the names of the dimensions. If any coordinate is not provided, it is set as an index vector with the values from 1 to the length of the corresponding dimension.

varname

A character string indicating the name of the variable to be saved.

metadata

A named list where each element is a variable containing the corresponding information. The information must be contained in a list of lists for each variable.

Datasets

A vector of character string indicating the names of the datasets.

startdates

A vector of dates that will be used for the filenames when saving the data in multiple files. It must be a vector of the same length as the start date dimension of data. It must be a vector of class Dates, 'POSIXct' or character with lenghts between 1 and 10. If it is NULL, the first Date of each time step will be used as the name of the files. It is NULL by default.

dat_dim

A character string indicating the name of dataset dimension. By default, it is set to 'dataset'. It can be NULL if there is no dataset dimension.

sdate_dim

A character string indicating the name of the start date dimension. By default, it is set to 'sdate'. It can be NULL if there is no start date dimension.

ftime_dim

A character string indicating the name of the forecast time dimension. By default, it is set to 'time'. It can be NULL if there is no forecast time dimension.

var_dim

A character string indicating the name of variable dimension. By default, it is set to 'var'. It can be NULL if there is no variable dimension.

memb_dim

A character string indicating the name of the member dimension. By default, it is set to 'member'. It can be NULL if there is no member dimension.

drop_dims

A vector of character strings indicating the dimension names of length 1 that need to be dropped in order that they don't appear in the netCDF file. It is NULL by default (optional).

single_file

A logical value indicating if all object is saved in a unique file (TRUE) or in separated directories (FALSE). When it is FALSE, the array is separated for Datasets, variable and start date. It is FALSE by default (optional).

extra_string

A character string to be include as part of the file name, for instance, to identify member or realization. It would be added to the file name between underscore characters (optional).

Value

Multiple or single NetCDF files containing the data array.

single_file = TRUE

All data is saved in a single file located in the specified destination path with the following name: <variable_name>_<extra_string>_<first_sdate>_<last_sdate>.nc. Multiple variables are saved separately in the same file. The forecast time units is extracted from the frequency of the time steps (hours, days, months). The first value of forecast time is 1. If no frequency is found, the units will be 'hours since' each start date and the time steps are assumed to be equally spaced.

single_file = FALSE

The data array is subset and stored into multiple files. Each file contains the data subset for each start date, variable and dataset. Files with different variables and Datasets are stored in separated directories within the following directory tree: destination/Dataset/variable/. The name of each file will be: <variable_name>_<extra_string>_<sdate>.nc.

Author(s)

Perez-Zanon Nuria, nuria.perez@bsc.es

Examples

## Not run: 
data <- lonlat_temp_st$exp$data
lon <- lonlat_temp_st$exp$coords$lon
lat <- lonlat_temp_st$exp$coords$lat
coords <- list(lon = lon, lat = lat)
Datasets <- lonlat_temp_st$exp$attrs$Datasets
varname <- 'tas'
Dates <- lonlat_temp_st$exp$attrs$Dates
destination = './'
metadata <- lonlat_temp_st$exp$attrs$Variable$metadata
SaveExp(data = data, destination = destination, coords = coords, 
       Datasets = Datasets, varname = varname, Dates = Dates, 
       metadata = metadata, single_file = TRUE, ftime_dim = 'ftime', 
       var_dim = 'var', dat_dim = 'dataset')

## End(Not run)


CSTools documentation built on Oct. 20, 2023, 5:10 p.m.