LowRank.AlignDecompositions#
LowRank.AlignDecompositions.py
Utility for aligning scattering profiles from two decompositions onto a
common q-grid. Exported at the top-level as molass.align_decompositions.
- get_P_at(decomp, q_target, normalize=False)#
Return the XR scattering matrix P interpolated onto q_target.
- Parameters:
decomp (Decomposition) – A decomposition object returned by
quick_decomposition().q_target (array-like, shape (m,)) – Target q-values in Å⁻¹. Must lie within the q-range of decomp.
normalize (bool, optional) – If
True, each component column is divided by its maximum value so that all columns peak at 1. DefaultFalse.
- Returns:
P_interp – Scattering matrix P evaluated at q_target.
- Return type:
np.ndarray, shape (m, n_components)
- align_decompositions(decomp_a, decomp_b, n=500, normalize=False)#
Interpolate two decompositions’ XR scattering matrices onto a shared q-grid.
The shared grid spans the intersection of the two q-ranges and contains n evenly-spaced points.
- Parameters:
decomp_a (Decomposition) – Two decomposition objects to align.
decomp_b (Decomposition) – Two decomposition objects to align.
n (int, optional) – Number of q-points in the common grid. Default 500.
normalize (bool, optional) – If
True, each component column in both matrices is normalised to peak at 1. Useful for shape comparison regardless of absolute scale. DefaultFalse.
- Returns:
q_common (np.ndarray, shape (n,)) – The shared q-grid in Å⁻¹.
P_a (np.ndarray, shape (n, n_components_a)) – Scattering matrix of decomp_a evaluated on q_common.
P_b (np.ndarray, shape (n, n_components_b)) – Scattering matrix of decomp_b evaluated on q_common.
Examples
Compare the first scattering component of two decompositions:
from scipy.stats import pearsonr import molass q, P_a, P_b = molass.align_decompositions(decomp_1, decomp_2, normalize=True) r, _ = pearsonr(P_a[:, 0], P_b[:, 0]) print(f"Pearson r = {r:.5f}")