-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
Description
import scipp as sc
dim='x'
midpoint = sc.vectors(values=[[0.5, 0.5, 0.5], [1.5, 1.5, 1.5]], dims=[dim], unit='m')
ok_vector_edged = sc.DataArray(data=sc.scalar(1), coords={dim: midpoint})
try:
ok_vector_edged.coords.is_edges(dim)
except sc.DimensionError:
raise RuntimeError("This should not be triggered")
not_ok_vector_edged = sc.DataArray(
data=sc.array(values=[[1]], dims=['x', 'y'], unit='V'),
coords={
dim: midpoint,
'y': sc.array(values=[2], dims=['y'], unit='s'),
'z': sc.vectors(values=[[[0,1,2],[3,4,5]]], dims=['y', dim], unit='m'),
})
try:
not_ok_vector_edged.coords.is_edges('z')
except sc.DimensionError as er:
print(f'Failed identifying {dim} as an edges dimension when checking "z", with somewhat cryptic message `{er}`')The first try block above succeeded without error, but the second raises causing the following output on my machine:
Failed identifying x as an edges dimension when checking "z", with somewhat cryptic message `Expected 1 dimensions, got 2`The following alternative seems to work for vector valued edge coordinates, but I can't claim that I've tested it extensively.
(Maybe it's actually missing the case where, e.g. 'x' itself isn't present or isn't edges but 'z' is.)
def vector_safe_is_edges(x: DataArray, dim: str) -> bool:
from scipp import DType
if x.coords[dim].dtype != DType.vector3:
return x.coords.is_edges(dim)
return x.coords[dim].sizes[dim] == x.sizes[dim] + 1Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done