From 71e04d41205b38c4441379cc794b544425c28f17 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 5 Jun 2020 18:08:17 +0200 Subject: [PATCH 1/9] SaveExp is now working with arrays and exposed to users --- R/CST_SaveExp.R | 207 +++++++++++++++++++++++++++++++----------------- 1 file changed, 136 insertions(+), 71 deletions(-) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 1b3b4b10..3c0050a0 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -16,9 +16,10 @@ #' #'@seealso \code{\link{CST_Load}}, \code{\link{as.s2dv_cube}} and \code{\link{s2dv_cube}} #' -#'@import s2dverification +#'@importFrom ClimProjDiags Subset #'@import ncdf4 -#'@import abind +#'@import s2dv +#'@import multiApply #' #'@examples #'\dontrun{ @@ -39,28 +40,89 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { stop("Parameter 'data' must be of the class 's2dv_cube', ", "as output by CSTools::CST_Load.") } -dimname <- names(dim(data$data)) - if (any(dimname == "time")) { - dimname[which(dimname == "time")] <- "ftime" - names(dim(data$data))[which(dimname == "time")] <- "ftime" + sdates <- lapply(1:length(data$Datasets), function(x) {data$Datasets[[x]]$InitializationDates[[1]]})[[1]] + if (!is.character(attributes(data$Variable)$units)) { + units <- attributes(data$Variable)$variable$units + } else { + units <- attributes(data$Variable)$units + } + cdo_grid_name = attr(lon, 'cdo_grid_name') + projection = attr(lon, 'projection') + var_name <- data$Variable$varName + time_values <- data$Dates$start + dim(time_values) <- c(time = length(time_values)/length(sdates), sdate = length(sdates)) + SaveExp(data = data$data, lon = data$lon, lat = data$lat, + Dataset = names(data$Datasets), var_name = var_name, + units = units, cdo_grid_name = cdo_grid_name, projection = projection, + startdates = sdates, Dates = time_values, destination) +} +#'Save an experiment in a format compatible with CST_Load +#'@description This function is created for compatibility with CST_Load/Load for saving post-processed datasets such as those calibrated of downscaled with CSTools functions +#' +#'@author Perez-Zanon Nuria, \email{nuria.perez@bsc.es} +#' +#'@param data an multi-dimensional array with named dimensions (longitude, latitude, time, member, sdate) +#'@param vector of logitud corresponding to the longitudinal dimension in data +#'@param vector of latitud corresponding to the latitudinal dimension in data +#'@param Dataset a vector of character string indicating the names of the datasets +#'@param var_name a character string indicating the name of the variable to be saved +#'@param units a character string indicating the units of the variable +#'@param startdates a vector of dates indicating the initialization date of each simulations +#'@param Dates a matrix of dates with two dimension 'time' and 'sdate'. +#'@param cdo_grid_name a character string indicating the name of the grid e.g.: 'r360x181' +#'@param projection a character string indicating the projection name +#'@param destination a character string indicating the path where to store the NetCDF files +#' +#'@return the function creates as many files as sdates per dataset. Each file could contain multiple members +#' The path will be created with the name of the variable and each Datasets. +#' +#'@importFrom ClimProjDiags Subset +#'@import ncdf4 +#'@import s2dv +#'@import multiApply +#' +#'@examples +#'data <- lonlat_data$exp$data +#'lon <- lonlat_data$exp$lon +#'lat <- lonlat_data$exp$lat +#'Dataset <- 'XXX' +#'var_name <- 'tas' +#'units <- 'k' +#'startdates <- lapply(1:length(lonlat_data$exp$Datasets), +#' function(x) { +#' lonlat_data$exp$Datasets[[x]]$InitializationDates[[1]]})[[1]] +#'Dates <- lonlat_data$exp$Dates$start +#'dim(Dates) <- c(time = length(Dates)/length(startdates), sdate = length(startdates)) +#'cdo_grid_name = attr(lonlat_data$exp$lon, 'cdo_grid_name') +#'projection = attr(lonlat_data$exp$lon, 'projection') +#'destination = '/esarchive/scratch/nperez/git/Flor/cstools/' +#'SaveExp(data, lon, lat, Dataset, var_name, units, startdates, Dates, +#' cdo_grid_name, projection, destination) +#'@export +SaveExp <- function(data, lon, lat, Dataset, var_name, units, startdates, Dates, + cdo_grid_name, projection, destination) { + dimname <- names(dim(data)) + if (any(dimname == "ftime")) { + dimname[which(dimname == "ftime")] <- "time" + names(dim(data))[which(dimname == "ftime")] <- "time" } if (any(dimname == "memb")) { dimname[which(dimname == "memb")] <- "member" - names(dim(data$data))[which(dimname == "memb")] <- "member" + names(dim(data))[which(dimname == "memb")] <- "member" } if (any(dimname == "ensemble")) { dimname[which(dimname == "ensemble")] <- "member" - names(dim(data$data))[which(dimname == "ensemble")] <- "member" + names(dim(data))[which(dimname == "ensemble")] <- "member" } - if (any(dimname == "longitude")) { - dimname[which(dimname == "longitude")] <- "lon" - names(dim(data$data))[which(dimname == "longitude")] <- "lon" + if (any(dimname == "lon")) { + dimname[which(dimname == "lon")] <- "longitude" + names(dim(data))[which(dimname == "lon")] <- "longitude" } - if (any(dimname == "latitude")) { - dimname[which(dimname == "latitude")] <- "lat" - names(dim(data$data))[which(dimname == "latitude")] <- "lat" + if (any(dimname == "lat")) { + dimname[which(dimname == "lat")] <- "latitude" + names(dim(data))[which(dimname == "lat")] <- "latitude" } -names(dim(data$data)) <- dimname +names(dim(data)) <- dimname if (is.null(dimname)) { stop("Element 'data' in parameter 'data' must have named dimensions.") @@ -73,24 +135,23 @@ sdate_pos <- which(dimname == "sdate") stop("Element 'data' in parameter 'data' has more than one 'sdate'", " dimension.") } -n_sdates <- dim(data$data)[sdate_pos] # number of files to create dataset_pos <- which(dimname == "dataset" | dimname == "dat") -dims <- dim(data$data) +dims <- dim(data) if (length(dataset_pos) == 0) { warning("Element 'data' in parameter 'data' hasn't 'dataset' dimension. ", "All data is stored in the same 'dataset' folder.") - data$data <- InsertDim(var = data$data, posdim = 1, lendim = 1) - names(dim(data$data))[1] <- "dataset" + data$data <- InsertDim(var = data, posdim = 1, lendim = 1) + names(dim(data))[1] <- "dataset" dimname <- c("dataset", dimname) dataset_pos = 1 } else if (length(dataset_pos) > 1) { stop("Element 'data' in parameter 'data' has more than one 'dataset'", " dimension.") } -n_datasets <- dim(data$data)[dataset_pos] # number of folder by dataset +n_datasets <- dim(data)[dataset_pos] # number of folder by dataset # dataset names: -datasets <- names(data$Datasets) +datasets <- Dataset if (n_datasets > length(datasets)) { warning("Dimension 'dataset' in element 'data' from parameter 'data' ", "is greater than those listed in element 'Datasets' and the ", @@ -106,11 +167,10 @@ datasets <- names(data$Datasets) if ('var' %in% dimname) { var_pos <- which(dimname == 'var') if (dims[var_pos] == 1) { - data$data <- adrop(data$data, drop = var_pos) - dimname <- names(dim(data$data)) + data$data <- adrop(data, drop = var_pos) + dimname <- names(dim(data)) } } -var_name <- data$Variable$varName if (length(var_name) != 1) { stop("One variable name must be included in element 'Variable$varName' ", "of parameter 'data'.") @@ -127,13 +187,13 @@ list_pos <- 1 if (any(dimname == 'longitude') | any(dimname == 'lon')) { dim_lon <- ncdim_def(name = 'lon', units = 'degrees', - vals = as.vector(data$lon), longname = 'longitude') + vals = as.vector(lon), longname = 'longitude') dims_var[[list_pos]] <- dim_lon list_pos <- list_pos + 1 } if (any(dimname == 'latitude') | any(dimname == 'lat')) { dim_lat <- ncdim_def(name = 'lat', units = 'degrees_north', - vals = as.vector(data$lat), longname = 'latitude') + vals = as.vector(lat), longname = 'latitude') dims_var[[list_pos]] <- dim_lat list_pos <- list_pos + 1 } @@ -143,15 +203,13 @@ list_pos <- 1 stop("Ask for saving realizations or further dimensions to the mantainer.") } else { dim_memb <- ncdim_def(name = 'ensemble', units = "adim", - vals = 1 : dim(data$data)[which(dimname == 'member')], + vals = 1 : dim(data)[which(dimname == 'member')], longname = 'ensemble', create_dimvar = TRUE) dims_var[[list_pos]] <- dim_memb list_pos <- list_pos + 1 } } - # Lead-time depends on the start date - nlt <- length(data$Dates$start)/n_sdates if (any(dimname == 'level')) { stop("Ask for saving 3Dim fields to the mantainer.") @@ -160,49 +218,56 @@ list_pos <- 1 for (i in 1 : n_datasets) { path <- file.path(destination, datasets[i], var_name) dir.create(path, recursive = TRUE) - startdate <- gsub("-", "", data$Datasets[[i]]$InitializationDates[[1]]) - file_name <- paste0(var_name, "_", startdate, ".nc") - full_filename <- file.path(path, file_name) + startdate <- gsub("-", "", startdates) - data_dataset <- Subset(data$data, along = which(dimname == 'dataset'), indices = i) - standard_order <- c("lon", "lat", "member", "ftime") - change_names <- c("lon", "lat", "ensemble", "ftime") - for (j in 1 : n_sdates) { - n_data <- s2dverification::Subset(data_dataset, - along = which(dimname == 'sdate'), - indices = j, drop = TRUE) - pos_standard_order <- match( standard_order, names(dim(n_data))) - n_data <- aperm(n_data, pos_standard_order) - names(dim(n_data)) <- change_names - - # Lead-time depends on the start date - # The correct time should be selected from $Dates$start - time_values <- as.Date(substr(data$Dates$start[(j * nlt - nlt + 1):(j * nlt)], - 1, 10)) - - if (any(dimname == 'time') | any(dimname == 'ftime')) { - dim_time <- ncdim_def(name = 'time', units = 'days since 1970-01-01', - vals = as.numeric(time_values), - longname = 'time', unlim = TRUE) - if (i == 1 & j == 1) { - dims_var[[list_pos]] <- dim_time - list_pos <- list_pos + 1 - } - } - if (!is.character(attributes(data$Variable)$units)) { - units = attributes(data$Variable)$variable$units - } else { - units = attributes(data$Variable)$units - } - datanc <- ncvar_def(name = var_name, - units = units, - dim = dims_var, missval = -99999) - file_nc <- nc_create(full_filename[j], datanc) - ncvar_put(file_nc, datanc, n_data) - ncatt_put(file_nc, datanc, 'coordinates', attr(data$lon, 'cdo_grid_name')) - ncatt_put(file_nc, datanc, 'projection', attr(data$lon, 'projection')) - nc_close(file_nc) - } + Apply(list(data, startdate, Dates), + target_dims = list(c('member', 'time', 'latitude', 'longitude'), NULL, 'time'), + fun = .saveExp, var_name = var_name, units = units, + dims_var = dims_var, cdo_grid_name = cdo_grid_name, projection = projection, + destination = destination) } } + +# data is an array with dimensions: member, time, lat, lon: +# Dates is a vector of the dates for the time dimension +# dims_var is a list with the ncdim_def of common variables in dataset: member, lat and lon: +# data <- 1:(3 * 4 * 5 * 6) +# dim(data) <- c(longitude = 3, latitude = 4, time = 5, member = 6) +# var_name <- 'tas' +# units <- 'K' +# lon <- 1:3 +# lat <- 1:4 +# sdate = '19001101' +# destination = '/esarchive/scratch/nperez/git/Flor/cstools/' +# dims_var = list(ncdim_def(name = 'lon', units = 'degrees', +# vals = as.vector(lon), longname = 'longitude'), +# ncdim_def(name = 'lat', units = 'degrees_north', +# vals = as.vector(lat), longname = 'latitude'), +# ncdim_def(name = 'ensemble', units = "adim", +# vals = 1 : 6, +# longname = 'ensemble', create_dimvar = TRUE)) +#Dates <- as.Date(c("1900-11-01", "1900-12-01", "1901-01-01", "1901-02-01", "1901-03-01")) +#.saveExp(data, sdate, Dates, var_name, units, dims_var, cdo_grid_name = 'r360x181', projection = 'none', destination) +.saveExp <- function(data, sdate, Dates, var_name, units, dims_var, + cdo_grid_name, projection, destination) { + dim_names <- names(dim(data)) + if (any(dim_names != c('longitude', 'latitude', 'member', 'time'))) { + data <- Reorder(data, c('longitude', 'latitude', 'member', 'time')) + } + dim_time <- ncdim_def(name = 'time', units = 'days since 1970-01-01', + vals = as.numeric(Dates), + longname = 'time', unlim = TRUE) + list_pos = length(dims_var) + 1 + dims_var[[list_pos]] <- dim_time + datanc <- ncvar_def(name = var_name, + units = units, + dim = dims_var, missval = -99999) + file_name <- paste0(var_name, "_", sdate, ".nc") + full_filename <- file.path(destination, file_name) + file_nc <- nc_create(full_filename, datanc) + ncvar_put(file_nc, datanc, data) + ncatt_put(file_nc, datanc, 'coordinates', cdo_grid_name) + ncatt_put(file_nc, datanc, 'projection', projection) + nc_close(file_nc) +} -- GitLab From 97a50a5dfd54b0608f88ccbb82f936542ebbef60 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 11:47:35 +0200 Subject: [PATCH 2/9] Fixes reported problems --- R/CST_SaveExp.R | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 3c0050a0..842b8fd0 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -40,17 +40,19 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { stop("Parameter 'data' must be of the class 's2dv_cube', ", "as output by CSTools::CST_Load.") } - sdates <- lapply(1:length(data$Datasets), function(x) {data$Datasets[[x]]$InitializationDates[[1]]})[[1]] + sdates <- lapply(1:length(data$Datasets), function(x) { + data$Datasets[[x]]$InitializationDates[[1]]})[[1]] if (!is.character(attributes(data$Variable)$units)) { units <- attributes(data$Variable)$variable$units } else { units <- attributes(data$Variable)$units } - cdo_grid_name = attr(lon, 'cdo_grid_name') - projection = attr(lon, 'projection') + cdo_grid_name = attr(data$lon, 'cdo_grid_name') + projection = attr(data$lon, 'projection') var_name <- data$Variable$varName time_values <- data$Dates$start - dim(time_values) <- c(time = length(time_values)/length(sdates), sdate = length(sdates)) + dim(time_values) <- c(time = length(time_values) / length(sdates), + sdate = length(sdates)) SaveExp(data = data$data, lon = data$lon, lat = data$lat, Dataset = names(data$Datasets), var_name = var_name, units = units, cdo_grid_name = cdo_grid_name, projection = projection, @@ -122,12 +124,11 @@ SaveExp <- function(data, lon, lat, Dataset, var_name, units, startdates, Dates, dimname[which(dimname == "lat")] <- "latitude" names(dim(data))[which(dimname == "lat")] <- "latitude" } -names(dim(data)) <- dimname - + names(dim(data)) <- dimname if (is.null(dimname)) { stop("Element 'data' in parameter 'data' must have named dimensions.") } -sdate_pos <- which(dimname == "sdate") + sdate_pos <- which(dimname == "sdate") if (length(sdate_pos) == 0) { stop("Element 'data' in parameter 'data' hasn't 'sdate' dimension.") @@ -136,8 +137,8 @@ sdate_pos <- which(dimname == "sdate") " dimension.") } -dataset_pos <- which(dimname == "dataset" | dimname == "dat") -dims <- dim(data) + dataset_pos <- which(dimname == "dataset" | dimname == "dat") + dims <- dim(data) if (length(dataset_pos) == 0) { warning("Element 'data' in parameter 'data' hasn't 'dataset' dimension. ", "All data is stored in the same 'dataset' folder.") @@ -149,9 +150,9 @@ dims <- dim(data) stop("Element 'data' in parameter 'data' has more than one 'dataset'", " dimension.") } -n_datasets <- dim(data)[dataset_pos] # number of folder by dataset -# dataset names: -datasets <- Dataset + n_datasets <- dim(data)[dataset_pos] # number of folder by dataset + # dataset names: + datasets <- Dataset if (n_datasets > length(datasets)) { warning("Dimension 'dataset' in element 'data' from parameter 'data' ", "is greater than those listed in element 'Datasets' and the ", @@ -163,11 +164,11 @@ datasets <- Dataset " first element will be used.") datasets <- datasets[1 : n_datasets] } -# var names: + # var names: if ('var' %in% dimname) { var_pos <- which(dimname == 'var') if (dims[var_pos] == 1) { - data$data <- adrop(data, drop = var_pos) + data <- adrop(data, drop = var_pos) dimname <- names(dim(data)) } } @@ -180,10 +181,10 @@ datasets <- Dataset "must be a character string.") } -known_dim_names <- c("var", "lat", "latitude", "lon", "longitude", "time", - "ftime", "sdate", "dataset", "dat", "nlevel", "levels") -dims_var <- NULL -list_pos <- 1 + known_dim_names <- c("var", "lat", "latitude", "lon", "longitude", "time", + "ftime", "sdate", "dataset", "dat", "nlevel", "levels") + dims_var <- NULL + list_pos <- 1 if (any(dimname == 'longitude') | any(dimname == 'lon')) { dim_lon <- ncdim_def(name = 'lon', units = 'degrees', @@ -225,7 +226,7 @@ list_pos <- 1 target_dims = list(c('member', 'time', 'latitude', 'longitude'), NULL, 'time'), fun = .saveExp, var_name = var_name, units = units, dims_var = dims_var, cdo_grid_name = cdo_grid_name, projection = projection, - destination = destination) + destination = path) } } -- GitLab From 5bee9776a364f62e854476a1713bc66085e43b57 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 12:50:53 +0200 Subject: [PATCH 3/9] Fix in dates --- R/CST_SaveExp.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 842b8fd0..83bbaf53 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -221,9 +221,10 @@ SaveExp <- function(data, lon, lat, Dataset, var_name, units, startdates, Dates, dir.create(path, recursive = TRUE) startdate <- gsub("-", "", startdates) - + dim(startdate) <- c(sdate = length(startdate)) Apply(list(data, startdate, Dates), - target_dims = list(c('member', 'time', 'latitude', 'longitude'), NULL, 'time'), + target_dims = list(c('member', 'time', 'latitude', 'longitude'), + NULL, 'time'), fun = .saveExp, var_name = var_name, units = units, dims_var = dims_var, cdo_grid_name = cdo_grid_name, projection = projection, destination = path) -- GitLab From b3a7387bca06e3b4ac312716e13b96b8679fdce5 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 13:20:16 +0200 Subject: [PATCH 4/9] documentation automatically generated with devtools --- NAMESPACE | 2 ++ man/SaveExp.Rd | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 man/SaveExp.Rd diff --git a/NAMESPACE b/NAMESPACE index 342847f3..ba2dc402 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,6 +37,7 @@ export(RFSlope) export(RFTemp) export(RainFARM) export(RegimesAssign) +export(SaveExp) export(SplitDim) export(WeatherRegime) export(as.s2dv_cube) @@ -47,6 +48,7 @@ import(multiApply) import(ncdf4) import(qmap) import(rainfarmr) +import(s2dv) import(s2dverification) import(stats) importFrom(ClimProjDiags,SelBox) diff --git a/man/SaveExp.Rd b/man/SaveExp.Rd new file mode 100644 index 00000000..f2999518 --- /dev/null +++ b/man/SaveExp.Rd @@ -0,0 +1,69 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/CST_SaveExp.R +\name{SaveExp} +\alias{SaveExp} +\title{Save an experiment in a format compatible with CST_Load} +\usage{ +SaveExp( + data, + lon, + lat, + Dataset, + var_name, + units, + startdates, + Dates, + cdo_grid_name, + projection, + destination +) +} +\arguments{ +\item{data}{an multi-dimensional array with named dimensions (longitude, latitude, time, member, sdate)} + +\item{Dataset}{a vector of character string indicating the names of the datasets} + +\item{var_name}{a character string indicating the name of the variable to be saved} + +\item{units}{a character string indicating the units of the variable} + +\item{startdates}{a vector of dates indicating the initialization date of each simulations} + +\item{Dates}{a matrix of dates with two dimension 'time' and 'sdate'.} + +\item{cdo_grid_name}{a character string indicating the name of the grid e.g.: 'r360x181'} + +\item{projection}{a character string indicating the projection name} + +\item{destination}{a character string indicating the path where to store the NetCDF files} + +\item{vector}{of latitud corresponding to the latitudinal dimension in data} +} +\value{ +the function creates as many files as sdates per dataset. Each file could contain multiple members +The path will be created with the name of the variable and each Datasets. +} +\description{ +This function is created for compatibility with CST_Load/Load for saving post-processed datasets such as those calibrated of downscaled with CSTools functions +} +\examples{ +data <- lonlat_data$exp$data +lon <- lonlat_data$exp$lon +lat <- lonlat_data$exp$lat +Dataset <- 'XXX' +var_name <- 'tas' +units <- 'k' +startdates <- lapply(1:length(lonlat_data$exp$Datasets), + function(x) { + lonlat_data$exp$Datasets[[x]]$InitializationDates[[1]]})[[1]] +Dates <- lonlat_data$exp$Dates$start +dim(Dates) <- c(time = length(Dates)/length(startdates), sdate = length(startdates)) +cdo_grid_name = attr(lonlat_data$exp$lon, 'cdo_grid_name') +projection = attr(lonlat_data$exp$lon, 'projection') +destination = '/esarchive/scratch/nperez/git/Flor/cstools/' +SaveExp(data, lon, lat, Dataset, var_name, units, startdates, Dates, + cdo_grid_name, projection, destination) +} +\author{ +Perez-Zanon Nuria, \email{nuria.perez@bsc.es} +} -- GitLab From 527da14a2e6edcc91ecdd17c41d8c96f6508996a Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 13:21:20 +0200 Subject: [PATCH 5/9] fix listed in NEWs --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 19caa068..1a9069e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ + DESCRIPTION specifies the minimum multiApply version required + EnsClustering has a fixed 'closest_member' output + PlotCombinedMap handles masks correctly + + CST_SaveExp uses multiApply and save time dimension correctly ### CSTools 3.0.0 **Submission date to CRAN: 10-02-2020** -- GitLab From 281befdd6f965a5ecc84cb11129bf288915bd64c Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 13:28:47 +0200 Subject: [PATCH 6/9] adding s2dv dependency to DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 0492186b..09b9cf06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,6 +47,7 @@ Depends: maps Imports: s2dverification, + s2dv, rainfarmr, multiApply (>= 2.1.1), qmap, -- GitLab From b8eff7b1ceadcd82ab67c210bb3000906327d657 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 13:48:17 +0200 Subject: [PATCH 7/9] dontrun examples using local paths --- R/CST_SaveExp.R | 4 +++- man/SaveExp.Rd | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 83bbaf53..6335c67b 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -84,6 +84,7 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { #'@import multiApply #' #'@examples +#'\dontrun{ #'data <- lonlat_data$exp$data #'lon <- lonlat_data$exp$lon #'lat <- lonlat_data$exp$lat @@ -97,9 +98,10 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { #'dim(Dates) <- c(time = length(Dates)/length(startdates), sdate = length(startdates)) #'cdo_grid_name = attr(lonlat_data$exp$lon, 'cdo_grid_name') #'projection = attr(lonlat_data$exp$lon, 'projection') -#'destination = '/esarchive/scratch/nperez/git/Flor/cstools/' +#'destination = './path/' #'SaveExp(data, lon, lat, Dataset, var_name, units, startdates, Dates, #' cdo_grid_name, projection, destination) +#'} #'@export SaveExp <- function(data, lon, lat, Dataset, var_name, units, startdates, Dates, cdo_grid_name, projection, destination) { diff --git a/man/SaveExp.Rd b/man/SaveExp.Rd index f2999518..626a64be 100644 --- a/man/SaveExp.Rd +++ b/man/SaveExp.Rd @@ -47,6 +47,7 @@ The path will be created with the name of the variable and each Datasets. This function is created for compatibility with CST_Load/Load for saving post-processed datasets such as those calibrated of downscaled with CSTools functions } \examples{ +\dontrun{ data <- lonlat_data$exp$data lon <- lonlat_data$exp$lon lat <- lonlat_data$exp$lat @@ -60,10 +61,11 @@ Dates <- lonlat_data$exp$Dates$start dim(Dates) <- c(time = length(Dates)/length(startdates), sdate = length(startdates)) cdo_grid_name = attr(lonlat_data$exp$lon, 'cdo_grid_name') projection = attr(lonlat_data$exp$lon, 'projection') -destination = '/esarchive/scratch/nperez/git/Flor/cstools/' +destination = './path/' SaveExp(data, lon, lat, Dataset, var_name, units, startdates, Dates, cdo_grid_name, projection, destination) } +} \author{ Perez-Zanon Nuria, \email{nuria.perez@bsc.es} } -- GitLab From 09a5027409a0cceeb434ecc27cfbca171d855a7a Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 13:58:24 +0200 Subject: [PATCH 8/9] only request Reorder to be loaded from s2dv --- NAMESPACE | 2 +- R/CST_SaveExp.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index ba2dc402..e070ff78 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,7 +48,6 @@ import(multiApply) import(ncdf4) import(qmap) import(rainfarmr) -import(s2dv) import(s2dverification) import(stats) importFrom(ClimProjDiags,SelBox) @@ -79,6 +78,7 @@ importFrom(maps,map) importFrom(plyr,.) importFrom(plyr,dlply) importFrom(reshape2,melt) +importFrom(s2dv,Reorder) importFrom(utils,glob2rx) importFrom(utils,head) importFrom(utils,tail) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 6335c67b..0b585669 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -18,7 +18,7 @@ #' #'@importFrom ClimProjDiags Subset #'@import ncdf4 -#'@import s2dv +#'@importFrom s2dv Reorder #'@import multiApply #' #'@examples @@ -80,7 +80,7 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { #' #'@importFrom ClimProjDiags Subset #'@import ncdf4 -#'@import s2dv +#'@importFrom s2dv Reorder #'@import multiApply #' #'@examples -- GitLab From 2a92f077c0b7254a95b49eaab4ae041f20309e18 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 30 Jun 2020 14:07:27 +0200 Subject: [PATCH 9/9] adding name of parameters lon,lat to SaveExp --- R/CST_SaveExp.R | 4 ++-- man/SaveExp.Rd | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/CST_SaveExp.R b/R/CST_SaveExp.R index 0b585669..c3e04c2a 100644 --- a/R/CST_SaveExp.R +++ b/R/CST_SaveExp.R @@ -64,8 +64,8 @@ CST_SaveExp <- function(data, destination = "./CST_Data") { #'@author Perez-Zanon Nuria, \email{nuria.perez@bsc.es} #' #'@param data an multi-dimensional array with named dimensions (longitude, latitude, time, member, sdate) -#'@param vector of logitud corresponding to the longitudinal dimension in data -#'@param vector of latitud corresponding to the latitudinal dimension in data +#'@param lon vector of logitud corresponding to the longitudinal dimension in data +#'@param lat vector of latitud corresponding to the latitudinal dimension in data #'@param Dataset a vector of character string indicating the names of the datasets #'@param var_name a character string indicating the name of the variable to be saved #'@param units a character string indicating the units of the variable diff --git a/man/SaveExp.Rd b/man/SaveExp.Rd index 626a64be..40ace2db 100644 --- a/man/SaveExp.Rd +++ b/man/SaveExp.Rd @@ -21,6 +21,10 @@ SaveExp( \arguments{ \item{data}{an multi-dimensional array with named dimensions (longitude, latitude, time, member, sdate)} +\item{lon}{vector of logitud corresponding to the longitudinal dimension in data} + +\item{lat}{vector of latitud corresponding to the latitudinal dimension in data} + \item{Dataset}{a vector of character string indicating the names of the datasets} \item{var_name}{a character string indicating the name of the variable to be saved} @@ -36,8 +40,6 @@ SaveExp( \item{projection}{a character string indicating the projection name} \item{destination}{a character string indicating the path where to store the NetCDF files} - -\item{vector}{of latitud corresponding to the latitudinal dimension in data} } \value{ the function creates as many files as sdates per dataset. Each file could contain multiple members -- GitLab