Skip to content

Deduce shape from coordinates #239

@Alexsaphir

Description

@Alexsaphir

Would it be possible for a dataclass AsDataArray to deduce the shape of the Data from the coordinates, ie:

@dataclass
class Image(AsDataArray):
    """2D image as DataArray."""

    x: Coord[X, int]
    y: Coord[Y, int] 

    data: Data[tuple[X, Y], float]

In this case, the coordinates are not optional.

To do that, the classmethod shaped should allow shape to be optional, and use the shape from the kwargs.
(Could extends the case where shape is a dict and fallback to the value specified in the dict)

        if isinstance(shape, None):
            shape = tuple(kwargs[dim].size for dim in entry.dims)

Happy to open a PR, if you want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions