FilterBaseClass#

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

Base class for filters.

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

  • allowed_input_type (Literal["both", "chunked", "not chunked"]) – Whether the filter accepts chunked input, not chunked input or both.

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

  • name (str, optional) – The name of the filter. This is used to identify the filter in the dataset. If not provided, the name of the filter class will be used.

  • 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.

__call__(input_array: np.ndarray | list[np.ndarray], \*\*kwargs) np.ndarray | Dict[str, np.ndarray][source]#

Filters the input array(s).

Note

A filter can accept a single numpy array OR a list of numpy arrays. Not both.

Input shape is determined by whether the allowed_input_type is “both”, “chunked” or “not chunked”.

When a filter is applied via Data.apply_filter(), it automatically receives all Data object parameters as keyword arguments. These are automatically set as attributes on the filter instance if they don’t already exist, making them accessible in the _filter method.

The filter can return either a single numpy array or a dictionary of numpy arrays. If a dictionary is returned, each key-value pair will be stored as a separate representation in the data processing graph with the key appended to the filter name.

Raises:

ValueError – If input_is_chunked is not explicitly set. If allowed_input_type is not valid.

Parameters:
  • input_is_chunked (bool)

  • allowed_input_type (Literal['both', 'chunked', 'not chunked'])

  • is_output (bool)

  • name (str | None)

  • run_checks (bool)

Notes

Filter Implementation:

When implementing a custom filter, ensure your _filter method accepts **kwargs:

def _filter(self, input_array, **kwargs):

# Access Data object parameters via self attributes # For example, if the Data object has a ‘sampling_frequency’ attribute: fs = self.sampling_frequency … return filtered_data

This allows your filter to use parameters from the Data object without requiring users to manually pass them.

To return multiple representations from a single filter, return a dictionary where: - Each key will be appended to the filter name to create a unique representation name - Each value should be a numpy array representing the data for that representation

Example:

def _filter(self, input_array, **kwargs):

# Split input into three grids grid1 = input_array[:, :10] grid2 = input_array[:, 10:20] grid3 = input_array[:, 20:30]

return {

“grid1”: grid1, “grid2”: grid2, “grid3”: grid3

}

Methods

__call__(input_array, **kwargs)

Apply the filter to the input array.

__init__(input_is_chunked, allowed_input_type)

__repr__()

Return repr(self).

__str__()

Return str(self).

_filter(input_array, **kwargs)

Apply the filter to the input array.

_filter_with_checks(input_array, **kwargs)

_run_filter_checks(input_array)

Run checks on the input array.

_run_init_checks()

Run checks on the filter initialization parameters.

property name#

Return the filter name, using the class name if no custom name was provided.