From ed64097d79be118d8518eb1ce085156647ace8ca Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 16 May 2024 14:27:42 +0200 Subject: [PATCH 1/5] Iterate over names instead of length when correcting 'sub_array_of_indices_by_file' --- R/Start.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Start.R b/R/Start.R index 2be297b..98b2df3 100644 --- a/R/Start.R +++ b/R/Start.R @@ -3279,8 +3279,8 @@ Start <- function(..., # dim = indices/selectors, indices_chunk <- c(indices_chunk, rep(item, length(tmp) - length(indices_chunk))) } sub_array_of_indices_by_file <- split(sub_array_of_indices, indices_chunk) - for (item in 2:length(sub_array_of_indices_by_file)) { - sub_array_of_indices_by_file[[item]] <- sub_array_of_indices_by_file[[item]] - cumsum(inner_dim_lengths)[item - 1] + for (item in names(sub_array_of_indices_by_file)) { + sub_array_of_indices_by_file[[item]] <- sub_array_of_indices_by_file[[item]] - cumsum(inner_dim_lengths)[as.numeric(item) - 1] } transformed_indices <- unlist(sub_array_of_indices_by_file, use.names = FALSE) } -- GitLab From 7dc8481330c110870b83ca11bbd633ddc6196415 Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 16 May 2024 16:22:02 +0200 Subject: [PATCH 2/5] Run unit tests on gitlab --- .Rbuildignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index aa7059a..39771b3 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,7 +9,7 @@ ^inst/doc$ ^\.gitlab-ci\.yml$ ## unit tests should be ignored when building the package for CRAN -^tests$ +# ^tests$ ^inst/PlotProfiling\.R$ ^.gitlab$ # Suggested by http://r-pkgs.had.co.nz/package.html -- GitLab From c3706ecab5e8e28937c36f7989bd012daa64cb3b Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Fri, 17 May 2024 10:39:30 +0200 Subject: [PATCH 3/5] Do not apply sub_array_of_indices_by_file correction if item is 1 --- R/Start.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/Start.R b/R/Start.R index 98b2df3..42f72b6 100644 --- a/R/Start.R +++ b/R/Start.R @@ -3279,8 +3279,11 @@ Start <- function(..., # dim = indices/selectors, indices_chunk <- c(indices_chunk, rep(item, length(tmp) - length(indices_chunk))) } sub_array_of_indices_by_file <- split(sub_array_of_indices, indices_chunk) - for (item in names(sub_array_of_indices_by_file)) { - sub_array_of_indices_by_file[[item]] <- sub_array_of_indices_by_file[[item]] - cumsum(inner_dim_lengths)[as.numeric(item) - 1] + for (item in names((sub_array_of_indices_by_file))) { + # If item is 1, cumsum(inner_dim_lengths)[item - 1] returns numeric(0) + if (as.numeric(item) > 1) { + sub_array_of_indices_by_file[[item]] <- sub_array_of_indices_by_file[[item]] - cumsum(inner_dim_lengths)[as.numeric(item) - 1] + } } transformed_indices <- unlist(sub_array_of_indices_by_file, use.names = FALSE) } -- GitLab From c3b2b7abbf8028af409566c12dd3df88bbcb55e9 Mon Sep 17 00:00:00 2001 From: vagudets Date: Mon, 8 Jul 2024 12:56:29 +0200 Subject: [PATCH 4/5] Add unit test for across + depends when largest_dims_length = TRUE --- ...-DCPP-across-depends-largest_dims_length.R | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R diff --git a/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R b/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R new file mode 100644 index 0000000..f873bca --- /dev/null +++ b/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R @@ -0,0 +1,61 @@ +suppressMessages({ +test_that("Chunks of DCPP files with largest_dims_length = TRUE - Local execution", { + path <- '/esarchive/exp/CMIP6/dcppA-hindcast/HadGEM3-GC31-MM/DCPP/MOHC/HadGEM3-GC31-MM/dcppA-hindcast/r1i1p1f2/Omon/tos/gn/v20200417/$var$_Omon_HadGEM3-GC31-MM_dcppA-hindcast_s$sdate$-r1i1p1f2_gn_$chunk$.nc' + path <- paste0('/esarchive/scratch/aho/startR_unittest_files/', path) + + sdates <- c('2017', '2018') +suppressWarnings( + dat1 <- Start(dat = path, + var = 'tos', + sdate = sdates, + chunk = 'all', + chunk_depends = 'sdate', + time = indices(1:15), + i = indices(1:10), + j = indices(1:10), + time_across = 'chunk', + merge_across_dims = TRUE, + largest_dims_length = TRUE, + retrieve = TRUE, + return_vars = list(time = 'sdate')) +) + +# Start at chunk 2 (skip time steps in the first file) +suppressWarnings( + dat2 <- Start(dat = path, + var = 'tos', + sdate = sdates, + chunk = 'all', + chunk_depends = 'sdate', + time = indices(3:15), + i = indices(1:10), + j = indices(1:10), + time_across = 'chunk', + merge_across_dims = TRUE, + largest_dims_length = TRUE, + retrieve = TRUE, + return_vars = list(time = 'sdate')) +) + +expect_equal(dat1[1, 1, 1:2, 3:15, 10, 10], dat2[1, 1, 1:2, , 10, 10]) + +# Start at chunk 3 (skip time steps in the first and second files) +suppressWarnings( + dat3 <- Start(dat = path, + var = 'tos', + sdate = sdates, + chunk = 'all', + chunk_depends = 'sdate', + time = indices(15), + i = indices(1:10), + j = indices(1:10), + time_across = 'chunk', + merge_across_dims = TRUE, + largest_dims_length = TRUE, + retrieve = TRUE, + return_vars = list(time = 'sdate')) +) + +expect_equal(dat1[1, 1, 1:2, 15, 10, 10], dat3[1, 1, 1:2, , 10, 10]) + +}) #suppressMessages -- GitLab From 3964bc38dc72c53e214d402b8c233cde0effc6bf Mon Sep 17 00:00:00 2001 From: vagudets Date: Mon, 8 Jul 2024 14:13:18 +0200 Subject: [PATCH 5/5] Fix pipeline --- .../test-Start-DCPP-across-depends-largest_dims_length.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R b/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R index f873bca..3e10c55 100644 --- a/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R +++ b/tests/testthat/test-Start-DCPP-across-depends-largest_dims_length.R @@ -58,4 +58,6 @@ suppressWarnings( expect_equal(dat1[1, 1, 1:2, 15, 10, 10], dat3[1, 1, 1:2, , 10, 10]) +}) + }) #suppressMessages -- GitLab