Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • CSIndicators CSIndicators
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Graph
    • Compare revisions
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Terraform modules
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Earth SciencesEarth Sciences
  • CSIndicatorsCSIndicators
  • Issues
  • #29
Closed
Open
Issue created May 18, 2023 by Eva Rifà@erifarovMaintainer

Remove ClimProjDiags and s2dv dependency

Hi @aho,

I open this issue in order to bring up some ideas to temporary remove Subset dependency from packages.

In this package there are 2 functions that use ClimProjDiags::Subset:

  • QThreshold: line 210
  • SelectPeriodOnData: line 154

Here there are 3 examples with possible options to subset data in a similar way that Subset from ClimProjDiags does:

Options to subset data

# example array to subset
res <- array(1:12, dim = c(a = 2, b = 2, c = 3, d = 1))
dim_remove <- c('a', 'b')
  1. Add an auxiliary function that has some code lines from Subset
# Option 1: Add an auxiliary function that has some code lines from Subset
index_array <- function(x, dim, value, drop = FALSE) { 
  indices <- rep(list(bquote()), length(dim(x)))
  dims <- which(names(dim(x)) %in% dim)
  indices[dims] <- value
  call <- as.call(c(list(as.name("["), quote(x)), indices, list(drop = drop)))
  eval(call)
}

res1 <- index_array(res, dim = dim_remove, value = 1)

dim(res1)
# a b c d 
# 1 1 3 1 
  1. Use multiApply
# Option 2: multiApply
res2 <- array(1:12, dim = c(a = 2, b = 2, c = 3, d = 1))
dims <- dim(res2)
for (dimi in dim_remove) {
  res2 <- Apply(res2, target_dims = dimi, fun = function(x) {
                                            x <- x[1]
                                            })$output1
}
dim(res2) <- c(dim(res2), rep(1, length(dim_remove)))
names(dim(res2)) <- c(names(dims)[-which(names(dims) %in% dim_remove)], dim_remove)

dim(res2)
# c d a b 
# 3 1 1 1 
  1. Use external function abind
# Option 3: abind
res <- array(1:12,dim=c(a = 2, b = 2, c = 3, d = 1),
            dimnames=list(letters[1:2],LETTERS[1:2],letters[1:3], letters[1]))
library(abind)
res3 <- asub(res, list(1), c(1), drop=FALSE)
res3 <- asub(res3, list(1), c(2), drop=FALSE)

dim(res3)
# a b c d 
# 1 1 3 1 

Development

In branch: develop-remove_Subset !42 (merged) the sustitution has been made for Option 1. I have chosen this option because it doesn't require to load external packages and I think it's more efficient than the multiApply option. Also, there may be other options that I haven't think about it.

Best,
Eva

Edited May 18, 2023 by Eva Rifà
Assignee
Assign to
Time tracking