File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -419,6 +419,22 @@ def test_assign_ugrid_topology_start_index_zero_infer():
419419 assert ds ["mesh_edge_nodes" ].attrs ["start_index" ] == 0
420420 assert ds ["mesh_boundary_nodes" ].attrs ["start_index" ] == 0
421421
422+ def test_assign_ugrid_topology_start_index_zero_infer_bad_data ():
423+ """
424+ if the connectivity array has negative or no zero or one indexes -- not good.
425+ """
426+ # set a negative index
427+ ds = xr .open_dataset (EXAMPLE_DATA / "small_ugrid_zero_based.nc" )
428+ faces = ds ['mesh_face_nodes' ].data [0 , 0 ] = - 3
429+ with pytest .raises (ValueError ):
430+ ds = ugrid .assign_ugrid_topology (ds , face_node_connectivity = "mesh_face_nodes" )
431+
432+ # remove zero and one indexes
433+ data = ds ['mesh_face_nodes' ].data
434+ data [data < 2 ] = 100
435+ with pytest .raises (ValueError ):
436+ ds = ugrid .assign_ugrid_topology (ds , face_node_connectivity = "mesh_face_nodes" )
437+
422438
423439# NOTE: these tests are probably not complete -- but they are something.
424440# 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