From bbbdf679ce00c537b2072dca6401909b1df5fe11 Mon Sep 17 00:00:00 2001 From: Emily Browning Date: Tue, 18 Nov 2025 13:29:47 -0900 Subject: [PATCH 1/2] begin to add xarray capability and add new variables in coords --- mhkit/river/io/d3d.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mhkit/river/io/d3d.py b/mhkit/river/io/d3d.py index 7295d7e11..b4c854264 100644 --- a/mhkit/river/io/d3d.py +++ b/mhkit/river/io/d3d.py @@ -35,8 +35,8 @@ def get_all_time(data: netCDF4.Dataset) -> NDArray: simulation conditions at that time. """ - if not isinstance(data, netCDF4.Dataset): - raise TypeError("data must be a NetCDF4 object") + if not isinstance(data, (netCDF4.Dataset, xr.Dataset)): + raise TypeError("data must be a NetCDF4 object or xarray Dataset") seconds_run = np.ma.getdata(data.variables["time"][:], False) @@ -244,6 +244,10 @@ def get_layer_data( "name": "mesh2d_nLayers", "coords": data.variables["mesh2d_layer_sigma"][:], }, + "mesh2d_face_x mesh2d_face_y mesh2d_layer_sigma": { + "name": "mesh2d_nLayers", + "coords": data.variables["mesh2d_layer_sigma"][:], + }, "mesh2d_edge_x mesh2d_edge_y": { "name": "mesh2d_nInterfaces", "coords": data.variables["mesh2d_interface_sigma"][:], @@ -637,6 +641,10 @@ def get_all_data_points( "name": "mesh2d_nLayers", "coords": data.variables["mesh2d_layer_sigma"][:], }, + "mesh2d_face_x mesh2d_face_y mesh2d_layer_sigma": { + "name": "mesh2d_nLayers", + "coords": data.variables["mesh2d_layer_sigma"][:], + }, "mesh2d_edge_x mesh2d_edge_y": { "name": "mesh2d_nInterfaces", "coords": data.variables["mesh2d_interface_sigma"][:], From bb27980efaa51deaed38c850db6b0186ba3cea21 Mon Sep 17 00:00:00 2001 From: Emily Browning Date: Wed, 19 Nov 2025 10:18:15 -0900 Subject: [PATCH 2/2] fix waterdepth name --- mhkit/river/io/d3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mhkit/river/io/d3d.py b/mhkit/river/io/d3d.py index b4c854264..f0491e69d 100644 --- a/mhkit/river/io/d3d.py +++ b/mhkit/river/io/d3d.py @@ -257,7 +257,7 @@ def get_layer_data( data.variables["mesh2d_waterdepth"][time_index, :], False ) waterlevel = np.ma.getdata(data.variables["mesh2d_s1"][time_index, :], False) - coords = str(data.variables["waterdepth"].coordinates).split() + coords = str(data.variables["mesh2d_waterdepth"].coordinates).split() elif str(data.variables[variable].coordinates) == "FlowElem_xcc FlowElem_ycc": cords_to_layers = {