Skip to content

CST_BindDim concatenates s2dv_cube objects if a time dimension is selected

Hi @vagudets and @tkariyat,

R and packages Version

Using R version 4.4.1 in hub 06

Summary

When calling to the CST_BindDim function and trying to bind two s2dv_cube objects along any time dimension (time, sdate, syear, sweek...), the function concatenates both objects, instead of ordering the dates properly.

Example

I include here a small script to reproduce the issue, loading two simple s2dv_cube objects with SUNSET and then calling on the function.

setwd("/esarchive/scratch/jcorvill/gitlab/sunset/")
# Load modules
source("modules/Loading/Loading.R")

# Read recipe (2000-2002 monthly mean temperature data for January)
recipe_file <- "/esarchive/scratch/jcorvill/recipe_sre_1.yml"
recipe <- prepare_outputs(recipe_file)

# Load datasets
datasets <- Loading(recipe)

# Obtain the observations for this dataset
obs_1 <- datasets$obs
dates_1 <- datasets$obs$attrs$Dates

# Read recipe (2000-2002 monthly mean temperature data for February)
recipe_file <- "/esarchive/scratch/jcorvill/recipe_sre_2.yml"
recipe <- prepare_outputs(recipe_file)

# Load datasets
datasets <- Loading(recipe)

# Obtain the observations for this dataset
obs_2 <- datasets$obs
dates_2 <- datasets$obs$attrs$Dates

# Source the BindDim function from the CSTools package:
source("/esarchive/scratch/jcorvill/gitlab/cstools/R/CST_BindDim.R")

result <- CST_BindDim(x = list(obs_1, obs_2),
                            along = "syear", dat_dim = "dat", var_dim = "var")

# Here, the Dates attribute is concatenated, not ordered correctly
result_dates <- result$attrs$Dates

I tried to come up with a fix for this issue separately. Following the example, the expected behavior is then reproduced

# Source the BindDim function with the fix:
source("/esarchive/scratch/jcorvill/rscripts/CST_BindDim_fix.R")

result_fix <- CST_BindDim(x = list(obs_1, obs_2),
                                along = "syear", dat_dim = "dat", var_dim = "var")

# Here, the Dates attribute is correctly ordered
result_fix_dates <- result_fix$attrs$Dates

If need be, I can create a new branch with the fix. Let me know if this works well for you!

Javier

(P.S. Tagging @nperez and @vtorralba so that they can follow the discussion as well)