pik-piam / magclass

R package | Data Class and Tools for Handling Spatial-Temporal Data
GNU Lesser General Public License v3.0
4 stars 24 forks source link

Unexpected behavior of magpie_expand #166

Closed orichters closed 7 months ago

orichters commented 7 months ago
library(magclass)
t <- c(1995, 2005, 2015)
s <- c('AFR', 'CPA')
A <- dimSums(maxample('pop')[s,t,'A2'], 3)
B <- dimSums(maxample('pop')[s,t[-2],'B1'], 3)
> A
An object of class "magpie"
, , 1

     t
i         y1995   y2005   y2015
  AFR  552.6664  696.44  889.18
  CPA 1280.6350 1429.53 1518.46

> B
An object of class "magpie"
, , 1

     t
i         y1995   y2015
  AFR  552.6664  932.04
  CPA 1280.6350 1499.74

Now, running magpie_expand on B with A as ref:

magpie_expand(B, A)
An object of class "magpie"
, , 1

     t.t1
i     y1995.y1995 y1995.y2015 y2005.y1995 y2005.y2015 y2015.y1995 y2015.y2015
  AFR    552.6664      932.04    552.6664      932.04    552.6664      932.04
  CPA   1280.6350     1499.74   1280.6350     1499.74   1280.6350     1499.74

That is not how I understand the function, I would have expected something with the dimension of A

Digging into the code, it seems that magclass:::magpie_expand_dim(B, A, dim = 2) shows this error, so I guess the problem is somewhere here: Before this line, the object are defined as follows:

> lx
$t
[1] "y1995" "y2015"

> lref
$t
[1] "y1995" "y2005" "y2015"

> match(lx, lref)
NA

So it cannot match anything. Unclear whether that is intended.

tscheypidi commented 7 months ago

This is the intended behavior. The time dimensions have different elements, hence they are treated as different dimensions.