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#

apply_pca_score_baseline(time, scores[, n_points, ...])

Baseline-correct PCA scores.

flip_pc_scores_for_consistency(scores, time[, ...])

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_points is not None): subtract the mean of the first n_points time 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_points is None.

  • baseline_max_ms (float) – Time-window baseline boundaries used when n_points is None.

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:
  • scores (pd.DataFrame) – PC rows x time columns.

  • time (np.ndarray of shape (n_times,)) – Time stamps aligned with the columns of scores.

  • flip_window_ms (tuple[float, float], default=(-200.0, 800.0)) – Half-open time window used to compute the reference mean.

Returns:

Copy of scores with sign-flipped rows as needed.

Return type:

pd.DataFrame