From f8a52ea9b76a07023c9aa4961bfbfbf061f2158e Mon Sep 17 00:00:00 2001 From: Sven Geboers Date: Thu, 16 Apr 2026 21:44:02 +0200 Subject: [PATCH] fix: pass annual-only windows to compute_nd_axes in SVD components tab _get_aligned_party_scores and _get_aligned_trajectory_scores both called compute_nd_axes() with no window_ids, which defaulted to _load_window_ids() returning ALL windows including quarterly. This caused the SVD component 1 bar chart to disagree with the compass (which correctly used annual-only windows via get_uniform_dim_windows). D66 appeared between GL-PvdA and PvdD in component 1 because quarterly windows contaminated the PCA basis. --- explorer.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/explorer.py b/explorer.py index 3c83089..e441fe9 100644 --- a/explorer.py +++ b/explorer.py @@ -633,8 +633,10 @@ def _get_aligned_trajectory_scores( """ from analysis.political_axis import compute_nd_axes - # Get aligned scores for all windows via PCA - scores_by_window, _ = compute_nd_axes(db_path, n_components=n_components) + # Get aligned scores for the requested windows via PCA (annual-only, no quarterly) + scores_by_window, _ = compute_nd_axes( + db_path, window_ids=windows, n_components=n_components + ) if not scores_by_window: return {} @@ -2634,7 +2636,10 @@ def build_svd_components_tab(db_path: str) -> None: """Get party scores for all N components from aligned PCA positions.""" from analysis.political_axis import compute_nd_axes - scores_by_window, _ = compute_nd_axes(db_path, n_components=10) + annual_windows = get_uniform_dim_windows(db_path) + scores_by_window, _ = compute_nd_axes( + db_path, window_ids=annual_windows, n_components=10 + ) window_scores = scores_by_window.get(window, {}) if not window_scores: return {}