File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -387,6 +387,22 @@ def test_assign_ugrid_topology_start_index_zero_infer():
387387 assert ds ["mesh_edge_nodes" ].attrs ["start_index" ] == 0
388388 assert ds ["mesh_boundary_nodes" ].attrs ["start_index" ] == 0
389389
390+ def test_assign_ugrid_topology_start_index_zero_infer_bad_data ():
391+ """
392+ if the connectivity array has negative or no zero or one indexes -- not good.
393+ """
394+ # set a negative index
395+ ds = xr .open_dataset (EXAMPLE_DATA / "small_ugrid_zero_based.nc" )
396+ faces = ds ['mesh_face_nodes' ].data [0 , 0 ] = - 3
397+ with pytest .raises (ValueError ):
398+ ds = ugrid .assign_ugrid_topology (ds , face_node_connectivity = "mesh_face_nodes" )
399+
400+ # remove zero and one indexes
401+ data = ds ['mesh_face_nodes' ].data
402+ data [data < 2 ] = 100
403+ with pytest .raises (ValueError ):
404+ ds = ugrid .assign_ugrid_topology (ds , face_node_connectivity = "mesh_face_nodes" )
405+
390406
391407# NOTE: these tests are probably not complete -- but they are something.
392408# we really should have a complete UGRID example to test with.
Original file line number Diff line number Diff line change @@ -464,8 +464,12 @@ def assign_ugrid_topology(
464464 mapping = [(dim , ds [dim ].size ) for dim in dims ]
465465 mesh .face_dimension = next (x [0 ] for x in mapping if x [1 ] != 3 and x [1 ] != 4 )
466466
467- # check for start_index, and set it if there.
467+ # check for start_index, and set it not there.
468468 if mesh .start_index is None :
469+ start_index = int (ds [mesh .face_node_connectivity ].min ())
470+ if start_index not in (0 , 1 ):
471+ raise ValueError (f"minimum index in face_node_connectivity array is { start_index } "
472+ " -- it should be zero (C-style indexing) or 1 (Fortran-style indexing)" )
469473 mesh .start_index = int (ds [mesh .face_node_connectivity ].min ())
470474
471475 if mesh .start_index not in (0 , 1 ):
You can’t perform that action at this time.
0 commit comments