cosmotron_mcp.tools.covariance¶
compute_full_covariance_from_session ¶
compute_full_covariance_from_session(session_dir: str, galaxy_bias: float = 1.5, cl_theory_mode: str = 'ccl', cosmo_params: dict | None = None, marginalise_sigma_m: bool = True, workspace_cache_scope: str = 'session', jobspec: dict | None = None) -> dict
Compute the full multi-tracer Gaussian covariance for a tomographic session.
Calls the multi-tracer compute_covariance(tracer_configs=[...]) API for all
N tomographic bins simultaneously, producing a joint (N_pairs×n_bpw)²
covariance matrix saved as results/covariance/covariance_all_bins.json, where
N_pairs = N*(N+1)//2.
Use this instead of calling compute_covariance_from_session per bin when you
need a full cross-bin covariance for tomographic SACC assembly. The existing
compute_covariance_from_session (per-bin, block-diagonal) remains available
for single-bin sessions.
Prerequisites: compute_all_cls_from_session must have run (auto-Cl files
cls_bin_{i:02d}_x_{i:02d}.json must exist for every bin).
marginalise_sigma_m: when True (default) and any spin-2 bin carries a manifest
sigma_m, add the analytic multiplicative-bias marginalisation term
(2110.06947 Eq. 20 ≡ Cosmotheka m_marg) to the covariance. The multiplicative
bias m itself is applied to the DATA at ingest (Eq. 2), so the covariance
theory Cℓ stays plain; only sigma_m enters, as this additive term (kept
separate so the Knox check validates the Gaussian part). No sigma_m set ⇒ no
term ⇒ byte-identical to a pre-calibration covariance.
workspace_cache_scope: "session" (default) or "registry" — see
compute_cls_from_session; a pure cache-location choice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory (all N tomographic bins' auto-Cl files must already exist). |
required |
galaxy_bias
|
float
|
Forwarded to |
1.5
|
cl_theory_mode
|
str
|
Forwarded to |
'ccl'
|
cosmo_params
|
dict | None
|
Forwarded to |
None
|
marginalise_sigma_m
|
bool
|
Add the analytic multiplicative-bias
marginalisation term for spin-2 bins carrying a manifest
|
True
|
workspace_cache_scope
|
str
|
|
'session'
|
jobspec
|
dict | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
An async receipt ``{job_id, status, mode: "async", run_dir, |
dict
|
session_dir, next: "check_job", ...}`` — never the covariance |
dict
|
numbers. Poll |
dict
|
|
dict
|
n_pairs, pair_labels, output_path, covariance, sqrt_diag, ells}``. |
Source code in cosmotron_mcp/server.py
compute_validation_covariance_from_session ¶
compute_validation_covariance_from_session(session_dir: str, component: str = 'BB', jobspec: dict | None = None) -> dict
Analytic Gaussian B-mode VALIDATION covariance (component "BB" or "EB").
B/EB modes are validated with their OWN covariance — they never enter the data
vector or the EE-only data covariance. For a null signal the variance is
noise-dominated (BB: 2·N²/(f_sky·modes); EB: N_EE·N_BB/(f_sky·modes)). Builds a
block-diagonal matrix over the spin-2 auto-bins and writes
results/covariance/covariance_validation_{BB|EB}.json (artefact type
covariance_validation, NOT covariance). Feeds run_bmode_null_tests_from_session.
Sessions with no spin-2 bins return {skipped: ...}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
component
|
str
|
|
'BB'
|
jobspec
|
dict | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
An async receipt ``{job_id, status, mode: "async", run_dir, |
dict
|
session_dir, next: "check_job", ...}``. Poll |
dict
|
|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
compute_covariance ¶
compute_covariance(cls_result: dict | None = None, survey_mask: list | None = None, z: list | None = None, nz: list | None = None, n_bar: float | None = None, nside: int = 512, cosmo_params: dict | None = None, galaxy_bias: float = 1.5, cl_theory_mode: str = 'ccl', workspace_path: str | None = None, covariance_workspace_path: str | None = None, output_path: str | None = None, generated_by: str | None = None, agent_name: str | None = None, tracer_configs: list[dict] | None = None, pairs: list | None = None) -> dict
Compute the Gaussian NMT covariance matrix using TJPCov.
PREFER compute_covariance_from_session (single bin) or
compute_full_covariance_from_session (tomographic/3×2pt) — this
low-level primitive takes no session_dir and needs every physical
input hand-assembled.
Two calling conventions, both returning a dict:
Single-tracer (legacy): compute_covariance(cls_result, survey_mask, z, nz, n_bar=n_bar, nside=nside) Multi-tracer (N > 1 bins or spin-2), keyword-only: compute_covariance(tracer_configs=[{...}, {...}], nside=nside)
Supports spin-0 and spin-2 fields and mixed-spin probe combinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_result
|
dict | None
|
Output dict from |
None
|
survey_mask
|
list | None
|
HEALPix mask (legacy single-tracer API). |
None
|
z
|
list | None
|
Redshift distribution grid (legacy single-tracer API). |
None
|
nz
|
list | None
|
Redshift distribution n(z) values (legacy single-tracer API). |
None
|
n_bar
|
float | None
|
Mean counts per occupied HEALPix pixel (legacy single-tracer API). Must be > 0. |
None
|
nside
|
int
|
HEALPix resolution parameter. |
512
|
cosmo_params
|
dict | None
|
CCL cosmological parameters. Defaults to Planck 2018 ΛCDM. |
None
|
galaxy_bias
|
float
|
Galaxy bias for the single-tracer legacy path. |
1.5
|
cl_theory_mode
|
str
|
|
'ccl'
|
workspace_path
|
str | None
|
Optional disk path for caching NaMaster workspaces (single-tracer legacy path only). |
None
|
covariance_workspace_path
|
str | None
|
Optional disk path for caching the covariance NaMaster workspace (single-tracer legacy path only). |
None
|
output_path
|
str | None
|
If provided, write the result JSON to this path. |
None
|
generated_by
|
str | None
|
Infrastructure kwarg — auto-populated from the executor environment. |
None
|
agent_name
|
str | None
|
Infrastructure kwarg — auto-populated from the executor environment. |
None
|
tracer_configs
|
list[dict] | None
|
List of tracer config dicts (multi-tracer API). Each
dict must have: |
None
|
pairs
|
list | None
|
Optional subset of tracer pairs to build (multi-tracer API). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict
|
Single-tracer (legacy API): |
|
dict
|
|
|
dict
|
Multi-tracer ( |
|
dict
|
|
|
dict
|
|
|
dict
|
|
|
dict
|
Requires the optional |
|
dict
|
|
|
dict
|
inside the function. |
|
dict
|
This is a |
|
dict
|
covariance (either path) is compute-node work, so it ALWAYS runs as |
|
dict
|
a non-blocking local background job, never inline (no |
|
dict
|
param — session-less, local job routing only). The dict shapes |
|
dict
|
above describe what lands in |
|
returns |
dict
|
it returns an async receipt ``{job_id, status, mode: |
dict
|
"async", run_dir, session_dir, next: "check_job", ...}`` — |
|
dict
|
|
|
dict
|
session of its own), NOT a pipeline session; use the |
|
dict
|
the receipt itself returns when polling. Poll |
|
dict
|
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 | |
compute_covariance_from_session ¶
compute_covariance_from_session(session_dir: str, bin_index: int = 0, nz_path: str | None = None, galaxy_bias: float = 1.5, cl_theory_mode: str = 'ccl', cosmo_params: dict | None = None, marginalise_sigma_m: bool = True, workspace_cache_scope: str = 'session', jobspec: dict | None = None) -> dict
Compute the Gaussian covariance for one bin straight from a session.
Session-driven wrapper around :func:compute_covariance, mirroring
:func:cosmotron.tools.compute_cls_from_session. It assembles every
argument from the session on disk so the caller never has to hand-build a
survey mask, redshift distribution, or n_bar — the brittle assembly that
repeatedly broke the compute_cls → compute_covariance handoff.
Steps¶
- Read
pipeline_config(nside, full_sky, apodisation) and the manifest. - Load the bin's
results/spectra/cls_bin_{bin_index:02d}_x_{bin_index:02d}.json(must already exist — runcompute_cls_from_sessionfirst). - Build
survey_mask:mask.fitsif the manifest references one, else a full-sky map of ones — always a float64 ndarray. - Pull
n_barfrommanifest[...]["catalogue_stats"]["n_bar"]. - Load the calibrated
z/nzfrom the survey n(z) file (explicitnz_pathor discovered indata_folder). A catalogue redshift histogram is deliberately NOT used — it gives the wrong theory Cl. - Call :func:
compute_covariance, writingresults/covariance/covariance_bin_{bin_index:02d}_x_{bin_index:02d}.jsonand returning a JSON-serialisable dict (lists, not ndarrays).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session workspace directory (contains manifest.json + session_context.json). |
required |
bin_index
|
int
|
Zero-based index into |
0
|
nz_path
|
str | None
|
Path to the calibrated 2-column (z, dndz) n(z) file for
this bin. If |
None
|
galaxy_bias
|
float
|
Forwarded to |
1.5
|
cl_theory_mode
|
str
|
Forwarded to |
'ccl'
|
cosmo_params
|
dict | None
|
Forwarded to |
None
|
marginalise_sigma_m
|
bool
|
When |
True
|
workspace_cache_scope
|
str
|
|
'session'
|
jobspec
|
dict | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
An async receipt ``{job_id, status, mode: "async", run_dir, |
dict
|
session_dir, next: "check_job", ...}`` — never the covariance |
dict
|
numbers. Poll |
dict
|
|
dict
|
single-tracer |
dict
|
( |
dict
|
lists), plus |
Source code in cosmotron_mcp/server.py
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 | |
validate_covariance_knox ¶
validate_covariance_knox(session_dir: str | None = None, bin_index: int = 0, cov_result: dict | None = None, cls_result: dict | None = None, f_sky: float | None = None) -> dict
Scientifically validate a covariance against the analytic Knox baseline.
Compares the diagonal of the (TJPCov/NaMaster) covariance to the binned
Gaussian Knox variance built from the same theory Cl + shot noise + f_sky.
The verdict is f_sky-aware: a strict precision band near full sky, an
order-of-magnitude sanity band on a cut sky (where mode-coupling makes the two
legitimately differ). This catches a grossly wrong covariance — including the
fabricated cov_diag = noise_bias regression — without false-failing a
correct cut-sky covariance.
Call it either from a session (loads results/covariance/covariance_bin_NN_x_NN.json +
results/spectra/cls_bin_NN_x_NN.json) or in-memory by passing cov_result +
cls_result directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str | None
|
Session directory to load the covariance/Cl JSON from;
omit when passing |
None
|
bin_index
|
int
|
Tomographic bin index (session mode only). |
0
|
cov_result
|
dict | None
|
Covariance result dict (in-memory mode). |
None
|
cls_result
|
dict | None
|
Power-spectrum result dict (in-memory mode). |
None
|
f_sky
|
float | None
|
Sky fraction; inferred from the session when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A JSON-safe |
dict
|
|
dict
|
( |
dict
|
|
dict
|
|