filtering
filtering
¶
Temporal filtering and interpolation for perfusion data.
This module provides functions for temporal filtering, smoothing, and interpolation of time-series perfusion data.
All operations are GPU/CPU agnostic using the xp array module pattern. NO scipy dependencies - see XP Compatibility Requirements in plan.md.
temporal_filter
¶
Apply temporal filtering to time-series data.
GPU/CPU agnostic implementation using FFT-based convolution. No scipy dependency.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Time-series data. Last dimension is time.
TYPE:
|
filter_type
|
Filter type: - "gaussian": Gaussian smoothing (sigma controls width) - "moving_average": Moving average (window_size controls width) - "median": Median filter (window_size controls width)
TYPE:
|
sigma
|
Standard deviation for Gaussian filter (in time points).
TYPE:
|
window_size
|
Window size for moving average or median filter.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Filtered data with same shape as input. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If invalid filter_type or parameters. |
Examples:
temporal_interpolate
¶
Interpolate time-series data to new time points.
GPU/CPU agnostic implementation. No scipy dependency.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Time-series data. Last dimension is time with length len(time_old).
TYPE:
|
time_old
|
Original time points.
TYPE:
|
time_new
|
Target time points for interpolation.
TYPE:
|
method
|
Interpolation method: - "linear": Linear interpolation - "cubic": Cubic spline interpolation - "nearest": Nearest neighbor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray[floating]
|
Interpolated data with last dimension length len(time_new). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If time arrays have invalid shapes or method is unknown. |
Examples:
>>> import numpy as np
>>> from osipy.common.signal.filtering import temporal_interpolate
>>> data = np.random.rand(64, 64, 20, 30)
>>> time_old = np.linspace(0, 300, 30)
>>> time_new = np.linspace(0, 300, 60) # Upsample to 60 points
>>> interpolated = temporal_interpolate(data, time_old, time_new)
>>> print(interpolated.shape)
(64, 64, 20, 60)
resample_to_uniform
¶
Resample non-uniform time series to uniform temporal spacing.
GPU/CPU agnostic implementation. No scipy dependency.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Time-series data. Last dimension is time.
TYPE:
|
time
|
Original (possibly non-uniform) time points.
TYPE:
|
dt
|
Target temporal resolution. If None, uses minimum time difference in original data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[NDArray, NDArray]
|
(resampled_data, new_time_points) |
Examples: