From 6b0cc7cfa801c9b4def40788df7cbd2d1004e404 Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Thu, 7 Jul 2022 15:15:03 +0200 Subject: [PATCH 1/3] first version --- R/ShiftLon.R | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 R/ShiftLon.R diff --git a/R/ShiftLon.R b/R/ShiftLon.R new file mode 100644 index 0000000..aaa1c43 --- /dev/null +++ b/R/ShiftLon.R @@ -0,0 +1,102 @@ +#'Shift longitudes in maps +#' +#'@description This function shifts the longitudes in maps. +#' +#'@param data An array with, at least, 'lon_dim' dimension. +#'@param lon A vector with the longitudes. +#'@param westB A number with the west boundary for the new longitudes. +#'@param lon_dim A string with the name of the longitude dimension. +#' The default value is "lon". +#'@param ncores The number of cores used for computation. The default +#' value is NULL (it uses only one core). +#' +#'@return +#'\item{data}{ +#' Array with the shifted data with the same dimensions as parameter 'data'. +#'} +#'\item{lon}{ +#' The new longitudes with the same length as parameter 'lon'. +#'} +#' +#'@import multiApply +#'@examples +#'data <- array(data = 1:50, dim = c(lon = 360, lat = 181)) +#'lon <- array(data = 0:359, dim = c(lon = 360)) +#'lat <- -90:90 ## lat does not change +#'shifted <- ShiftLon(data = data, lon = lon, westB = -180, ncores = 1) +#'s2dv::PlotEquiMap(var = data, lon = lon, lat = lat, filled.continents = FALSE) +#'s2dv::PlotEquiMap(var = shifted$data, lon = shifted$lon, lat = lat, filled.continents = FALSE) +#' +#'@import multiApply +#'@export +ShiftLon <- function(data, lon, westB, lon_dim = 'lon', ncores = NULL) { + + ## Check inputs + ## data + if (!is.array(data)){ + stop("Parameter 'data' must be and array.") + } + ## lon + if (!is.numeric(lon)){ + stop("Parameter 'lon' must be numeric.") + } else if (!(length(lon) == as.numeric(dim(data)[lon_dim]))){ + stop("The length of 'lon' must coindide with the length of 'lon_dim' in 'data'.") + } + ## westB + if (!is.numeric(westB)){ + stop("Parameter 'westB' must be numeric.") + } + ## lon_dim + if (!is.character(lon_dim)){ + stop("Parameter 'lon_dim' must be a character string.") + } + if (!(lon_dim %in% names(dim(data)))){ + stop("Parameter 'data' must have 'lon_dim' dimension.") + } + ## ncores + if (!is.null(ncores)) { + if (!is.numeric(ncores) | any(ncores %% 1 != 0) | any(ncores < 0) | + length(ncores) > 1) { + stop("Parameter 'ncores' must be a positive integer.") + } + } + + #########--- Shifting the longitudes (only needed to do it once) ---############ + ## adjust western boundary to lon vector if necessary + if (min(abs(westB-lon))>90){ + westB <- ifelse(westB>0,westB-360,westB+360) + } + ## find closest index in lon vector + first <- which.min(abs(westB-lon))[1] + if (first==1){ + new.lon <- lon + } else { + new.lon <- c(lon[first:length(lon)],lon[1:(first-1)]) + } + ## order to monotonically increasing + if (!all(diff(new.lon)>0)){ + new.lon[1:(which(diff(new.lon)<0))] <- new.lon[1:(which(diff(new.lon)<0))]-360 + if (all(new.lon<0)){ + new.lon <- new.lon+360 + } + } + + ############--- Shifting the data ---############ + output <- multiApply::Apply(data = data, + target_dims = lon_dim, + fun = .ShiftLon, + lon = lon, + new.lon = new.lon, + ncores = ncores)$output1 + return(list(data = output, + lon = new.lon)) +} + +.ShiftLon <- function(data, lon, new.lon) { + + new.data <- NA * data + new.data[new.lon %in% lon] <- data[lon %in% new.lon, drop = F] + new.data[!new.lon %in% lon] <- data[!lon %in% new.lon, drop = F] + + return(new.data) +} -- GitLab From 140f4ac00845bc9bcc4fc38579ef6a15084ff51c Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 5 Aug 2022 12:33:47 +0200 Subject: [PATCH 2/3] Revise ShiftLon.R and create unit tests --- R/ShiftLon.R | 140 +++++++++----- man/ShiftLon.Rd | 48 +++++ tests/testthat/test-ShiftLon.R | 342 +++++++++++++++++++++++++++++++++ 3 files changed, 477 insertions(+), 53 deletions(-) create mode 100644 man/ShiftLon.Rd create mode 100644 tests/testthat/test-ShiftLon.R diff --git a/R/ShiftLon.R b/R/ShiftLon.R index aaa1c43..aad4deb 100644 --- a/R/ShiftLon.R +++ b/R/ShiftLon.R @@ -1,99 +1,133 @@ -#'Shift longitudes in maps +#'Shift longitudes of a data array #' -#'@description This function shifts the longitudes in maps. +#'@description Shift the longitudes of a data array. Only reasonable for global +#' longitude shifting. It is useful for map plotting or aligning datasets. #' -#'@param data An array with, at least, 'lon_dim' dimension. -#'@param lon A vector with the longitudes. -#'@param westB A number with the west boundary for the new longitudes. -#'@param lon_dim A string with the name of the longitude dimension. -#' The default value is "lon". -#'@param ncores The number of cores used for computation. The default -#' value is NULL (it uses only one core). +#'@param data A named multidimensional array with at least 'lon_dim' dimension. +#'@param lon A numeric vector of longitudes. The values are expected to be +#' monotonic increasing. +#'@param westB A number indicating the west boundary of the new longitudes. +#'@param lon_dim A character string indicating the name of the longitude +#' dimension in 'data'. The default value is 'lon'. +#'@param ncores An integer indicating the number of cores used for computation. +#' The default value is NULL (use only one core). #' #'@return +#'A list of 2: #'\item{data}{ -#' Array with the shifted data with the same dimensions as parameter 'data'. +#' Array of the shifted data with the same dimensions as parameter 'data'. #'} #'\item{lon}{ -#' The new longitudes with the same length as parameter 'lon'. +#' The monotonic increasing new longitudes with the same length as parameter +#' 'lon' and start at 'westB'. #'} #' -#'@import multiApply #'@examples #'data <- array(data = 1:50, dim = c(lon = 360, lat = 181)) #'lon <- array(data = 0:359, dim = c(lon = 360)) #'lat <- -90:90 ## lat does not change #'shifted <- ShiftLon(data = data, lon = lon, westB = -180, ncores = 1) +#' +#' \donttest{ #'s2dv::PlotEquiMap(var = data, lon = lon, lat = lat, filled.continents = FALSE) #'s2dv::PlotEquiMap(var = shifted$data, lon = shifted$lon, lat = lat, filled.continents = FALSE) -#' +#' } +#' #'@import multiApply #'@export ShiftLon <- function(data, lon, westB, lon_dim = 'lon', ncores = NULL) { - ## Check inputs + # Check inputs ## data - if (!is.array(data)){ - stop("Parameter 'data' must be and array.") - } - ## lon - if (!is.numeric(lon)){ - stop("Parameter 'lon' must be numeric.") - } else if (!(length(lon) == as.numeric(dim(data)[lon_dim]))){ - stop("The length of 'lon' must coindide with the length of 'lon_dim' in 'data'.") + if (is.null(data)) { + stop("Parameter 'data' cannot be NULL.") } - ## westB - if (!is.numeric(westB)){ - stop("Parameter 'westB' must be numeric.") + if (!is.array(data) | !is.numeric(data)) { + stop("Parameter 'data' must be a numeric array.") + } + if(any(is.null(names(dim(data))))| any(nchar(names(dim(data))) == 0)) { + stop("Parameter 'data' must have dimension names.") } ## lon_dim - if (!is.character(lon_dim)){ + if (!is.character(lon_dim) | length(lon_dim) > 1) { stop("Parameter 'lon_dim' must be a character string.") } - if (!(lon_dim %in% names(dim(data)))){ - stop("Parameter 'data' must have 'lon_dim' dimension.") + if (!(lon_dim %in% names(dim(data)))) { + stop("Parameter 'lon_dim' is not found in 'data' dimensions.") + } + ## lon + if (!is.numeric(lon)) { + stop("Parameter 'lon' must be numeric.") + } + if (!(length(lon) == as.numeric(dim(data)[lon_dim]))) { + stop("The length of 'lon' must be the same as the length of 'lon_dim' in 'data'.") + } + if (any(diff(lon) < 0)) { + stop("Parameter 'lon' must be monotonic increasing.") + } + ## westB + if (!is.numeric(westB)) { + stop("Parameter 'westB' must be numeric.") + } + if (length(westB) != 1) { + westB <- westB[1] + warning("Parameter 'westB' should be a number. Use the first element only.") } ## ncores if (!is.null(ncores)) { - if (!is.numeric(ncores) | any(ncores %% 1 != 0) | any(ncores < 0) | - length(ncores) > 1) { + if (!is.numeric(ncores)) { + stop("Parameter 'ncores' must be a positive integer.") + } else if (any(ncores %% 1 != 0) | any(ncores <= 0) | length(ncores) > 1) { stop("Parameter 'ncores' must be a positive integer.") } } - #########--- Shifting the longitudes (only needed to do it once) ---############ - ## adjust western boundary to lon vector if necessary - if (min(abs(westB-lon))>90){ - westB <- ifelse(westB>0,westB-360,westB+360) + ############################################# + + # Shifting the longitudes (only needed to do it once) + ## Adjust western boundary of lon vector if necessary + ## If westB is not within lon, adjust it to find 'first' below + shft_westB_back <- 0 + if (westB < min(lon)) { + westB <- westB + 360 + shft_westB_back <- -360 + } else if (westB > max(lon)) { + westB <- westB - 360 + shft_westB_back <- 360 + } + if (westB < min(lon) | westB > (min(lon) + 360)) { + stop("westB is too far away from the 'lon' range.") } - ## find closest index in lon vector - first <- which.min(abs(westB-lon))[1] - if (first==1){ + + ## Find closest index in lon vector + first <- which.min(abs(westB - lon))[1] + if (first == 1) { new.lon <- lon } else { new.lon <- c(lon[first:length(lon)],lon[1:(first-1)]) } - ## order to monotonically increasing - if (!all(diff(new.lon)>0)){ - new.lon[1:(which(diff(new.lon)<0))] <- new.lon[1:(which(diff(new.lon)<0))]-360 - if (all(new.lon<0)){ - new.lon <- new.lon+360 - } + ## Order to monotonically increasing + if (!all(diff(new.lon) > 0)) { + new.lon[(which(diff(new.lon) < 0) + 1):length(new.lon)] <- new.lon[(which(diff(new.lon) < 0) + 1):length(new.lon)] + 360 + } - ############--- Shifting the data ---############ - output <- multiApply::Apply(data = data, - target_dims = lon_dim, - fun = .ShiftLon, - lon = lon, - new.lon = new.lon, - ncores = ncores)$output1 - return(list(data = output, - lon = new.lon)) + # Shifting the data + output <- Apply(data = data, + target_dims = lon_dim, + fun = .ShiftLon, + lon = lon, + new.lon = new.lon, + ncores = ncores)$output1 + + # Shift new.lon back to start at westB + new.lon <- new.lon + shft_westB_back + + return(list(data = output, lon = new.lon)) } .ShiftLon <- function(data, lon, new.lon) { - + # data: [lon] new.data <- NA * data new.data[new.lon %in% lon] <- data[lon %in% new.lon, drop = F] new.data[!new.lon %in% lon] <- data[!lon %in% new.lon, drop = F] diff --git a/man/ShiftLon.Rd b/man/ShiftLon.Rd new file mode 100644 index 0000000..bf8e0de --- /dev/null +++ b/man/ShiftLon.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ShiftLon.R +\name{ShiftLon} +\alias{ShiftLon} +\title{Shift longitudes of a data array} +\usage{ +ShiftLon(data, lon, westB, lon_dim = "lon", ncores = NULL) +} +\arguments{ +\item{data}{A named multidimensional array with at least 'lon_dim' dimension.} + +\item{lon}{A numeric vector of longitudes. The values are expected to be +monotonic increasing.} + +\item{westB}{A number indicating the west boundary of the new longitudes.} + +\item{lon_dim}{A character string indicating the name of the longitude +dimension in 'data'. The default value is 'lon'.} + +\item{ncores}{An integer indicating the number of cores used for computation. +The default value is NULL (use only one core).} +} +\value{ +A list of 2: +\item{data}{ + Array of the shifted data with the same dimensions as parameter 'data'. +} +\item{lon}{ + The monotonic increasing new longitudes with the same length as parameter + 'lon' and start at 'westB'. +} +} +\description{ +Shift the longitudes of a data array. Only reasonable for global + longitude shifting. It is useful for map plotting or aligning datasets. +} +\examples{ +data <- array(data = 1:50, dim = c(lon = 360, lat = 181)) +lon <- array(data = 0:359, dim = c(lon = 360)) +lat <- -90:90 ## lat does not change +shifted <- ShiftLon(data = data, lon = lon, westB = -180, ncores = 1) + + \donttest{ +s2dv::PlotEquiMap(var = data, lon = lon, lat = lat, filled.continents = FALSE) +s2dv::PlotEquiMap(var = shifted$data, lon = shifted$lon, lat = lat, filled.continents = FALSE) + } + +} diff --git a/tests/testthat/test-ShiftLon.R b/tests/testthat/test-ShiftLon.R new file mode 100644 index 0000000..efa358e --- /dev/null +++ b/tests/testthat/test-ShiftLon.R @@ -0,0 +1,342 @@ +context("ShiftLon tests") + +############################################## + +# dat1 +dat1 <- array(1:360, dim = c(lon = 360, lat = 181)) +lon1 <- 0:359 +lat1 <- -90:90 + +# dat2 +dat2 <- array(1:360, dim = c(lon = 360, lat = 181)) +lon2 <- -180:179 +lat2 <- -90:90 + +# dat3 +dat3 <- array(1:512, dim = c(lon = 512, lat = 216, time = 2)) +lon3 <- seq(0, 360, length.out = 513)[1:512] +lat3 <- seq(-90, 90, length.out = 216) + +############################################## +test_that("1. Input checks", { + # data + expect_error( + ShiftLon(c()), + "Parameter 'data' cannot be NULL." + ) + expect_error( + ShiftLon(1:10), + "Parameter 'data' must be a numeric array." + ) + expect_error( + ShiftLon(array(1:10)), + "Parameter 'data' must have dimension names." + ) + # lon_dim + expect_error( + ShiftLon(dat1, lon1, lon_dim = 1), + "Parameter 'lon_dim' must be a character string." + ) + expect_error( + ShiftLon(dat1, lon1, lon_dim = 'a'), + "Parameter 'lon_dim' is not found in 'data' dimensions." + ) + # lon + expect_error( + ShiftLon(dat1, lon = 'a'), + "Parameter 'lon' must be numeric." + ) + expect_error( + ShiftLon(dat1, lon = 1:100), + "The length of 'lon' must be the same as the length of 'lon_dim' in 'data'." + ) + expect_error( + ShiftLon(dat1, lon = 359:0), + "Parameter 'lon' must be monotonic increasing." + ) + # westB + expect_error( + ShiftLon(dat1, lon = lon1, westB = 'a'), + "Parameter 'westB' must be numeric." + ) + expect_warning( + ShiftLon(dat1, lon = lon1, westB = 1:10), + "Parameter 'westB' should be a number. Use the first element only." + ) + # ncores + expect_error( + ShiftLon(dat1, lon = lon1, westB = 10, ncores = 'a'), + "Parameter 'ncores' must be a positive integer." + ) + +}) + + +############################################## +test_that("2. dat1", { + + westB <- -180 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + -180:179 + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(181:360, 1:180) + ) + #----------------- + westB <- 90 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + 90:(90 + 359) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(91:360, 1:90) + ) + #----------------- + westB <- 300 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + 300:(300 + 359) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(301:360, 1:300) + ) + #----------------- + westB <- -270 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + -270:(-270+359) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(91:360, 1:90) + ) + #----------------- + westB <- -10 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + -10:(-10 + 359) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(351:360, 1:350) + ) + #----------------- + westB <- -0.5 + expect_equal( + dim(ShiftLon(dat1, lon = lon1, westB = westB)$data), + dim(dat1) + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$lon, + -1:358 + ) + expect_equal( + ShiftLon(dat1, lon = lon1, westB = westB)$data[,1], + c(360, 1:359) + ) + +}) + + +############################################## +test_that("3. dat2", { + + westB <- 0 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + 0:359 + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(181:360, 1:180) + ) + #----------------- + westB <- 90 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + 90:(90 + 359) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(271:360, 1:270) + ) + #----------------- + westB <- 300 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + 300:(300 + 359) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(121:360, 1:120) + ) + #----------------- + westB <- -270 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + -270:(-270+359) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(271:360, 1:270) + ) + #----------------- + westB <- -10 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + -10:(-10 + 359) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(171:360, 1:170) + ) + #----------------- + westB <- -0.5 + expect_equal( + dim(ShiftLon(dat2, lon = lon2, westB = westB)$data), + dim(dat2) + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$lon, + -1:358 + ) + expect_equal( + ShiftLon(dat2, lon = lon2, westB = westB)$data[,1], + c(180:360, 1:179) + ) + +}) + +############################################## +test_that("4. dat3", { + + westB <- -180 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(westB, westB + 360, length.out = 513)[-513] + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(257:512, 1:256) + ) + #----------------- + westB <- 90 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(westB, westB + 360, length.out = 513)[-513] + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(129:512, 1:128) + ) + #----------------- + westB <- 300 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(300.2344, 300.2344 + 360, length.out = 513)[-513], + tolerance = 0.001 + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(428:512, 1:427) + ) + #----------------- + westB <- -270 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(westB, westB + 360, length.out = 513)[-513] + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(129:512, 1:128) + ) + #----------------- + westB <- -10 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(-9.843750, -9.843750 + 360, length.out = 513)[-513] + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(499:512, 1:498) + ) + #----------------- + westB <- -0.5 + expect_equal( + dim(ShiftLon(dat3, lon = lon3, westB = westB)$data), + dim(dat3) + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$lon, + seq(-0.703125, -0.703125 + 360, length.out = 513)[-513] + ) + expect_equal( + ShiftLon(dat3, lon = lon3, westB = westB)$data[,1, 2], + c(512, 1:511) + ) + +}) -- GitLab From 29ad5aa0e92fdbbebaaaefa4c28e9772bdfbcc79 Mon Sep 17 00:00:00 2001 From: aho Date: Fri, 5 Aug 2022 12:34:01 +0200 Subject: [PATCH 3/3] Format update --- DESCRIPTION | 2 +- NAMESPACE | 1 + man/AnoAgree.Rd | 1 - man/ArrayToList.Rd | 1 - man/Climdex.Rd | 13 ++++++++++--- man/CombineIndices.Rd | 1 - man/DTRIndicator.Rd | 13 ++++++++++--- man/DTRRef.Rd | 13 ++++++++++--- man/DailyAno.Rd | 4 +--- man/Extremes.Rd | 16 ++++++++++++---- man/Lon2Index.Rd | 1 - man/SeasonSelect.Rd | 1 - man/SelBox.Rd | 1 - man/Subset.Rd | 1 - man/Threshold.Rd | 12 +++++++++--- man/WaveDuration.Rd | 13 ++++++++++--- man/WeightedMean.Rd | 12 +++++++++--- 17 files changed, 73 insertions(+), 33 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cbcbdb2..bd980e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ License: Apache License 2.0 URL: https://earth.bsc.es/gitlab/es/ClimProjDiags BugReports: https://earth.bsc.es/gitlab/es/ClimProjDiags/-/issues Encoding: UTF-8 -RoxygenNote: 5.0.0 +RoxygenNote: 7.2.0 Suggests: knitr, testthat, diff --git a/NAMESPACE b/NAMESPACE index 2a5d243..40ba733 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(Extremes) export(Lon2Index) export(SeasonSelect) export(SelBox) +export(ShiftLon) export(Subset) export(Threshold) export(WaveDuration) diff --git a/man/AnoAgree.Rd b/man/AnoAgree.Rd index c929352..63c1450 100644 --- a/man/AnoAgree.Rd +++ b/man/AnoAgree.Rd @@ -34,4 +34,3 @@ a <- rnorm(6) agree <- AnoAgree(ano = a, membersdim = 1, na.rm = TRUE, ncores = NULL) print(agree) } - diff --git a/man/ArrayToList.Rd b/man/ArrayToList.Rd index 9a7d181..9951ae1 100644 --- a/man/ArrayToList.Rd +++ b/man/ArrayToList.Rd @@ -38,4 +38,3 @@ str(datalist) \seealso{ \link[s2dv]{PlotLayout} } - diff --git a/man/Climdex.Rd b/man/Climdex.Rd index 669570a..372712c 100644 --- a/man/Climdex.Rd +++ b/man/Climdex.Rd @@ -4,8 +4,16 @@ \alias{Climdex} \title{Wrapper for applying the climdex routine ETCCDI climate change indices to n-dimensional arrays.} \usage{ -Climdex(data, metric, threshold = NULL, base.range = NULL, dates = NULL, - timedim = NULL, calendar = NULL, ncores = NULL) +Climdex( + data, + metric, + threshold = NULL, + base.range = NULL, + dates = NULL, + timedim = NULL, + calendar = NULL, + ncores = NULL +) } \arguments{ \item{data}{A numeric n-dimensional array containing daily maximum or minimum temperature, wind speed or precipitation amount.} @@ -68,4 +76,3 @@ David Bronaugh for the Pacific Climate Impacts Consortium (2015). climdex.pcic: PCIC Implementation of Climdex Routines. R package version 1.1-6. http://CRAN.R-project.org/package=climdex.pcic } - diff --git a/man/CombineIndices.Rd b/man/CombineIndices.Rd index 95abc5e..6d032cd 100644 --- a/man/CombineIndices.Rd +++ b/man/CombineIndices.Rd @@ -33,4 +33,3 @@ dim(b) <- c(lon = 2, lat = 3, mod = 4) comb_ind <- CombineIndices(indices = list(a, b), weights = c(2, 1), operation = "add") print(comb_ind) } - diff --git a/man/DTRIndicator.Rd b/man/DTRIndicator.Rd index 33e7f50..e8be18b 100644 --- a/man/DTRIndicator.Rd +++ b/man/DTRIndicator.Rd @@ -4,8 +4,16 @@ \alias{DTRIndicator} \title{Diurnal temperature range indicator (DTR) of multidimensional arrays} \usage{ -DTRIndicator(tmax, tmin, ref, by.seasons = TRUE, dates = NULL, - timedim = NULL, calendar = NULL, ncores = NULL) +DTRIndicator( + tmax, + tmin, + ref, + by.seasons = TRUE, + dates = NULL, + timedim = NULL, + calendar = NULL, + ncores = NULL +) } \arguments{ \item{tmax}{A numeric multidimensional array containing daily maximum temperature.} @@ -60,4 +68,3 @@ aa <- DTRIndicator(tmax, tmin, ref = a, by.seasons = FALSE, ncores = NULL) str(aa) dim(aa$indicator) } - diff --git a/man/DTRRef.Rd b/man/DTRRef.Rd index 6e32e31..daea8c2 100644 --- a/man/DTRRef.Rd +++ b/man/DTRRef.Rd @@ -4,8 +4,16 @@ \alias{DTRRef} \title{Diurnal temperature range of multidimensional arrays} \usage{ -DTRRef(tmax, tmin, by.seasons = TRUE, dates = NULL, timedim = NULL, - calendar = NULL, na.rm = TRUE, ncores = NULL) +DTRRef( + tmax, + tmin, + by.seasons = TRUE, + dates = NULL, + timedim = NULL, + calendar = NULL, + na.rm = TRUE, + ncores = NULL +) } \arguments{ \item{tmax}{A numeric multidimensional array containing daily maximum temperature.} @@ -68,4 +76,3 @@ dim(tmin) <- c(2, 3, 365) a <- DTRRef(tmax, tmin, by.seasons = FALSE, dates = time, timedim = 3, ncores = NULL) str(a) } - diff --git a/man/DailyAno.Rd b/man/DailyAno.Rd index d4033f7..3bf59f6 100644 --- a/man/DailyAno.Rd +++ b/man/DailyAno.Rd @@ -4,8 +4,7 @@ \alias{DailyAno} \title{Daily anomalies} \usage{ -DailyAno(data, jdays = NULL, dates = NULL, calendar = NULL, - na.rm = TRUE) +DailyAno(data, jdays = NULL, dates = NULL, calendar = NULL, na.rm = TRUE) } \arguments{ \item{data}{A vector of daily data.} @@ -31,4 +30,3 @@ jdays <- c(rep(1, 5), rep(2, 5)) daily_anomaly <- DailyAno(data = data, jdays = jdays, na.rm = TRUE) print(daily_anomaly) } - diff --git a/man/Extremes.Rd b/man/Extremes.Rd index 0939fa6..ddc57e8 100644 --- a/man/Extremes.Rd +++ b/man/Extremes.Rd @@ -4,9 +4,18 @@ \alias{Extremes} \title{Sum of spell lengths exceeding daily threshold for n-dimensional arrays} \usage{ -Extremes(data, threshold, op = ">", min.length = 6, - spells.can.span.years = TRUE, max.missing.days = 5, dates = NULL, - timedim = NULL, calendar = NULL, ncores = NULL) +Extremes( + data, + threshold, + op = ">", + min.length = 6, + spells.can.span.years = TRUE, + max.missing.days = 5, + dates = NULL, + timedim = NULL, + calendar = NULL, + ncores = NULL +) } \arguments{ \item{data}{A n-dimensional array containing daily data.} @@ -58,4 +67,3 @@ a <- Extremes(data, threshold = threshold, op = ">", min.length = 6, spells.can. max.missing.days = 5, ncores = NULL) str(a) } - diff --git a/man/Lon2Index.Rd b/man/Lon2Index.Rd index b2012a6..dbae6dc 100644 --- a/man/Lon2Index.Rd +++ b/man/Lon2Index.Rd @@ -33,4 +33,3 @@ pos <- Lon2Index(lon, lonmin = 340, lonmax = 20) lon[pos] } - diff --git a/man/SeasonSelect.Rd b/man/SeasonSelect.Rd index a71fd24..33066ee 100644 --- a/man/SeasonSelect.Rd +++ b/man/SeasonSelect.Rd @@ -45,4 +45,3 @@ attr(data, 'Variables')$common[[2]]$dim[[3]]$vals <- time a <- SeasonSelect(data = data, season = 'JJA') str(a) } - diff --git a/man/SelBox.Rd b/man/SelBox.Rd index 07e92b2..38e3547 100644 --- a/man/SelBox.Rd +++ b/man/SelBox.Rd @@ -43,4 +43,3 @@ a <- SelBox(data = data, lon = lon, lat = lat, region = c(2, 20, 1, 5), londim = 1, latdim = 2, mask = NULL) str(a) } - diff --git a/man/Subset.Rd b/man/Subset.Rd index 634cfe2..5d24310 100644 --- a/man/Subset.Rd +++ b/man/Subset.Rd @@ -31,4 +31,3 @@ data_subset <- Subset(data, c('time', 'model'), dim(data_subset) } - diff --git a/man/Threshold.Rd b/man/Threshold.Rd index cec12e6..a0fa10a 100644 --- a/man/Threshold.Rd +++ b/man/Threshold.Rd @@ -4,8 +4,15 @@ \alias{Threshold} \title{Daily thresholds based on quantiles for n-dimensional arrays} \usage{ -Threshold(data, dates = NULL, calendar = NULL, base.range = NULL, - qtiles = 0.9, ncores = NULL, na.rm = FALSE) +Threshold( + data, + dates = NULL, + calendar = NULL, + base.range = NULL, + qtiles = 0.9, + ncores = NULL, + na.rm = FALSE +) } \arguments{ \item{data}{A numeric n-dimensional array containing daily data.} @@ -42,4 +49,3 @@ attr(data, 'Variables')$dat1$time <- time a <- Threshold(data, dates = NULL, base.range = NULL, qtiles = 0.9, ncores = NULL) str(a) } - diff --git a/man/WaveDuration.Rd b/man/WaveDuration.Rd index b068252..a43c6b9 100644 --- a/man/WaveDuration.Rd +++ b/man/WaveDuration.Rd @@ -4,8 +4,16 @@ \alias{WaveDuration} \title{Heat and cold waves duration for n-dimensional arrays} \usage{ -WaveDuration(data, threshold, op = ">", spell.length = 6, - by.seasons = TRUE, dates = NULL, calendar = NULL, ncores = NULL) +WaveDuration( + data, + threshold, + op = ">", + spell.length = 6, + by.seasons = TRUE, + dates = NULL, + calendar = NULL, + ncores = NULL +) } \arguments{ \item{data}{A numeric n-dimensional array containing daily maximum or minimum temperature} @@ -48,4 +56,3 @@ threshold <- rep(40, 31) a <- WaveDuration(data, threshold, op = ">", spell.length = 6, by.seasons = TRUE, ncores = NULL) str(a) } - diff --git a/man/WeightedMean.Rd b/man/WeightedMean.Rd index 23f31c6..ac3411c 100644 --- a/man/WeightedMean.Rd +++ b/man/WeightedMean.Rd @@ -4,8 +4,15 @@ \alias{WeightedMean} \title{Calculate spatial area-weighted average of multidimensional arrays} \usage{ -WeightedMean(data, lon, lat, region = NULL, mask = NULL, londim = NULL, - latdim = NULL) +WeightedMean( + data, + lon, + lat, + region = NULL, + mask = NULL, + londim = NULL, + latdim = NULL +) } \arguments{ \item{data}{An array with minimum two dimensions of latitude and longitude.} @@ -60,4 +67,3 @@ a <- WeightedMean(data = data, lon = lon, lat = lat, region = NULL, mask = NULL, londim = 1, latdim = 2) str(a) } - -- GitLab