Skip to content

Multiple coordinates for one dimension #295

@aurelije

Description

@aurelije

Hi people, I am currently struggling with xarray and linopy.

I have a dimension A whose coordinates can be grouped. For me it was natural to have a dimension A with coordinates for A but also coordinate B that is built on dimension A and then swap dimensions but I failed to do it.

So here is an example.
dimension A has coordinates: [1, 2, 3, 4, 5, 6] but coordinates [1, 2, 3] belong to group 311 and rest of them to group 322. I would like to create constraints based on those 2 groups.

I have a variable with this situation:

var.coords
Coordinates:
   * A (A) int64 48B 1 2 3 4 5 6
     B (A) int64 48B 311 311 311 322 322 322

Looking at xarray docs this may be the way var.swap_dims({'A': 'B'}) and then I can do sum on other dimensions and set constraint for groups. But Variable doesn't have that method.

Next I tried with groupby on B, I got correct groups but then sum on groupby expression will throw an error that B is already present...

In the end I made B full dimension (I am breaking normalization from Databases theory :D) but looks like suboptimal solution and I have this kind of case for multiple coordinates so instead of having small dimensional case of 7 dimensions I will end with at least 9

Could I do something better?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions