Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • CSTools CSTools
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 28
    • Issues 28
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • External
  • CSToolsCSTools
  • Merge requests
  • !160

Correct bug in CST_Subset when a coordinate element is a multidimensional array

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Eva Rifà requested to merge hotfix_v5.0.0_CST_Subset into master Apr 04, 2023
  • Overview 2
  • Commits 1
  • Pipelines 1
  • Changes 2

There was a bug when the function was subsetting a coordinate with multiple dimensions. Example code:

library(StartR)
library(ClimProjDiags)
library(s2dv)

repos <- "/esarchive/exp/ecmwf/system5_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc"
repos2 <- "/esarchive/exp/ecmwf/system4_m1/monthly_mean/$var$_f6h/$var$_$sdate$.nc"

data3 <- Start(dat = list(list(name = 'system4_m1', path = repos2),
                          list(name = 'system5_m1', path = repos)),
              var = c('tas', 'sfcWind'),
              sdate = '20170101',
              ensemble = indices(1),
              time = indices(1:3),
              lat = indices(1:4),
              lon = indices(1:4),
              synonims = list(lat = c('lat', 'latitude'),
                              lon = c('lon', 'longitude')),
              return_vars =  list(time = 'sdate',
                                  longitude = 'dat',
                                  latitude = 'dat'),
              metadata_dims = c('dat', 'var'),
              retrieve = T
              )
exp_start <- as.s2dv_cube(data3)

source("https://earth.bsc.es/gitlab/external/cstools/-/raw/master/R/CST_Subset.R")

exp_sub1 <- CST_Subset(exp_start,
                       along = c("dat", "lon", 'time', 'var'),
                       indices = list(1, 1:2, 1:2, 1),
                       dat_dim = 'dat', 
                       var_dim = 'var',
                       drop = 'non-selected')
# Error in names(dim(l)) <- x.dims : 
# 'names' attribute [2] must be the same length as the vector [1]

The error was found in function: .subset_with_attrs. This was due to time coordinate having dimensions: sdate = 1, time = N.

Now, if the coordinate to subset has more than 1 dimension the function Subset is used directly. The changed part is in these lines and the same here.

@vagudets do you agree with this change?

Edited Apr 04, 2023 by Eva Rifà
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: hotfix_v5.0.0_CST_Subset