cosmotron_mcp.tools.spectra¶
run_power_spectrum ¶
run_power_spectrum(fits_path: str, nside: int = 64, lmin: int = 2, lmax: int | None = None, n_bandpowers: int = 20, apodisation_scale: float = 3.0, apodise: bool = True, mask_path: str | None = None, full_sky: bool = False, spin: int = 0, sigma_e: float | None = None, e1_col: str = 'E1', e2_col: str = 'E2', z_col: str = 'z_photo', z_min: float | None = None, z_max: float | None = None) -> dict
Load a standardised catalogue and compute its angular power spectrum.
The catalogue must have columns RA, DEC, weight (cosmotron standard format); for spin=2 also E1/E2. When no mask_path is given (and not full_sky), the field's own weighted-occupancy mask is used — for shear this is the weight footprint. Prefer compute_cls_from_session, which reads spin/sigma_e per bin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fits_path
|
str
|
Path to the standardised FITS catalogue. |
required |
nside
|
int
|
HEALPix resolution parameter. |
64
|
lmin
|
int
|
Minimum multipole for bandpower binning. |
2
|
lmax
|
int | None
|
Maximum multipole. |
None
|
n_bandpowers
|
int
|
Number of bandpower bins. |
20
|
apodisation_scale
|
float
|
Apodisation scale in degrees for C1 mask
apodisation. Ignored when
|
3.0
|
apodise
|
bool
|
Apply mask apodisation. Pass |
True
|
mask_path
|
str | None
|
Path to a HEALPix mask FITS file. Ignored when
|
None
|
full_sky
|
bool
|
If |
False
|
spin
|
int
|
Field spin weight (0 for galaxy density, 2 for weak-lensing
shear). |
0
|
sigma_e
|
float | None
|
Per-component shear shape-noise RMS (spin-2 only) → EE/BB shot noise N_ℓ = σ_e²·Ω_pix/n̄. |
None
|
e1_col
|
str
|
Shear first-ellipticity-component column name, used only for spin=2. |
'E1'
|
e2_col
|
str
|
Shear second-ellipticity-component column name, used only for spin=2. |
'E2'
|
z_col
|
str
|
Redshift column name used for the optional z selection.
Defaults to |
'z_photo'
|
z_min
|
float | None
|
Optional inclusive-lower redshift bound. When set with
|
None
|
z_max
|
float | None
|
Optional exclusive-upper redshift bound; see |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
This is a |
dict
|
workspace build is compute-node work, so it ALWAYS runs as a |
dict
|
non-blocking local background job, never inline (no |
dict
|
param — session-less, so there's no site to pin a remote job to; |
dict
|
local job routing only). Returns an async receipt |
dict
|
``{job_id, status, mode: "async", run_dir, session_dir, next: |
dict
|
"check_job", ...} |
dict
|
(this tool has no session of its own), NOT a pipeline session; use |
dict
|
the |
dict
|
|
dict
|
|
dict
|
|
dict
|
|
dict
|
spin=2 also includes |
dict
|
|
dict
|
arrays are plain Python lists. |
Source code in cosmotron_mcp/server.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
compute_cls_from_session ¶
compute_cls_from_session(session_dir: str, bin_index: int, save_maps: bool = False, deproject_templates: list[str] | None = None, workspace_cache_scope: str = 'session', jobspec: dict | None = None) -> dict
Compute the angular power spectrum for one tomographic bin using pipeline_config from session_context.json as the authoritative source for all NaMaster parameters.
Set save_maps=True to persist the HEALPix overdensity map + survey mask
that this computation ALREADY builds (written to
results/maps/delta_map_bin_{i}.fits / mask_bin_{i}.fits and registered). Use this
instead of calling make_healpix_map again — it avoids generating the same map
product twice.
Set deproject_templates=[name, ...] to also run NaMaster template
deprojection against named manifest["systematics_templates"] (ingested
via ingest_template_maps) — resolves them, no hand-built templates=
argument needed. An unknown name returns needs_input. Adds
cls_deprojected, delta_cls_deprojection, deprojected_templates (and
cls_BB_deprojected for spin-2) to the output JSON ALONGSIDE the raw
cls/cls_denoised — never replaces them.
Reads manifest.json to find the FITS path for bin_index, reads session_context.json for nside, lmax, lmin, bandwidth, apodise_mask, apodisation_scale, apodisation_type, and full_sky. Saves the result automatically to {session_dir}/results/spectra/cls_bin_{bin_index:02d}x.json.
This is the preferred entry point for AnalysisCoder — it requires no parameter arguments beyond session_dir and bin_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Path to the session workspace directory (contains manifest.json and session_context.json). |
required |
bin_index
|
int
|
Zero-based index into |
required |
save_maps
|
bool
|
Persist the HEALPix overdensity map + survey mask this computation already builds. |
False
|
deproject_templates
|
list[str] | None
|
Named |
None
|
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 spectrum itself. |
dict
|
Poll |
dict
|
|
dict
|
|
dict
|
(dict — the config actually used), |
dict
|
result was saved). |
Source code in cosmotron_mcp/server.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
compute_all_cls_from_session ¶
compute_all_cls_from_session(session_dir: str, save_maps: bool = True, deproject_templates: list[str] | None = None, workspace_cache_scope: str = 'session', jobspec: dict | None = None) -> dict
Compute all auto- and cross-power spectra for a tomographic session.
For N tomographic bins computes all N(N+1)/2 spectra in one call:
- N auto-spectra saved as results/spectra/cls_bin_{i:02d}_x_{i:02d}.json
- N(N-1)/2 cross-spectra saved as results/spectra/cls_bin_{i:02d}_x_{j:02d}.json (i < j)
Use this instead of calling compute_cls_from_session N times when you need
cross-spectra for tomographic SACC assembly. The auto-spectra are identical to
those produced by compute_cls_from_session(i, save_maps=True). Cross-spectra
load the saved HEALPix maps (requires save_maps=True, the default) and run a
NaMaster subprocess for each pair. Shot noise is zero for cross-spectra
(independent bins), so cls_denoised = pixel-window-corrected cls.
deproject_templates=[name, ...] applies the same named
manifest["systematics_templates"] deprojection to EVERY auto-spectrum bin
(see compute_cls_from_session). Cross-spectra are never deprojected.
Prerequisites: ingest_to_session must have run (manifest needed).
workspace_cache_scope: "session" (default) or "registry" — see
compute_cls_from_session; applied to both auto- and cross-spectra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory (manifest.json must exist). |
required |
save_maps
|
bool
|
Persist the HEALPix maps auto-spectra build (required for cross-spectra). |
True
|
deproject_templates
|
list[str] | None
|
Named templates to deproject from every auto-spectrum bin; cross-spectra are never deprojected. |
None
|
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 spectra |
dict
|
themselves. Poll |
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
compute_systematics_cls_from_session ¶
compute_systematics_cls_from_session(session_dir: str, bin_index: int, template_names: list[str] | None = None, jobspec: dict | None = None) -> dict
Cross-correlate a tomographic bin's field with ingested systematics templates (stellar density, seeing, dust, ...), using pipeline_config + manifest["systematics_templates"] as the sole parameter source.
Requires ingest_template_maps to have registered templates. If this bin's
saved field map(s) + mask are not yet on disk, this auto-runs
compute_cls_from_session(session_dir, bin_index, save_maps=True) first
(reported via maps_built).
template_names=None uses every ingested template; an unknown name returns needs_input listing the available ones.
Writes results/systematics/systematics_cls_bin_{bin_index:02d}.json: per-template {ells, cls_cross, max_abs_cl, spin}, plus a sigma_cl per-bandpower reference (from the bin's covariance sqrt_diag if present, else a Knox estimate) for later contamination-threshold checks. Registers a "systematics_cls" artefact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
bin_index
|
int
|
Tomographic bin index. |
required |
template_names
|
list[str] | None
|
Subset of ingested template names to cross-correlate
against; |
None
|
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
|
plus |
dict
|
template names if an unknown name was requested. |
Source code in cosmotron_mcp/server.py
run_bmode_null_tests_from_session ¶
run_bmode_null_tests_from_session(session_dir: str, significance: float = 0.01, jobspec: dict | None = None) -> dict
Run BB and EB null tests (H₀: Cℓ=0) for every spin-2 bin — a shear data check.
Uses cls_BB_denoised/cls_EB_denoised against the B-mode validation
covariance (built on demand) and run_null_test; registers a null_test
artefact per test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session directory. |
required |
significance
|
float
|
χ² significance threshold for the pass/fail verdict. |
0.01
|
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
|
verdict}], n_tests, n_fail} |
Source code in cosmotron_mcp/server.py
compute_systematics_cls ¶
compute_systematics_cls(delta_map: list, survey_mask: list, systematic_maps: dict[str, list], nside: int = 512, lmin: int = 10, lmax: int = 1000, n_bandpowers: int = 20, apodisation_scale: float = 0.5, spin: int = 0, field_maps_b: list | None = None) -> dict
Cross-correlate a HEALPix field with systematic template maps.
PREFER compute_systematics_cls_from_session — never hand-assemble
maps/masks for this low-level primitive.
Each systematic template is mean-subtracted over the survey footprint
before cross-correlation. Systematic templates are always spin-0 scalar
maps; the data field spin is controlled by the spin parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_map
|
list
|
HEALPix map consistent with |
required |
survey_mask
|
list
|
HEALPix survey mask consistent with |
required |
systematic_maps
|
dict[str, list]
|
Mapping of |
required |
nside
|
int
|
HEALPix resolution parameter, as in |
512
|
lmin
|
int
|
Minimum multipole, as in |
10
|
lmax
|
int
|
Maximum multipole, as in |
1000
|
n_bandpowers
|
int
|
Number of bandpowers, as in |
20
|
apodisation_scale
|
float
|
Mask apodisation scale, as in |
0.5
|
spin
|
int
|
Spin weight of the data field (0 or 2). |
0
|
field_maps_b
|
list | None
|
Second spin component (U-map) of the data field when
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict
|
This is a |
|
dict
|
cross-correlation is compute-node work, so it ALWAYS runs as a |
|
dict
|
non-blocking local background job, never inline (no |
|
dict
|
param — session-less, local job routing only). Returns an async |
|
dict
|
receipt ``{job_id, status, mode: "async", run_dir, session_dir, |
|
next |
dict
|
"check_job", ...} |
dict
|
root (this tool has no session of its own), NOT a pipeline session; |
|
dict
|
use the |
|
dict
|
|
|
dict
|
|
|
dict
|
|
|
dict
|
E-mode coupling for spin-2), |
|
dict
|
contamination diagnostic), |
Source code in cosmotron_mcp/server.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 | |
apply_template_deprojection ¶
apply_template_deprojection(delta_map: list, survey_mask: list, systematic_maps: dict[str, list], nside: int = 512, lmin: int = 10, lmax: int = 1000, n_bandpowers: int = 20, apodisation_scale: float = 0.5, spin: int = 0, field_maps_b: list | None = None, subtract_deprojection_bias: bool = False) -> dict
Remove systematic contamination via NaMaster template deprojection.
In a session, deprojection runs ONLY via
compute_cls_from_session(session_dir, bin_index, deproject_templates=[...])
— this low-level primitive is for CLI/script use with no session, and is
denied to every executing agent's tool map.
Constructs two NaMaster fields — one with contaminant templates (for deprojection) and one without (for comparison) — and returns the deprojected Cl estimates. Systematic templates are always spin-0 scalar maps; NaMaster supports cross-spin deprojection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_map
|
list
|
HEALPix map consistent with |
required |
survey_mask
|
list
|
HEALPix survey mask consistent with |
required |
systematic_maps
|
dict[str, list]
|
Mapping of |
required |
nside
|
int
|
HEALPix resolution parameter, as in |
512
|
lmin
|
int
|
Minimum multipole, as in |
10
|
lmax
|
int
|
Maximum multipole, as in |
1000
|
n_bandpowers
|
int
|
Number of bandpowers, as in |
20
|
apodisation_scale
|
float
|
Mask apodisation scale, as in |
0.5
|
spin
|
int
|
Spin weight of the data field (0 or 2). |
0
|
field_maps_b
|
list | None
|
Second spin component (U-map) of the data field when
|
None
|
subtract_deprojection_bias
|
bool
|
When |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict
|
This is a |
|
dict
|
(with/without templates) 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). Returns an async |
|
dict
|
receipt ``{job_id, status, mode: "async", run_dir, session_dir, |
|
next |
dict
|
"check_job", ...} |
dict
|
root (this tool has no session of its own), NOT a pipeline session; |
|
dict
|
use the |
|
dict
|
|
|
dict
|
|
|
dict
|
(np.ndarray — primary deprojected Cl, EE for spin-2), |
|
dict
|
(np.ndarray — Cls before deprojection), |
|
dict
|
|
|
dict
|
|
|
dict
|
(np.ndarray — BB deprojected, only when spin=2), |
|
dict
|
(np.ndarray — BB raw, only when spin=2). |
Source code in cosmotron_mcp/server.py
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 | |
run_null_test ¶
run_null_test(cls_array: list, cov_matrix: list, test_name: str = 'null_test', significance: float = 0.01, output_path: str | None = None, generated_by: str | None = None, agent_name: str | None = None) -> dict
Run a chi-squared null test: H₀: C_ell = 0.
Uses the full covariance matrix if provided, otherwise falls back to the diagonal. A result is flagged as FAIL if the p-value falls below the significance threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_array
|
list
|
1-D array of bandpower estimates to test against zero. |
required |
cov_matrix
|
list
|
2-D covariance matrix of shape
|
required |
test_name
|
str
|
Label for logging and the return dict. |
'null_test'
|
significance
|
float
|
p-value threshold below which the test is considered a failure. |
0.01
|
output_path
|
str | None
|
If provided, write the result JSON to this path. Omit to get the result dict only, without saving to disk. |
None
|
generated_by
|
str | None
|
Infrastructure kwarg — omit in normal usage; auto-populated from the executor environment. |
None
|
agent_name
|
str | None
|
Infrastructure kwarg — omit in normal usage; auto-populated from the executor environment. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
This is a |
dict
|
with its siblings, though it's cheap arithmetic on small |
dict
|
already-computed arrays) — ALWAYS runs as a non-blocking local |
dict
|
background job, never inline (no |
dict
|
local job routing only). Returns an async receipt ``{job_id, |
dict
|
status, mode: "async", run_dir, session_dir, next: "check_job", |
dict
|
...} |
dict
|
has no session of its own), NOT a pipeline session; use the |
dict
|
|
dict
|
|
dict
|
|
dict
|
(int), |
dict
|
(float), |
Source code in cosmotron_mcp/server.py
create_namaster_bins ¶
Create NaMaster bandpower bins using uniform bandwidth.
Always use lmax_bins (not requested lmax) when constructing NmtField objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lmin
|
int
|
Minimum multipole. |
required |
lmax
|
int
|
Maximum requested multipole. |
required |
bandwidth
|
int
|
Multipoles per bandpower bin. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|