Dataset Cache Keys #459
GitHub Actions / JUnit Test Report - python 3.10, minimum dependencies
failed
Sep 19, 2024 in 0s
400 tests run, 397 passed, 1 skipped, 2 failed.
Annotations
Check failure on line 723 in tests/conventions/test_ugrid.py
github-actions / JUnit Test Report - python 3.10, minimum dependencies
test_ugrid.test_apply_clip_mask
ValueError: conflicting sizes for dimension 'nMesh2_edge': length 155 on 'Mesh2_edge_x' and length 18 on {'nMesh2_face': 'Mesh2_face_nodes', 'nMaxMesh2_face_nodes': 'Mesh2_face_nodes', 'nMesh2_edge': 'Mesh2_edge_nodes', 'Two': 'Mesh2_edge_nodes', 'nMesh2_node': 'Mesh2_node_x', 'Mesh2_layers': 'Mesh2_layers'}
Raw output
tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_apply_clip_mask2')
def test_apply_clip_mask(tmp_path):
dataset = make_dataset(width=5)
topology = Mesh2DTopology(dataset)
# Sketch this out and number the faces, edges, and nodes, if you want to verify
face_indexes = [20, 21, 22, 23, 24, 27, 28, 29]
edge_indexes = [25, 28, 36, 37, 38, 39, 40, 41, 42, 43, 44, 49, 50, 51, 52, 53, 54, 55]
node_indexes = [12, 13, 14, 17, 18, 19, 20, 23, 24, 25, 26]
# Clip it!
mask = mask_from_face_indexes(numpy.array(face_indexes), topology)
> clipped = dataset.ems.apply_clip_mask(mask, tmp_path)
tests/conventions/test_ugrid.py:723:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/emsarray/conventions/ugrid.py:1231: in apply_clip_mask
topology_dataset = xarray.Dataset(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/dataset.py:685: in __init__
variables, coord_names, dims, indexes, _ = merge_data_and_coords(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/dataset.py:416: in merge_data_and_coords
return merge_core(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/merge.py:723: in merge_core
dims = calculate_dimensions(variables)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
variables = {'Mesh2': <xarray.Variable ()>
array(nan)
Attributes:
cf_role: mesh_topology
long_name: ... -9.49588381, -10.25304833, -10.17416122])
Attributes:
long_name: Characteristic longitude value of a edge, ...}
def calculate_dimensions(variables: Mapping[Any, Variable]) -> dict[Hashable, int]:
"""Calculate the dimensions corresponding to a set of variables.
Returns dictionary mapping from dimension names to sizes. Raises ValueError
if any of the dimension sizes conflict.
"""
dims: dict[Hashable, int] = {}
last_used = {}
scalar_vars = {k for k, v in variables.items() if not v.dims}
for k, var in variables.items():
for dim, size in zip(var.dims, var.shape):
if dim in scalar_vars:
raise ValueError(
f"dimension {dim!r} already exists as a scalar variable"
)
if dim not in dims:
dims[dim] = size
last_used[dim] = k
elif dims[dim] != size:
> raise ValueError(
f"conflicting sizes for dimension {dim!r}: "
f"length {size} on {k!r} and length {dims[dim]} on {last_used!r}"
)
E ValueError: conflicting sizes for dimension 'nMesh2_edge': length 155 on 'Mesh2_edge_x' and length 18 on {'nMesh2_face': 'Mesh2_face_nodes', 'nMaxMesh2_face_nodes': 'Mesh2_face_nodes', 'nMesh2_edge': 'Mesh2_edge_nodes', 'Two': 'Mesh2_edge_nodes', 'nMesh2_node': 'Mesh2_node_x', 'Mesh2_layers': 'Mesh2_layers'}
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/variable.py:3257: ValueError
Check failure on line 797 in tests/conventions/test_ugrid.py
github-actions / JUnit Test Report - python 3.10, minimum dependencies
test_ugrid.test_make_and_apply_clip_mask
ValueError: conflicting sizes for dimension 'nMesh2_edge': length 155 on 'Mesh2_edge_x' and length 40 on {'nMesh2_face': 'Mesh2_face_nodes', 'nMaxMesh2_face_nodes': 'Mesh2_face_nodes', 'nMesh2_edge': 'Mesh2_edge_nodes', 'Two': 'Mesh2_edge_nodes', 'nMesh2_node': 'Mesh2_node_x', 'Mesh2_layers': 'Mesh2_layers'}
Raw output
tmp_path = PosixPath('/tmp/pytest-of-runner/pytest-0/test_make_and_apply_clip_mask0')
def test_make_and_apply_clip_mask(tmp_path):
dataset = make_dataset(width=5)
# When saving a dataset to disk, xarray.coding.times.cast_to_int_if_safe
# will check if it is possible to encode a timedelta64 using integer values
# by casting the values and checking for equality.
# Recent versions of numpy will emit warnings
# when casting a data array with dtype timedelta64 to int
# if it contains NaT (not a time) values.
# xarray will fix this eventually, but for now...
# See https://github.com/pydata/xarray/issues/7942
with filter_warning(
'ignore', category=RuntimeWarning,
message='invalid value encountered in cast',
module=r'xarray\.coding\.times',
):
dataset.ems.to_netcdf(tmp_path / "original.nc")
geometry.write_geojson(dataset, tmp_path / 'original.geojson')
polygon = Polygon([[3.4, 1], [3.4, -1], [6, -1], [6, 1], [3.4, 1]])
with open(tmp_path / 'clip.geojson', 'w') as f:
json.dump(geojson.Feature(geometry=polygon), f)
topology = dataset.ems.topology
# Make a clip mask
clip_mask = dataset.ems.make_clip_mask(polygon, buffer=1)
clip_mask.to_netcdf(tmp_path / "clip.nc")
assert clip_mask.sizes == {
'old_face_index': topology.face_count,
'old_edge_index': topology.edge_count,
'old_node_index': topology.node_count,
}
# Intersecting the clip polygon and the dataset geometry should have
# selected some faces. Open the geojson files that are generated in qgis
# and inspect the index attributes. This list is built from that.
face_indexes = [6, 7, 8, 11, 12, 13, 14, 15, 19, 20, 21, 22, 23, 24, 27, 28, 29, 32, 33, 34]
fill_value = topology.sensible_fill_value
new_face_indexes = numpy.ma.masked_array(
numpy.full(topology.face_count, fill_value, dtype=numpy.float64), mask=True)
new_face_indexes[face_indexes] = numpy.arange(len(face_indexes))
assert_equal(clip_mask.data_vars['new_face_index'].values, new_face_indexes)
# Apply the clip mask
work_dir = tmp_path / 'work_dir'
work_dir.mkdir()
> clipped = dataset.ems.apply_clip_mask(clip_mask, work_dir)
tests/conventions/test_ugrid.py:797:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/emsarray/conventions/ugrid.py:1231: in apply_clip_mask
topology_dataset = xarray.Dataset(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/dataset.py:685: in __init__
variables, coord_names, dims, indexes, _ = merge_data_and_coords(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/dataset.py:416: in merge_data_and_coords
return merge_core(
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/merge.py:723: in merge_core
dims = calculate_dimensions(variables)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
variables = {'Mesh2': <xarray.Variable ()>
array(nan)
Attributes:
cf_role: mesh_topology
long_name: ... -9.49588381, -10.25304833, -10.17416122])
Attributes:
long_name: Characteristic longitude value of a edge, ...}
def calculate_dimensions(variables: Mapping[Any, Variable]) -> dict[Hashable, int]:
"""Calculate the dimensions corresponding to a set of variables.
Returns dictionary mapping from dimension names to sizes. Raises ValueError
if any of the dimension sizes conflict.
"""
dims: dict[Hashable, int] = {}
last_used = {}
scalar_vars = {k for k, v in variables.items() if not v.dims}
for k, var in variables.items():
for dim, size in zip(var.dims, var.shape):
if dim in scalar_vars:
raise ValueError(
f"dimension {dim!r} already exists as a scalar variable"
)
if dim not in dims:
dims[dim] = size
last_used[dim] = k
elif dims[dim] != size:
> raise ValueError(
f"conflicting sizes for dimension {dim!r}: "
f"length {size} on {k!r} and length {dims[dim]} on {last_used!r}"
)
E ValueError: conflicting sizes for dimension 'nMesh2_edge': length 155 on 'Mesh2_edge_x' and length 40 on {'nMesh2_face': 'Mesh2_face_nodes', 'nMaxMesh2_face_nodes': 'Mesh2_face_nodes', 'nMesh2_edge': 'Mesh2_edge_nodes', 'Two': 'Mesh2_edge_nodes', 'nMesh2_node': 'Mesh2_node_x', 'Mesh2_layers': 'Mesh2_layers'}
/usr/share/miniconda/envs/test/lib/python3.10/site-packages/xarray/core/variable.py:3257: ValueError
Loading