cosmotron_mcp.tools.io¶
save_covariance ¶
save_covariance(cov_result: dict, output_path: str, bin_index: int | None = None, generated_by: str | None = None, agent_name: str | None = None) -> dict
Save a covariance result dict to JSON with provenance and auto-registration.
Accepts the direct output of compute_covariance. Numpy arrays (covariance, ells, sqrt_diag, cls_theory) are serialised to lists automatically. The caller's dict is never mutated.
Auto-registers in artefact_registry.json when output_path is inside a results/ subdirectory. Carries bin_index so the dashboard can pair this entry with its matching cls_json artefact for error-bar and theory-Cl overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cov_result
|
dict
|
Output dict from |
required |
output_path
|
str
|
Destination JSON path. |
required |
bin_index
|
int | None
|
Tomographic bin index — used to link with the cls_json artefact. |
None
|
generated_by
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
agent_name
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
save_power_spectrum ¶
save_power_spectrum(cls_result: dict, output_path: str, generated_by: str | None = None, agent_name: str | None = None) -> dict
Save a power spectrum result dict to a JSON file.
Creates parent dirs, writes a _provenance block, and auto-registers the artefact in artefact_registry.json when output_path is inside a results/ subdirectory. The caller's dict is never mutated.
The optional generated_by and agent_name kwargs are auto-populated by the executor — omit them in all normal script usage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_result
|
dict
|
Power-spectrum result dict to save. |
required |
output_path
|
str
|
Destination JSON path. |
required |
generated_by
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
agent_name
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in cosmotron_mcp/server.py
save_healpix_map ¶
save_healpix_map(healpix_map: list, output_path: str, role: str = 'delta_map', nside: int | None = None, generated_by: str | None = None, agent_name: str | None = None, overwrite: bool = True) -> dict
Save a HEALPix map to a FITS file with provenance headers and auto-registration.
Creates the parent directory if needed, writes provenance FITS header keywords, and auto-registers the artefact in artefact_registry.json when output_path is inside a results/ subdirectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
healpix_map
|
list
|
1-D HEALPix map as a list or np.ndarray. |
required |
output_path
|
str
|
Destination FITS file path. |
required |
role
|
str
|
One of |
'delta_map'
|
nside
|
int | None
|
HEALPix NSIDE. Inferred from map length if not supplied. |
None
|
generated_by
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
agent_name
|
str | None
|
Infrastructure kwarg — omit in normal script usage. |
None
|
overwrite
|
bool
|
Overwrite an existing file. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
save_data_vector_sacc ¶
save_data_vector_sacc(output_path: str, tracers: list[dict], data_points: list[dict], covariance: list[list[float]] | None = None, overwrite: bool = True, session_dir: str | None = None) -> dict
Save a SACC data vector to a FITS file with Firecrown-compatible conventions.
PREFER assemble_sacc_from_session for standard clustering/shear
sessions. Call this directly ONLY for CMB-lensing or shear×density
cross-types with no composite tool.
GATED when the output lands inside a session. This tool takes an
output_path, not a session_dir, so it used to be the one route to a FITS
data vector that bypassed BOTH the plan gate and the systematics gate that
assemble_sacc_from_session enforces. Writing into workspace/<session>/
now requires session_dir and passes those gates; a path outside any
session (the genuine standalone use) is unaffected.
Supports NZ (galaxy clustering: lens0/lens1, weak lensing: src0/src1), Map (CMB lensing: cmbk), and NuMap (frequency maps: B20_T/B20_P) tracers.
Tracer names MUST follow Firecrown patterns: lens0/src0/cmbk/etc. Data type strings MUST use Firecrown measurement strings (e.g. "galaxy_density_cl", "galaxy_shearDensity_cl_e"), NOT raw spin strings (cl_00, cl_0e). Tracer pair ordering must satisfy Firecrown enum ordering: CMB < Clusters < src (SHEAR_E) < lens (COUNTS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str
|
Path for the output FITS file. |
required |
tracers
|
list[dict]
|
Each dict must have a NZ tracer (galaxy clustering / weak lensing):: Map tracer (CMB lensing):: NuMap tracer (frequency map):: |
required |
data_points
|
list[dict]
|
Each dict must contain: |
required |
covariance
|
list[list[float]] | None
|
Full covariance matrix as a 2D list; omitted if |
None
|
overwrite
|
bool
|
Overwrite an existing file. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 | |
find_file ¶
Search recursively for a file by name under search_dir.
Useful when the exact path is uncertain (e.g. after DataIngestor writes to a session directory whose name was not communicated to downstream agents). Returns the path of the lexicographically first match found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Base filename to search for, e.g.
|
required |
search_dir
|
str
|
Root directory to search under. |
'workspace'
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
|
dict
|
|
Source code in cosmotron_mcp/server.py
read_session_context_tool ¶
Read session_context.json from the given session directory.
Returns the full session_context dict including pipeline_config. Use this at the start of every analysis task to obtain the authoritative nside, lmax, lmin, n_bandpowers, bandwidth, apodise_mask, and full_sky.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If session_context.json is missing (i.e. DataIngestor has not yet completed). |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session workspace directory. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The full session_context dict, including |
Source code in cosmotron_mcp/server.py
register_artefact ¶
register_artefact(session_dir: str, artefact_type: str, artefact_path: str, generated_by: str | None = None, agent_name: str | None = None, bin_index: int | None = None, metadata: dict | None = None) -> dict
Register a result artefact in the session artefact registry.
Only needed for artefacts NOT produced by save_power_spectrum, run_null_test, or compute_covariance — those three auto-register when output_path is inside results/. Use register_artefact for: HEALPix maps, SACC files, custom plots, or any output file not written by a pipeline tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session workspace directory. |
required |
artefact_type
|
str
|
One of: |
required |
artefact_path
|
str
|
Path to the artefact, relative to |
required |
generated_by
|
str | None
|
Script path (optional — auto-populated from the executor env if absent). |
None
|
agent_name
|
str | None
|
Agent name (optional — defaults to |
None
|
bin_index
|
int | None
|
Tomographic bin index, or |
None
|
metadata
|
dict | None
|
Type-specific extra fields dict (e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in cosmotron_mcp/server.py
get_provenance ¶
Return the pipeline_config_provenance dict from session_context.json. Returns an empty dict if provenance was not recorded (legacy sessions). Use this to check whether a parameter was user-specified before modifying it in a script.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_dir
|
str
|
Session workspace directory. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The |
dict
|
sessions that predate provenance recording. |
Source code in cosmotron_mcp/server.py
load_text_columns ¶
Read a plain-text columnar file (.dat/.txt/.csv) as JSON columns.
The canonical way to read n(z) / theory Cℓ files — the opencode read tool
rejects .dat as binary. Never use read on data files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the text file. |
required |
max_rows
|
int | None
|
Optional cap on the number of rows read. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
dict
|
(one list per column). |