Skip to content

Commit b7466e7

Browse files
committed
Add final_time accessor
This returns the final time slice of a dataset or dataarray, whether the data contains multiple time slices or not. This is helpful when working with multiple simulations, some of which may have only been run for one timestep for developer reasons.
1 parent cb87f23 commit b7466e7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

xbout/boutdataarray.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,3 +1169,13 @@ def as_cherab_emitter(
11691169
cylinder_rmax=cyliner_rmax,
11701170
step=step,
11711171
)
1172+
1173+
def final_time(self):
1174+
"""
1175+
Returns the final time in the Dataset whether
1176+
it contains a time dimension or not.
1177+
"""
1178+
if "t" in self.data.sizes:
1179+
return self.data.isel(t=-1)
1180+
else:
1181+
return self.data

xbout/boutdataset.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
_split_into_restarts,
3434
)
3535

36-
3736
@xr.register_dataset_accessor("bout")
3837
class BoutDatasetAccessor:
3938
"""
@@ -1355,7 +1354,16 @@ def with_cherab_grid(self):
13551354
from .cherab import grid
13561355

13571356
return grid.ds_with_cherab_grid(self.data)
1358-
1357+
1358+
def final_time(self):
1359+
"""
1360+
Returns the final time in the Dataset whether
1361+
it contains a time dimension or not.
1362+
"""
1363+
if "t" in self.data.sizes:
1364+
return self.data.isel(t=-1)
1365+
else:
1366+
return self.data
13591367

13601368
def _find_major_vars(data):
13611369
"""

0 commit comments

Comments
 (0)