Commit ac739180 authored by Nicolau Manubens's avatar Nicolau Manubens
Browse files

Prepared for release of v0.0.0

parent bf67fee7
.git
.gitignore
.tar.gz
.pdf
./.nc
......@@ -10,8 +10,6 @@ Depends:
Imports:
ncdf4,
abind
Suggests:
startR
License: LGPL-3
URL: https://earth.bsc.es/gitlab/es/easyNCDF/wikis/home
BugReports: https://earth.bsc.es/gitlab/es/easyNCDF/issues
......
......@@ -318,3 +318,5 @@ ArrayToNc <- function(arrays, file_path) {
nc_close(ncdf_object)
invisible(NULL)
}
a2nc <- ArrayToNc
......@@ -49,6 +49,7 @@ NcReadDims <- function(file_to_read, var_names = NULL) {
if (!is.null(dims)) {
dims <- .MergeArrayDims(dims, found_dims)
dims <- pmax(dims[[1]], dims[[2]])
dims['var'] <- dims['var'] + 1
} else {
dims <- found_dims
}
......
......@@ -203,12 +203,14 @@ NcToArray <- function(file_to_read, dim_indices = NULL, vars_to_read = NULL,
# }
# missing_dims <- missing_dim_names
#}
indices_dims <- names(dim_indices)[which(names(dim_indices) %in% names(found_dims))]
reorder_back <- NULL
if (any(names(found_dims) != indices_dims)) {
#reorder <- sapply(names(found_dims), function(x) which(indices_dims == x))
reorder_back <- sapply(indices_dims, function(x) which(names(found_dims) == x))
#indices_to_take <- indices_to_take[reorder]
indices_dims <- names(dim_indices)[which(names(dim_indices) %in% names(found_dims))]
if (length(indices_dims) > 0) {
if (any(names(found_dims) != indices_dims)) {
#reorder <- sapply(names(found_dims), function(x) which(indices_dims == x))
reorder_back <- sapply(indices_dims, function(x) which(names(found_dims) == x))
#indices_to_take <- indices_to_take[reorder]
}
}
start <- sapply(indices_to_take, function(x) if (is_single_na(x)) 1 else min(x))
count <- sapply(indices_to_take, function(x) if (is_single_na(x)) -1 else max(x) - min(x) + 1)
......@@ -219,14 +221,14 @@ NcToArray <- function(file_to_read, dim_indices = NULL, vars_to_read = NULL,
if (!is.null(reorder_back)) {
var_result <- aperm(var_result, reorder_back)
}
names(dim(var_result)) <- names(indices_to_take)[reorder_back]
#if (!is.null(missing_dims)) {
# dim(var_result) <- original_dims
#}
if (!is.null(extra_dims)) {
dim(var_result) <- dim(var_result)[-which(indices_dims %in% extra_dims)]
dim(var_result) <- dim(var_result)[-which(names(indices_to_take) %in% extra_dims)]
}
#attr(var_result, 'variables') <- metadata
names(dim(var_result)) <- indices_dims
}
atts <- file_object$var[[var_name]]
atts_to_remove <- c('id', 'name', 'ndims', 'natts', 'size',
......@@ -242,7 +244,7 @@ NcToArray <- function(file_to_read, dim_indices = NULL, vars_to_read = NULL,
#names(dim(var_result)) <- sapply(file_object$var[[var_name]]$dim, '[[', 'name')
}
if (!is.null(var_result)) {
if (!drop_var_dim && (length(vars_to_read_vector) == 1)) {
if (!drop_var_dim || (length(vars_to_read_vector) == 1)) {
dim(var_result) <- c(setNames(1, var_tag), dim(var_result))
}
attr(var_result, 'variables') <- structure(list(atts), .Names = var_name)
......
No preview for this file type
......@@ -18,6 +18,21 @@ NetCDF object as returned by \code{ncdf4::nc_open}.
The result of \code{ncdf4::nc_close}.
}
\examples{
# Create an array from R
file_path <- tempfile(fileext = '.nc')
a <- array(1:9, dim = c(member = 3, time = 3))
# Store into a NetCDF twice, as two different variables
ArrayToNc(list(var_1 = a, var_2 = a + 1), file_path)
# Read the dimensions and variables in the created file
fnc <- NcOpen(file_path)
fnc_dims <- NcReadDims(fnc)
var_names <- NcReadVarNames(fnc)
# Read the two variables from the file into an R array
a_from_file <- NcToArray(fnc, vars_to_read = var_names)
NcClose(fnc)
# Check the obtained array matches the original array
print(a)
print(a_from_file[1, , ])
}
\author{
History:\cr
......
......@@ -18,6 +18,21 @@ Character string with the path to the file to be opened.
A NetCDF object as returned by \code{ncdf4::nc_open} or NULL on failure.
}
\examples{
# Create an array from R
file_path <- tempfile(fileext = '.nc')
a <- array(1:9, dim = c(member = 3, time = 3))
# Store into a NetCDF twice, as two different variables
ArrayToNc(list(var_1 = a, var_2 = a + 1), file_path)
# Read the dimensions and variables in the created file
fnc <- NcOpen(file_path)
fnc_dims <- NcReadDims(fnc)
var_names <- NcReadVarNames(fnc)
# Read the two variables from the file into an R array
a_from_file <- NcToArray(fnc, vars_to_read = var_names)
NcClose(fnc)
# Check the obtained array matches the original array
print(a)
print(a_from_file[1, , ])
}
\author{
History:\cr
......
......@@ -21,6 +21,21 @@ Vector of character strings with the names of the variables which to read the di
Named numeric vector with the names and sizes of the dimensions for the requested variables.
}
\examples{
# Create an array from R
file_path <- tempfile(fileext = '.nc')
a <- array(1:9, dim = c(member = 3, time = 3))
# Store into a NetCDF twice, as two different variables
ArrayToNc(list(var_1 = a, var_2 = a + 1), file_path)
# Read the dimensions and variables in the created file
fnc <- NcOpen(file_path)
fnc_dims <- NcReadDims(fnc)
var_names <- NcReadVarNames(fnc)
# Read the two variables from the file into an R array
a_from_file <- NcToArray(fnc, vars_to_read = var_names)
NcClose(fnc)
# Check the obtained array matches the original array
print(a)
print(a_from_file[1, , ])
}
\author{
History:\cr
......
......@@ -18,6 +18,21 @@ Path to the file to be read or a NetCDF object as returned by \code{easyNCDF::Nc
Vector of character strings with the names of the variables in the NetCDF file.
}
\examples{
# Create an array from R
file_path <- tempfile(fileext = '.nc')
a <- array(1:9, dim = c(member = 3, time = 3))
# Store into a NetCDF twice, as two different variables
ArrayToNc(list(var_1 = a, var_2 = a + 1), file_path)
# Read the dimensions and variables in the created file
fnc <- NcOpen(file_path)
fnc_dims <- NcReadDims(fnc)
var_names <- NcReadVarNames(fnc)
# Read the two variables from the file into an R array
a_from_file <- NcToArray(fnc, vars_to_read = var_names)
NcClose(fnc)
# Check the obtained array matches the original array
print(a)
print(a_from_file[1, , ])
}
\author{
History:\cr
......
......@@ -49,6 +49,21 @@ Whether to allow indices out of range (simply disregard them) or to stop if indi
Array or list of arrays with the data for one or more than one of the requested variables (depending on the parameters). The dimensions are named. The arrays contain the attribute 'variables' with the metadata items found in the NetCDF file.
}
\examples{
# Create an array from R
file_path <- tempfile(fileext = '.nc')
a <- array(1:9, dim = c(member = 3, time = 3))
# Store into a NetCDF twice, as two different variables
ArrayToNc(list(var_1 = a, var_2 = a + 1), file_path)
# Read the dimensions and variables in the created file
fnc <- NcOpen(file_path)
fnc_dims <- NcReadDims(fnc)
var_names <- NcReadVarNames(fnc)
# Read the two variables from the file into an R array
a_from_file <- NcToArray(fnc, vars_to_read = var_names)
NcClose(fnc)
# Check the obtained array matches the original array
print(a)
print(a_from_file[1, , ])
}
\author{
History:\cr
......
......@@ -40,5 +40,9 @@ FALSE, 'selected', and 'non-selected'.
}
}
\examples{
# Create an array from R with data for 3 'var', 3 'member' and 3 'time'
a <- array(1:27, dim = c(var = 3, member = 3, time = 3))
# Take a subset with all 'member' and 'time' for the 1st 'var'
b <- Subset(a, 'var', 1)
}
\keyword{dplot}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment