Skip to content
Snippets Groups Projects
Commit d6fa7a39 authored by HEVIN GUILLAUME's avatar HEVIN GUILLAUME
Browse files

optimization of TNETutils_appendNetCDF() and adding it and TNETutils_createNetCDF to documentation

parent 4095bad2
No related merge requests found
Checking pipeline status
......@@ -27,7 +27,9 @@ export(TNETshape_getSafran)
export(TNETshape_mergeSegments)
export(TNETshape_prepare)
export(TNETshape_removePbDrainArea)
export(TNETutils_appendNetCDF)
export(TNETutils_checkShapefile)
export(TNETutils_createNetCDF)
export(TNETutils_findUpstreamSegment)
export(TNETutils_getDatInfoJ2K)
export(TNETutils_getLongProfile)
......
#' Append data to a TNET NetCDF
#'
#' @description
#' This function will add data to a NetCDF created by [TNETutils_createNetCDF()]
#'
#'
#' @param nc_file NetCDF file created by [TNETutils_createNetCDF()]
#' @param Data data.frame with the data to add. The dimensions variables and one variable name must be in the colnames.
#' @param variable the name of the column in the `Data` to export (must be set as variable in the NetCDF)
#'
#' @returns None
#' @export
#'
#' @examples
#' netcdf_file <- TNETutils_createNetCDF(...)
#'
#' TNETutils_appendNetCDF(netcdf_file, Data)
TNETutils_appendNetCDF <- function(nc_file,Data,variable = NULL){
#Option to deactivate scientific notation when using as.character
options(scipen = 999)
#Get the variable name in the file to extract
if(is.null(variable)) {
......@@ -54,7 +74,7 @@ TNETutils_appendNetCDF <- function(nc_file,Data,variable = NULL){
#Export of the data
Data$gid <- sprintf("%.0f",Data$gid)
Data[,gid := as.character(gid)]
for (variable_use in variable) {
Data_var <- dcast(Data,Date ~ gid, value.var = variable_use)
......@@ -74,4 +94,7 @@ TNETutils_appendNetCDF <- function(nc_file,Data,variable = NULL){
}
#Reset scipen option
options(scipen = 0)
}
\ No newline at end of file
#' Create NetCDF file for TnetRUI and TNET results
#'
#' @description
#' This function will create all NetCDF files used to export results from the TnetRUI package.
#' It's possible to put data in the created NetCDF files using [TNETutils_appendNetCDF()]
#'
#' @param path_createdNetCDF path where the NetCDF file will be created
#' @param variable vector of variable to create in the NetCDF
#' @param units vector of units of the `variable` (can be 1 element or the number of elements in the `variable` parameter)
#' @param longname vector of more explicit names for the `variables`
#' @param NetCDF_base NetCDF file where the dimensions will be copied for the new NetCDF
#' @param ID_dim vector of values to use as the dimention ID
#' @param ID_name name of the dimension with the IDs (by defaults it's "gid")
#' @param time_dim vector to values to put in the time dimension (as to be in POSIXct format)
#' @param chunksize Use a chunksize for the variables ? (see [ncdf4::ncvar_def()] function)
#'
#' @returns A nc_file
#' @export
#'
#' @examples
#' netcdf_file <- TNETutils_createNetCDF(path/to/export,
#' variable = c('Runoff','QlatSout'),
#' units = 'm3/s',
#' NetCDF_base = 'path/to/ncdf.nc')
TNETutils_createNetCDF <- function(path_createdNetCDF , variable, units = '',longname = variable,NetCDF_base = NULL, ID_dim = NULL,ID_name = NULL,time_dim = NULL, chunksize = NULL) {
if(is.null(units)){units = ''}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/TNETutils_appendNetCDF.R
\name{TNETutils_appendNetCDF}
\alias{TNETutils_appendNetCDF}
\title{Append data to a TNET NetCDF}
\usage{
TNETutils_appendNetCDF(nc_file, Data, variable = NULL)
}
\arguments{
\item{nc_file}{NetCDF file created by \code{\link[=TNETutils_createNetCDF]{TNETutils_createNetCDF()}}}
\item{Data}{data.frame with the data to add. The dimensions variables and one variable name must be in the colnames.}
\item{variable}{the name of the column in the \code{Data} to export (must be set as variable in the NetCDF)}
}
\value{
None
}
\description{
This function will add data to a NetCDF created by \code{\link[=TNETutils_createNetCDF]{TNETutils_createNetCDF()}}
}
\examples{
netcdf_file <- TNETutils_createNetCDF(...)
TNETutils_appendNetCDF(netcdf_file, Data)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/TNETutils_createNetCDF.R
\name{TNETutils_createNetCDF}
\alias{TNETutils_createNetCDF}
\title{Create NetCDF file for TnetRUI and TNET results}
\usage{
TNETutils_createNetCDF(
path_createdNetCDF,
variable,
units = "",
longname = variable,
NetCDF_base = NULL,
ID_dim = NULL,
ID_name = NULL,
time_dim = NULL,
chunksize = NULL
)
}
\arguments{
\item{path_createdNetCDF}{path where the NetCDF file will be created}
\item{variable}{vector of variable to create in the NetCDF}
\item{units}{vector of units of the \code{variable} (can be 1 element or the number of elements in the \code{variable} parameter)}
\item{longname}{vector of more explicit names for the \code{variables}}
\item{NetCDF_base}{NetCDF file where the dimensions will be copied for the new NetCDF}
\item{ID_dim}{vector of values to use as the dimention ID}
\item{ID_name}{name of the dimension with the IDs (by defaults it's "gid")}
\item{time_dim}{vector to values to put in the time dimension (as to be in POSIXct format)}
\item{chunksize}{Use a chunksize for the variables ? (see \code{\link[ncdf4:ncvar_def]{ncdf4::ncvar_def()}} function)}
}
\value{
A nc_file
}
\description{
This function will create all NetCDF files used to export results from the TnetRUI package.
It's possible to put data in the created NetCDF files using \code{\link[=TNETutils_appendNetCDF]{TNETutils_appendNetCDF()}}
}
\examples{
netcdf_file <- TNETutils_createNetCDF(path/to/export,
variable = c('Runoff','QlatSout'),
units = 'm3/s',
NetCDF_base = 'path/to/ncdf.nc')
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment