get_slice_from_monotonic

function of dascore.utils.misc source

get_slice_from_monotonic(
    array ,
    cond: tuple | None[<class ’tuple, None] ,
)-> ‘slice’

Return a slice object which meets conditions in cond on array.

This is useful for determining how a particular dimension should be trimmed based on a coordinate (array) and an interval (cond).

Parameters

Parameter Description
array Any array with sorted values, but the array can have zeros at the end up to the sorted segment. Eg [1,2,3, 0, 0] works.
cond An interval for which the array is to be indexed. End points are inclusive.

Examples

import numpy as np
from dascore.utils.misc import get_slice_from_monotonic
ar = np.arange(100)
array_slice = get_slice_from_monotonic(ar, cond=(1, 10))