Skip to content

Commit

Permalink
made test_open_2Dnetwork_with_1Dtopology
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Feb 4, 2025
1 parent b4bf4eb commit eb950d0
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/test_xugrid_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,24 @@ def test_uds_auto_set_crs_spherical():
assert uds.grid.is_geographic is True


@pytest.mark.requireslocaldata
@pytest.mark.unittest
def test_open_2Dnetwork_with_1Dtopology():
file_nc = r'p:\1204257-dcsmzuno\2006-2012\3D-DCSM-FM\A18b_ntsu1\DCSM-FM_0_5nm_grid_20191202_depth_20181213_net.nc'
uds = dfmt.open_partitioned_dataset(file_nc)
def test_open_2Dnetwork_with_1Dtopology(tmp_path):
file_nc = dfmt.data.fm_grevelingen_map(return_filepath=True).replace('0*','0002')

# save as new network with only the 1D information in the mesh_topology
mesh1d_attrs = {'cf_role': 'mesh_topology',
'long_name': 'Topology data of 1D network',
'topology_dimension': 1,
'node_coordinates': 'mesh2d_node_x mesh2d_node_y',
'node_dimension': 'nmesh2d_node',
'edge_node_connectivity': 'mesh2d_edge_nodes',
'edge_dimension': 'nmesh2d_edge'}
ds = xr.open_dataset(file_nc, decode_cf=False, decode_times=False, decode_coords=False)
ds['mesh2d'] = ds['mesh2d'].assign_attrs(mesh1d_attrs)
file_nc_out = os.path.join(tmp_path, "network_1d_net.nc")
ds.to_netcdf(file_nc_out)

uds = dfmt.open_partitioned_dataset(file_nc_out)
assert isinstance(uds.grid, xu.ugrid.ugrid1d.Ugrid1d)
assert not hasattr(uds.grid, "face_node_connectivity")

Expand All @@ -129,7 +142,7 @@ def test_open_2Dnetwork_with_1Dtopology():
# test projected attr, xugrid automatically sets standard_name
# based on projected property
node_x = uds_withcellinfo.grid.to_dataset().mesh2d_node_x
assert node_x.attrs['standard_name'] == "longitude"
assert node_x.attrs['standard_name'] == "projection_x_coordinate"


@pytest.mark.unittest
Expand Down

0 comments on commit eb950d0

Please sign in to comment.