get_next_index

method of dascore.core.coords.BaseCoord source

get_next_index(
    self ,
    value ,
    samples = False,
    allow_out_of_bounds = False,
    relative = False,
)-> ‘int’

Get the index a value would have in a coordinate.

This returns the “next” rather than the closest, index if the exact value is not contained by the index.

Parameters

Parameter Description
value The value which could be contained by the coordinate.
samples If True, value refers to samples (ie an index) of coord.
allow_out_of_bounds If True, allow the value to be out of bounds of the coordinate
and just return an index referring to the end
(len(coords) - 1) or beginning (0).
relative If True, the provided values are relative to the start (if possitve)
or end (if negative) of the coordinate.

Examples

from dascore.core import get_coord
coord = get_coord(start=0, stop=10, step=1)
# Find the index for a value contained by the coordinate.
assert coord.get_next_index(1) == 1
# The next (not closest) index is return for value not in coord.
assert coord.get_next_index(2.000001) == 3