File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -804,12 +804,15 @@ def isel(
804
804
spatial_axis = axis - 1 if self .dims [0 ] == "time" else axis
805
805
geometry = self .geometry .isel (idx , axis = spatial_axis )
806
806
807
- # TODO this is ugly
808
807
if isinstance (geometry , _GeometryFMLayered ):
809
808
node_ids , _ = self .geometry ._get_nodes_and_table_for_elements (
810
809
idx , node_layers = "all"
811
810
)
812
- zn = self ._zn [:, node_ids ] # type: ignore
811
+ assert isinstance (self ._zn , np .ndarray )
812
+ if self ._zn .ndim == 2 :
813
+ zn = self ._zn [:, node_ids ]
814
+ else :
815
+ zn = self ._zn [node_ids ]
813
816
814
817
# reduce dims only if singleton idx
815
818
dims = (
Original file line number Diff line number Diff line change @@ -206,19 +206,18 @@ def _get_nodes_and_table_for_elements(
206
206
207
207
"""
208
208
elem_tbl = np .empty (len (elements ), dtype = np .dtype ("O" ))
209
- if ( node_layers == "all" ) or self . is_2d :
209
+ if node_layers == "all" :
210
210
for j , eid in enumerate (elements ):
211
- elem_tbl [j ] = np . asarray ( self .element_table [eid ])
211
+ elem_tbl [j ] = self .element_table [eid ]
212
212
213
213
else :
214
214
# 3D => 2D
215
215
for j , eid in enumerate (elements ):
216
- elem_nodes = np .asarray (self .element_table [eid ])
217
- nn = len (elem_nodes )
218
- halfn = int (nn / 2 )
216
+ elem_nodes = self .element_table [eid ]
217
+ halfn = len (elem_nodes ) // 2
219
218
if node_layers == "bottom" :
220
219
elem_nodes = elem_nodes [:halfn ]
221
- if node_layers == "top" :
220
+ elif node_layers == "top" :
222
221
elem_nodes = elem_nodes [halfn :]
223
222
elem_tbl [j ] = elem_nodes
224
223
Original file line number Diff line number Diff line change @@ -662,3 +662,14 @@ def test_write_3d_non_equidistant(tmp_path: Path) -> None:
662
662
663
663
# but getting the end time is not that expensive
664
664
assert dfs .end_time == pd .Timestamp ("2000-01-10" )
665
+
666
+
667
+ def test_isel_3d_single_time () -> None :
668
+ ds = mikeio .Dfsu3D ("tests/testdata/basin_3d.dfsu" ).read ()
669
+ ds1 = ds .isel (element = [0 , 1 ])
670
+ assert ds1 .geometry .n_elements == 2
671
+
672
+ ds2 = ds .isel (time = - 1 )
673
+ assert "time" not in ds2 .dims
674
+ ds3 = ds2 .isel (element = [0 , 1 ])
675
+ assert ds3 .geometry .n_elements == 2
You can’t perform that action at this time.
0 commit comments