Skip to content

Confused by cat behaviour #973

@alex-s-gardner

Description

@alex-s-gardner

I want to calculate the monthly mean of a 2D DimArray (DateTime by X) and produce a resulting 2D DimArray with dimensions of integer month and X

Create a DimArray with dimensions DataTime and x

using DimensionalData, Dates, Statistics
dTi = Ti(collect(Date(2000,1,1):Day(1):Date(2024,10,1)));
dX = X(collect(1:10));
da = rand(dTi,dX);

group by month and calculate mean

gda = groupby(da, dTi => Bins(month, 1:12));
gda = mean.(gda; dims=Ti);

now comes the part I don't get.

try dropping the DataTime dimension then concatenating

foo2 = dropdims.(gda; dims=Ti);
foo = cat(foo2...; dims=Ti)

somehow DateTime is still there. How did that happen? I explicitly dropped this dim.

┌ 10×12 DimArray{Float64, 2} ┐
├────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────── dims ┐
  ↓ X  Sampled{Int64} [1, 2, …, 9, 10] ForwardOrdered Irregular Points,
  → Ti Sampled{Date} [2012-01-16, …, 2012-12-01] ForwardOrdered Irregular Points
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  ↓ →   2012-01-16   2012-02-15   2012-03-16  …   2012-10-01   2012-11-01   2012-12-01
  1    0.492005             0.504026             0.494869                0.495121             0.513776             0.507932
  2    0.496965             0.493398             0.51959                 0.487964             0.490996             0.499451
  3    0.488379             0.496261             0.507665                0.481631             0.534441             0.495114
  ⋮                                                                   ⋱  ⋮                                         
  8    0.487388             0.49639              0.514814                0.495875             0.504643             0.492865
  9    0.495462             0.491538             0.492786                0.501266             0.501263             0.504023
 10    0.506875             0.481782             0.500255             …  0.49605              0.51212              0.492466

How can I combine the grouped DimArray to give me a DimArray that inherits the Ti dimension from the groups of the the grouped DimArray such that:

↓ Ti Sampled{Int64} 1:12 ForwardOrdered Regular Points

I can get what I want doing the following:

foo = cat(foo2...; dims=dims(foo2, :Ti))

but it seems cumbersome that cat is not able to inherit the dimension from the groups... which makes me think that I'm not doing this correctly. I looked for a combine function by couldn't find one

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions