slice_xarray_by_dim

HSTB.kluster.xarray_helpers.slice_xarray_by_dim(arr, dimname='time', start_time=None, end_time=None)

Slice the input xarray dataset/dataarray by provided start_time and end_time. Start/end time do not have to be values in the dataarray index to be used, this function will find the nearest times.

If times provided are outside the array, will return the original array.

If times are not provided, will return the original array

Parameters
  • arr (Union[Dataset, DataArray]) – xarray Dataarray/Dataset with an index of dimname

  • dimname (str) – str, name of dimension to use with selection/slicing

  • start_time (Optional[float]) – float, start time of slice

  • end_time (Optional[float]) – float, end time of slice

Returns

xarray dataarray/dataset sliced to the input start time and end time

Return type

Union[xr.Dataset, xr.DataArray]