Skip to content

Accept flat or grid shape grid data inputs #235

@mjreno

Description

@mjreno

Note this behavior is likely expected, this issue was created to ask the question if grid shaped arrays should be tolerated when dfn shape is nodes.

Version: Commit d50342f
Recreate:

  • First, update test_component.py quickstart test IC package as below:
strt = np.full((1, 10, 10), 1.0, dtype=float)
strt = strt.flatten()
ic = Ic(parent=gwf, strt=strt)
  • Run test, succeeds as expected
  • Now, update IC as below:
strt = np.full((1, 10, 10), 1.0, dtype=float)
#strt = strt.flatten()
ic = Ic(parent=gwf, strt=strt)

Result:

    def _resolve_array(
        xat: Xattribute, value: ArrayLike, strict: bool = False, **dims
    ) -> Optional[NDArray]:
        dims = dims or {}
        match xat:
            case Coord():
                if xat.default is None or not isinstance(xat.default, Scalar):
                    raise CannotExpand(
                        f"Class '{cls_name}' coord array '{xat.name}'"
                        f"paired with dim '{xat.name}' can't expand "
                        f"without a scalar default dimension size."
                    )
                return chexpand(value, (xat.default,))
            case Array():
                shape = tuple([dims.pop(dim, dim) for dim in (xat.dims or [])])
                unresolved = [dim for dim in shape if not isinstance(dim, int)]
                if strict and any(unresolved):
                    raise DimsNotFound(
                        f"Class '{cls_name}' array '{xat.name}' "
                        f"failed dim resolution: {', '.join(unresolved)}"
                    )
                if value is None or isinstance(value, str) or not isinstance(value, Iterable):
                    if xat.dims is None:
                        raise CannotExpand(
                            f"Class '{cls_name}' array '{xat.name}' can't expand "
                            "without explicit dimensions or a non-scalar default."
                        )
                    value = value if value is not None else xat.default  # type: ignore
                    if value is None:
                        return None  # type: ignore
                    return None if any(unresolved) else chexpand(value, shape)
                value = np.array(value)
                if xat.dims and value.ndim != len(shape):
>                   raise ValueError(
                        f"Class '{cls_name}' array '{xat.name}' "
                        f"expected {len(shape)} dims, got {value.ndim}"
                    )
E                   ValueError: Class 'Ic' array 'strt' expected 1 dims, got 3

../.pixi/envs/dev/lib/python3.11/site-packages/xattree/__init__.py:901: ValueError

Metadata

Metadata

Assignees

No one assigned

    Labels

    frontendRelated to the user-facing APIquestionInformation or decisions requiredrequirementCore requirement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions