IndexDataFilter#

class myoverse.datasets.filters.generic.IndexDataFilter(input_is_chunked, is_output=False, name=None, run_checks=True, *, indices=None)[source]#

Filter that indexes the input array using NumPy-style indexing.

This filter provides a flexible way to select specific elements or slices from the input array using NumPy’s powerful indexing syntax. It supports basic slicing, integer array indexing, boolean masks, ellipsis, and advanced indexing.

Parameters:
  • input_is_chunked (bool) – Whether the input is chunked or not.

  • is_output (bool, optional) – Whether the filter is an output filter. If True, the resulting signal will be outputted by any dataset pipeline, by default False.

  • name (str, optional) – The name of the filter, by default None.

  • run_checks (bool) –

    Whether to run the checks when filtering. By default, True. If False can potentially speed up performance.

    Warning

    If False, the user is responsible for ensuring that the input array is valid.

  • indices (any valid NumPy index) – The indices to use for indexing the input array. Can be: - Single index: 0, -1 - Slice: slice(0, 10), slice(None, None, 2) - Tuple of indices for multiple dimensions: (0, slice(None), [1, 2, 3]) - Ellipsis: … or Ellipsis - Boolean mask: array([True, False, True]) - Integer arrays for fancy indexing: np.array([0, 2, 4]) - Any combination of the above

Examples

>>> import numpy as np
>>> from myoverse.datasets.filters.generic import IndexDataFilter
>>> # Create data
>>> data = np.random.rand(5, 10, 100)
>>>
>>> # Select first element of first dimension
>>> filter_first = IndexDataFilter(indices=0)
>>> output = filter_first(data)  # shape: (10, 100)
>>>
>>> # Select first three elements of last dimension
>>> filter_slice = IndexDataFilter(indices=(slice(None), slice(None), slice(0, 3)))
>>> output = filter_slice(data)  # shape: (5, 10, 3)
>>>
>>> # Select specific elements with fancy indexing
>>> filter_fancy = IndexDataFilter(indices=([0, 2], slice(None), [0, 50, 99]))
>>> output = filter_fancy(data)  # shape: (2, 10, 3)
>>>
>>> # Use ellipsis to simplify indexing (equivalent to the above)
>>> filter_ellipsis = IndexDataFilter(indices=([0, 2], ..., [0, 50, 99]))
>>> output = filter_ellipsis(data)  # shape: (2, 10, 3)
>>>
>>> # Select specific elements from the last dimension
>>> filter_lastdim = IndexDataFilter(indices=(slice(None), slice(None), [0, 1, 2]))
>>> output = filter_lastdim(data)  # shape: (5, 10, 3)

Notes

This filter directly passes the provided indices to NumPy’s indexing system. The behavior will match exactly what you would expect from numpy.ndarray indexing.

Methods

__init__(input_is_chunked[, is_output, ...])

_filter(input_array, **kwargs)

Apply the indices to the input array.