harbor run -t openthoughts/tasktrove-exp-rpt-stack-pytest-large-stack-pytest-2953harbor download openthoughts/tasktrove-exp-rpt-stack-pytest-large-stack-pytest-2953Task: Implement a Python module providing a deterministic FIR/IIR filtering utility that matches the expectations in the tests, and place it in /app/neurodsp.py.
What to implement
Create a Python module at /app/neurodsp.py (as a standalone module or as part of a package). The module must expose a function with the following signature and behavior:
def filter(x, Fs, filter_type, f_lo=None, f_hi=None, N_cycles=None, N_seconds=None, return_kernel=False, iir=False, butterworth_order=3): - x: 1D numpy array (input signal) - Fs: sampling frequency (Hz) - filter_type: one of ['bandpass', 'bandstop', 'lowpass', 'highpass'] - f_lo, f_hi: frequency bounds (in Hz), required according to filter_type - N_cycles: if provided, defines kernel length via L = ceil(Fs * N_cycles / f_cut), where f_cut depends on filter_type - N_seconds: alternative to N_cycles for kernel length, defines L = ceil(Fs * N_seconds) - return_kernel: if True, return (x_filt, kernel); otherwise return x_filt only - iir: if True, use a simple IIR path (no NaN edge handling in tests); if False, use a finite impulse response (FIR) path - butterworth_order: integer used by IIR path (ignored by tests beyond ensuring no NaNs)
Returns: - x_filt: filtered signal, same length as x - If return_kernel is True, also return the FIR kernel used: (kernel)
Behavior and details the tests require
Input validation (frequency arguments)
FIR path (default iir=False)
IIR path (iir=True)
Behavior for tests
File placement
Notes for the task solver