transforms¶
Standalone transform functions for DesignMatrix.
Each function takes a DesignMatrix instance as the first argument (dm)
and returns a new DesignMatrix via copy_with(dm,...).
Methods:
| Name | Description |
|---|---|
downsample | Reduce temporal resolution using Polars-native operations. |
standardize | Standardize columns using the specified method. |
upsample | Increase temporal resolution using Polars-native interpolation. |
zscore | Z-score standardize columns to mean zero and unit variance. |
Classes¶
Methods¶
downsample¶
downsample(dm: DesignMatrix, target: float, method: str = 'mean') -> DesignMatrixReduce temporal resolution using Polars-native operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance to transform. | required |
target | float | Target sampling frequency in Hz (must be < current sampling_freq). | required |
method | str | Aggregation method - ‘mean’ or ‘median’. Default: ‘mean’. | ‘mean’ |
Returns:
| Name | Type | Description |
|---|---|---|
DesignMatrix | DesignMatrix | Downsampled DesignMatrix with updated sampling_freq. |
Examples:
>>> dm = DesignMatrix({"a": list(range(100))}, sampling_freq=1.0)
>>> dm_down = downsample(dm, target=0.5) # 1 Hz -> 0.5 Hz (100 -> 50 samples)standardize¶
standardize(dm: DesignMatrix, columns: list[str] | None = None, method: str = 'zscore') -> DesignMatrixStandardize columns using the specified method.
This method provides a consistent API with BrainData and Collection for data normalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance to transform. | required |
columns | list [ str ] | None | Columns to standardize. If None, standardize all non-confound columns. | None |
method | str | Standardization method. Options are: - ‘zscore’: Z-score standardization (mean=0, std=1) [default] - ‘center’: Mean centering only (mean=0) | ‘zscore’ |
Returns:
| Name | Type | Description |
|---|---|---|
DesignMatrix | DesignMatrix | New DesignMatrix with standardized columns. |
Examples:
>>> dm = DesignMatrix(np.random.randn(100, 3))
>>> dm_z = standardize(dm, method='zscore') # z-score all columns
>>> dm_c = standardize(dm, method='center') # center onlyupsample¶
upsample(dm: DesignMatrix, target: float, method: str = 'linear') -> DesignMatrixIncrease temporal resolution using Polars-native interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance to transform. | required |
target | float | Target sampling frequency in Hz (must be > current sampling_freq) | required |
method | str | Interpolation method - ‘linear’ or ‘nearest’ (default: ‘linear’) | ‘linear’ |
Returns:
| Name | Type | Description |
|---|---|---|
DesignMatrix | DesignMatrix | Upsampled DesignMatrix with updated sampling_freq. |
Examples:
>>> dm = DesignMatrix({"a": list(range(10))}, sampling_freq=1.0)
>>> dm_up = upsample(dm, target=2.0) # 1 Hz -> 2 Hz (10 -> 18 samples)zscore¶
zscore(dm: DesignMatrix, columns: list[str] | None = None) -> DesignMatrixZ-score standardize columns to mean zero and unit variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dm | DesignMatrix | DesignMatrix instance to transform. | required |
columns | list of str | Columns to standardize. If None, standardize all non-confound columns. | None |
Returns:
| Name | Type | Description |
|---|---|---|
DesignMatrix | DesignMatrix | New DesignMatrix with standardized columns |