coco_pipe.dim_reduction.preprocessing#
PCA score preprocessing utilities.
Functions#
- apply_pca_score_baseline
Baseline-correct PCA scores using an N-point or time-window approach.
- flip_pc_scores_for_consistency
Flip PC sign so the mean within a reference window is positive.
Functions#
|
Baseline-correct PCA scores. |
|
Flip each PC row so its mean within a reference window is non-negative. |
Module Contents#
- coco_pipe.dim_reduction.preprocessing.apply_pca_score_baseline(time, scores, n_points=None, baseline_min_ms=-200.0, baseline_max_ms=0.0)#
Baseline-correct PCA scores.
Two modes are available:
N-point mode (
n_pointsis notNone): subtract the mean of the firstn_pointstime samples from every PC row. Applied before any time cropping so that it replicates older script behaviour.Time-window mode (default): subtract the mean within
[baseline_min_ms, baseline_max_ms].
- Parameters:
time (np.ndarray of shape (n_times,)) – Time stamps aligned with the columns of
scores.scores (pd.DataFrame) – PC rows x time columns.
n_points (int, optional) – Number of leading samples to use as baseline. When set, takes priority over the time-window mode.
baseline_min_ms (float) – Time-window baseline boundaries used when
n_pointsisNone.baseline_max_ms (float) – Time-window baseline boundaries used when
n_pointsisNone.
- Returns:
Baseline-corrected copy of
scores.- Return type:
pd.DataFrame
- coco_pipe.dim_reduction.preprocessing.flip_pc_scores_for_consistency(scores, time, flip_window_ms=(-200.0, 800.0))#
Flip each PC row so its mean within a reference window is non-negative.
This makes the sign of PCA components visually consistent across subjects and conditions, removing the arbitrary sign indeterminacy of PCA.
- Parameters:
- Returns:
Copy of
scoreswith sign-flipped rows as needed.- Return type:
pd.DataFrame