cosmocore.conventions.cmb module

CMB-specific aliases over the structural SpectrumKind enum, plus the to_cmb_canonical helper for re-keying SpectrumKey-keyed dicts to the conventional T-first ordering regardless of component declaration order.

CMB-friendly aliases for SpectrumKind, plus the post-hoc canonicalisation helper that re-keys output dicts to T-first ordering and label-conversion helpers for user-facing output.

Slots map to CMB letters: S->T, G->E, C->B.

cosmocore.conventions.cmb.spectrum_key_to_label(key, *, labels, spins, separator='')[source]

Convert a SpectrumKey to a concatenated physical label.

Parameters:
  • key (SpectrumKey) – The spectrum identifier.

  • labels (sequence[str]) – Per-slot label list — typically params.labels. Must contain one entry per slot across all components (e.g. ["T", "E", "B"] for spins=(0, 2)).

  • spins (sequence[int]) – Per-component spin list (e.g. (0, 2) for TQU).

  • separator (str, optional) – Separator inserted between the two slot labels. Default empty string — yields "TT", "EE", "E1B2", etc. Pass "x" for "T1xT2" etc.

Returns:

labels[i] + separator + labels[j] where i and j are the slot indices selected by key.

Return type:

str

Examples

>>> spins = (0, 2)
>>> labels = ["T", "E", "B"]
>>> spectrum_key_to_label(
...     SpectrumKey(0, 0, SpectrumKind.SS, spins=spins),
...     labels=labels, spins=spins
... )
'TT'
>>> spectrum_key_to_label(
...     SpectrumKey(1, 1, SpectrumKind.GC, spins=spins),
...     labels=labels, spins=spins
... )
'EB'
cosmocore.conventions.cmb.to_cmb_canonical(result_dict, *, spins)[source]

Re-key a result dict to CMB-conventional ordering (T-first, then E/B).

For mixed-spin pairs (one spin-0 + one spin-2) where the declaration placed the spin-2 component first, the output key is swapped so the spin-0 (T) component appears first — matching the conventional CMB naming where TE / TB are written T-first. Same-spin pairs and pairs already in T-first order pass through unchanged.

Parameters:
  • result_dict (dict[SpectrumKey, Any]) – Output dictionary keyed by SpectrumKey.

  • spins (tuple[int, ...]) – Spin of each component in the original field collection.

Returns:

New dict with re-keyed entries; values are not copied.

Return type:

dict[SpectrumKey, Any]

cosmocore.conventions.cmb.to_label_dict(source, *, labels, spins, spectra_list=None, n_bins=None)[source]

Convert a SpectrumKey-keyed dict or a flat array into a label-keyed dict.

Parameters:
  • source (dict or numpy.ndarray) – Either a SpectrumKey-keyed dict ({key: value, ...}) or a flat array. For a 1-D array of shape (n_spectra * n_bins,) the result entries have shape (n_bins,). For a 2-D array of shape (n_sims, n_spectra * n_bins) the result entries have shape (n_sims, n_bins). The last axis is partitioned into n_spectra contiguous blocks of n_bins columns each, in the order given by spectra_list.

  • labels (sequence[str]) – Per-slot label list (typically params.labels).

  • spins (sequence[int]) – Per-component spin list.

  • spectra_list (list[SpectrumKey], optional) – Required when source is an array; ignored when source is a dict. Specifies the spectrum order in the flat layout.

  • n_bins (int, optional) – Required when source is an array. Number of bins per spectrum.

Returns:

Label-keyed dict. For multi-frequency / multi-component setups the user’s per-slot labels (e.g. ["T100", "T143"]) make the result keys unambiguous ("T100T143" etc.).

Return type:

dict[str, Any]