cosmotron_mcp.plotting¶
plot_cls_comparison ¶
plot_cls_comparison(session_dir: str, bin_index: int = 0, scaling: str = 'ell_cl', theory_file: str | None = None, theory_file_pattern: str | None = None, show_noise: bool = True, output_name: str | None = None, pair: list[int] | None = None, component: str = 'EE') -> dict
Plot measured Cℓ (with covariance error bars) vs theory for one bin or cross-pair.
AUTO-SPECTRUM (default): bin_index=N. Reads cls_bin_{N}.json + covariance_bin_{N}.json (or extracts from covariance_all_bins.json in tomo mode). Theory from theory_file_pattern → per-bin manifest → theory_file, drawn UNBINNED. Shot-noise overlay when show_noise=True.
CROSS-SPECTRUM: pair=[i, j] (i<j). Reads cls_bin_{i}x.json. Error bars from covariance_all_bins.json block. No shot noise. No theory unless theory_file given. Saves plots/cls_comparison_cross_{i}x.png.
scaling: "ell_cl" (ℓCℓ, default) | "ell2_cl" (ℓ(ℓ+1)Cℓ/2π) | "cl" (raw). output_name: override the output filename — satisfied BY THIS TOOL.
component: "EE" (default) | "BB" | "EB". Use component='BB' for B-mode null-test style plots ("plot the B modes the same way as the E modes"), 'EB' for the EB cross — do NOT hand-write matplotlib. No noise line for BB/EB. Error bars come from covariance_validation_{BB|EB}.json for auto bins (that file is auto-bin-only); cross pairs get an analytic Gaussian estimate from the measured spectra instead. NO theory curve is drawn — a zero reference line is drawn instead (theory_file/theory_file_pattern are ignored). Requires a spin-2 bin/pair (ValueError otherwise). Saves cls_comparison_bin_{N}BB.png / cls_comparison_crossx_BB.png (EE default filenames unchanged).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
bin_index
|
int
|
Auto-spectrum bin index (ignored when |
0
|
scaling
|
str
|
|
'ell_cl'
|
theory_file
|
str | None
|
Single theory Cℓ file for the auto-spectrum, used if
|
None
|
theory_file_pattern
|
str | None
|
Per-bin theory file pattern (e.g.
|
None
|
show_noise
|
bool
|
Overlay the shot-noise line (EE only). |
True
|
output_name
|
str | None
|
Override the output filename. |
None
|
pair
|
list[int] | None
|
|
None
|
component
|
str
|
|
'EE'
|
Returns:
| Type | Description |
|---|---|
dict
|
The plot result dict, including the saved PNG path(s). |
Source code in cosmotron_mcp/server.py
3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 | |
plot_cls_grid ¶
plot_cls_grid(session_dir: str, scaling: str = 'ell_cl', theory_file: str | None = None, theory_file_pattern: str | None = None, theory_file_pattern_cross: str | None = None, show_noise: bool = True, output_name: str | None = None, component: str = 'EE') -> dict
Plot all available Cℓ spectra in a single collated publication figure.
Auto-spectra only → vertical strip (N rows). Cross-correlations present → NxN upper-triangle grid (diagonal=auto, upper=cross, lower=blank).
Theory per auto-bin: resolved via theory_file_pattern (e.g.
"theory_cls/true_cls_bin{bin_index}.txt", relative to data_folder) →
per-bin manifest theory_path → theory_file (single file), drawn UNBINNED.
Theory for cross-panels: resolved via theory_file_pattern_cross (e.g.
"glass_true_cls_bin{i}x{j}.txt") with {i} and {j} placeholders
substituted per-panel. No fallback to theory_file_pattern — bin i's
auto theory is not the (i, j) cross theory; without a matching cross file
the panel is plotted measured-only.
The CCL cls_theory from covariance JSONs is NOT used — it is approximate and can be 2–4× off the simulation ground truth. Saves plots/cls_grid.png.
scaling: "ell_cl" (ℓCℓ, default) | "ell2_cl" (ℓ(ℓ+1)Cℓ/2π) | "cl" (raw). show_noise: overlay the noise line on EE auto panels (default True; labelled shear vs shot noise by spin). No-op for BB/EB (no noise line drawn there). output_name: override the output filename (satisfied by this tool — no matplotlib).
component: "EE" (default) | "BB" | "EB". Use component='BB' for B-mode null-test style plots ("plot the B modes the same way as the E modes"), 'EB' for the EB cross — do NOT hand-write matplotlib. theory_file/ theory_file_pattern* are ignored (a zero reference line is drawn instead); error bars come from covariance_validation_{BB|EB}.json for auto panels (cross panels get an analytic Gaussian estimate instead). A panel whose bin/pair is spin-0 shows a grey placeholder instead of failing; ValueError only if NO panel has the component. Saves cls_grid_BB.png (EE default cls_grid.png unchanged).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
scaling
|
str
|
|
'ell_cl'
|
theory_file
|
str | None
|
Single theory Cℓ file fallback for auto-panels. |
None
|
theory_file_pattern
|
str | None
|
Per-bin theory file pattern for auto-panels. |
None
|
theory_file_pattern_cross
|
str | None
|
Per-pair theory file pattern for
cross-panels, with |
None
|
show_noise
|
bool
|
Overlay the shot-noise line on EE auto panels. |
True
|
output_name
|
str | None
|
Override the output filename. |
None
|
component
|
str
|
|
'EE'
|
Returns:
| Type | Description |
|---|---|
dict
|
The plot result dict, including the saved PNG path. |
Source code in cosmotron_mcp/server.py
3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 | |
plot_covariance ¶
plot_covariance(session_dir: str, bin_index: int | None = None, output_name: str | None = None) -> dict
Plot the normalised covariance (correlation) matrix.
bin_index=None (default): assembles ALL covariance_bin_*.json into one block-diagonal matrix with white dividing lines between tomographic bins — matches publication-style combined-covariance figures. Saves to plots/covariance_combined.png. bin_index=N: single-bin plot → plots/covariance_bin_{N:02d}.png. output_name overrides the filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
bin_index
|
int | None
|
Single bin to plot; |
None
|
output_name
|
str | None
|
Override the output filename. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The plot result dict, including the saved PNG path. |
Source code in cosmotron_mcp/server.py
plot_catalogue_diagnostics ¶
Plot catalogue diagnostics (n(z) from the survey file, sky footprint).
Reads manifest.json. Plots whatever inputs are present and skips-with-note the rest; never fabricates data, never blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
output_name
|
str | None
|
Override the default filenames (still two files: a
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in cosmotron_mcp/server.py
plot_covariance_validation ¶
plot_covariance_validation(session_dir: str, bin_index: int = 0, output_name: str | None = None, pair: list[int] | None = None, component: str = 'EE') -> dict
Two-panel Knox covariance validation plot for one auto-bin or cross-pair.
AUTO-BIN (default): bin_index=N. Reads covariance_bin_{N}.json (with cls_theory, from compute_covariance). Falls back to the matching block in covariance_all_bins.json in tomographic mode where per-bin files are absent.
CROSS-PAIR: pair=[i, j] (i<j). Extracts the (i,j) diagonal block from covariance_all_bins.json and overlays the analytic Knox cross-pair estimate Var[C^ij] ≈ (C^ii·C^jj + (C^ij)²) / modes. Saves plots/covariance_validation_cross_{i}x.png.
Upper panel: σ_NaMaster(ℓ) vs σ_Knox(ℓ). Lower panel: ratio cov / Knox vs ℓ with tolerance band.
component: "EE" (default, unchanged) | "BB" | "EB". Reads covariance_validation_{BB|EB}.json instead (written by compute_validation_covariance_from_session) and checks it against the same analytic Knox formula used to build it. Auto-bin only — pair= with a non-EE component raises ValueError (no BB/EB cross covariance exists). Saves covariance_validation_bin_{N}_BB.png.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
bin_index
|
int
|
Auto-bin index (ignored when |
0
|
output_name
|
str | None
|
Override the output filename. |
None
|
pair
|
list[int] | None
|
|
None
|
component
|
str
|
|
'EE'
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in cosmotron_mcp/server.py
plot_bmode_diagnosis ¶
plot_bmode_diagnosis(session_dir: str, bin_index: int = 0, component: str = 'BB', output_name: str | None = None) -> dict
Plot the L1 B-mode excess diagnosis for one spin-2 auto-bin.
Shows the measured B-mode bandpowers against BOTH the analytic shot-noise error (what the null test used) and the high-ℓ α-rescaled error, annotated with the deterministic verdict / α / p_orig / p_rescaled from diagnose_bmode_excess_from_session. A benign noise-model residual is swallowed by the rescaled band; a colored excess sticks out of both. Run diagnose_bmode_excess_from_session first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
bin_index
|
int
|
Spin-2 auto-bin id. |
0
|
component
|
str
|
|
'BB'
|
output_name
|
str | None
|
Override the output filename (saved under plots/). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in cosmotron_mcp/server.py
plot_covariance_validation_grid ¶
Covariance-validation (Knox) plots for EVERY auto-bin and cross-pair, one call.
Mirrors plot_cls_grid's "auto-detects autos vs cross-correlations" guarantee for plot_covariance_validation, which otherwise takes one bin_index/pair at a time — a multi-bin session silently got only its bin_index=0 plot unless every pair was named explicitly. Detects every auto-bin and cross-pair present under results/spectra/ and calls plot_covariance_validation once per pair, saving each under its normal default filename (covariance_validation_bin_{i}.png / ...crossx.png / ...bin.png) — no single combined figure (a Knox panel is already a 2-row figure; an NxN grid of those would be unreadable).}_{BB|EB
component: "EE" (default) — auto-bin plots for every bin AND cross-pair
plots for every detected (i, j). "BB"/"EB" — auto-bin only (no cross
covariance exists for either), restricted to the spin-2 bins actually
recorded in covariance_validation_{BB|EB}.json; a spin-0 session or one
where compute_validation_covariance_from_session was never run returns
{"skipped": ..., "paths": []} rather than raising. A per-pair failure is
recorded in results with a "skipped" key and does not abort the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
component
|
str
|
"EE" (default), "BB", or "EB". |
'EE'
|
Returns:
| Type | Description |
|---|---|
dict
|
{"paths": [...], "results": [...], "n_bins", "n_pairs"}. |
Source code in cosmotron_mcp/server.py
plot_healpix_maps ¶
plot_healpix_maps(session_dir: str, map_paths: list[str] | None = None, output_name: str | None = None) -> dict
Mollweide projection plots of HEALPix maps from the session.
When map_paths is None, auto-detects delta_map/mask AND shear maps (roles shear_q/shear_u, from compute_cls_from_session(..., save_maps=True) on spin-2 bins) from artefact_registry.json: rows=bins, cols=(γ₁/Q, γ₂/U, mask) for shear, (δ_g, mask) for density, or all four for a mixed 3×2pt session (blank cell where a bin has no map for that column). Diverging RdBu_r colormap for the shear columns. Use for any "plot the shear / Q/U maps" request — never healpy scripting. For tomographic sessions each subplot title contains the bin index and redshift range (z_min–z_max from manifest).
Requires healpy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
map_paths
|
list[str] | None
|
Explicit map paths to plot; |
None
|
output_name
|
str | None
|
Override the output filename. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|