Skip to content

Commit

Permalink
Fix reading arrays without grids
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
ZedThree committed Oct 17, 2024
1 parent 10e8a9d commit f684c3d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/sdf_xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,18 @@ def _grid_species_name(grid_name: str) -> str:
continue

if isinstance(value, Constant) or value.grid is None:
# No grid, so just a scalar
data_attrs = {}
if value.units is not None:
data_attrs["units"] = value.units

data_vars[key] = Variable((), value.data, data_attrs)
# We don't have a grid, either because it's just a
# scalar, or because it's an array over something
# else. We have no more information, so just make up
# some (hopefully) unique dimension names
shape = getattr(value.data, "shape", ())
dims = [f"dim_{key}_{n}" for n, _ in enumerate(shape)]

data_vars[key] = Variable(dims, value.data, attrs=data_attrs)
continue

if value.is_point_data:
Expand Down

0 comments on commit f684c3d

Please sign in to comment.