Skip to content

cosmotron_mcp.tools.maps

make_shear_map

make_shear_map(ra: list, dec: list, e1: list, e2: list, weights: list, nside: int = 512, chunk_rows: int = 5000000) -> dict

Project a weak-lensing shear catalogue onto HEALPix Q and U maps.

Each occupied pixel receives the weighted mean ellipticity components

Q[p] = sum(w_i * e1_i) / sum(w_i) U[p] = sum(w_i * e2_i) / sum(w_i)

Pixels with no objects are set to zero in Q, U, and the mask.

Parameters:

Name Type Description Default
ra list

Object right ascension in degrees.

required
dec list

Object declination in degrees.

required
e1 list

Per-galaxy first ellipticity component (must be finite; typically |e| <= 1).

required
e2 list

Per-galaxy second ellipticity component (must be finite; typically |e| <= 1).

required
weights list

Per-object weights (must be non-negative).

required
nside int

HEALPix resolution parameter (must be a power of two).

512
chunk_rows int

Row-chunk size for the pixel accumulation (bounds peak transient memory for large catalogues). Purely mechanical — bit-identical output for any value; only change it for very large catalogues.

5000000

Returns:

Type Description
dict

dict with keys: Q_map (np.ndarray, shape (npix,) — weighted

dict

mean e1 per pixel), U_map (np.ndarray, shape (npix,) — weighted

dict

mean e2 per pixel), survey_mask (np.ndarray, shape (npix,),

dict

float 0/1), n_bar (float — mean weighted count per occupied

dict

pixel), f_sky (float — fraction of sky covered), nside

dict

(int), npix (int), sigma_e (float — per-component weighted

dict

shape noise RMS), n_eff (float — effective number density

dict

[sr⁻¹], Heymans+2012), n_eff_arcmin2 (float — n_eff converted

dict

to [arcmin⁻²]).

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def make_shear_map(
    ra: list,
    dec: list,
    e1: list,
    e2: list,
    weights: list,
    nside: int = 512,
    chunk_rows: int = 5_000_000,
) -> dict:
    """Project a weak-lensing shear catalogue onto HEALPix Q and U maps.

    Each occupied pixel receives the weighted mean ellipticity components:
        Q[p] = sum(w_i * e1_i) / sum(w_i)
        U[p] = sum(w_i * e2_i) / sum(w_i)
    Pixels with no objects are set to zero in Q, U, and the mask.

    Args:
        ra: Object right ascension in degrees.
        dec: Object declination in degrees.
        e1: Per-galaxy first ellipticity component (must be finite;
            typically |e| <= 1).
        e2: Per-galaxy second ellipticity component (must be finite;
            typically |e| <= 1).
        weights: Per-object weights (must be non-negative).
        nside: HEALPix resolution parameter (must be a power of two).
        chunk_rows: Row-chunk size for the pixel accumulation (bounds peak
            transient memory for large catalogues). Purely mechanical —
            bit-identical output for any value; only change it for very
            large catalogues.

    Returns:
        ``dict`` with keys: ``Q_map`` (np.ndarray, shape (npix,) — weighted
        mean e1 per pixel), ``U_map`` (np.ndarray, shape (npix,) — weighted
        mean e2 per pixel), ``survey_mask`` (np.ndarray, shape (npix,),
        float 0/1), ``n_bar`` (float — mean weighted count per occupied
        pixel), ``f_sky`` (float — fraction of sky covered), ``nside``
        (int), ``npix`` (int), ``sigma_e`` (float — per-component weighted
        shape noise RMS), ``n_eff`` (float — effective number density
        [sr⁻¹], Heymans+2012), ``n_eff_arcmin2`` (float — `n_eff` converted
        to [arcmin⁻²]).
    """
    return _make_shear_map(ra, dec, e1, e2, weights, nside=nside, chunk_rows=chunk_rows)

make_healpix_map

make_healpix_map(ra: list, dec: list, weights: list, nside: int = 512, chunk_rows: int = 5000000) -> dict

Project a galaxy catalogue onto a HEALPix overdensity map.

Returns dict with delta_map, survey_mask, n_bar, f_sky, nside, npix. Note: delta_map and survey_mask are large numpy arrays serialised as lists. Prefer run_power_spectrum / compute_cls_from_session for end-to-end runs. Use this only when you need the raw map for downstream custom steps.

chunk_rows: row-chunk size for the pixel accumulation (bounds peak transient memory for large catalogues). Purely mechanical — bit-identical output for any value.

Parameters:

Name Type Description Default
ra list

Object right ascension in degrees.

required
dec list

Object declination in degrees.

required
weights list

Per-object weights.

required
nside int

HEALPix resolution parameter.

512
chunk_rows int

Row-chunk size for the pixel accumulation.

5000000

Returns:

Type Description
dict

dict with delta_map, survey_mask, n_bar, f_sky,

dict

nside, npix.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def make_healpix_map(
    ra: list,
    dec: list,
    weights: list,
    nside: int = 512,
    chunk_rows: int = 5_000_000,
) -> dict:
    """Project a galaxy catalogue onto a HEALPix overdensity map.

    Returns dict with delta_map, survey_mask, n_bar, f_sky, nside, npix.
    Note: delta_map and survey_mask are large numpy arrays serialised as lists.
    Prefer run_power_spectrum / compute_cls_from_session for end-to-end runs.
    Use this only when you need the raw map for downstream custom steps.

    chunk_rows: row-chunk size for the pixel accumulation (bounds peak transient
    memory for large catalogues). Purely mechanical — bit-identical output for
    any value.

    Args:
        ra: Object right ascension in degrees.
        dec: Object declination in degrees.
        weights: Per-object weights.
        nside: HEALPix resolution parameter.
        chunk_rows: Row-chunk size for the pixel accumulation.

    Returns:
        ``dict`` with ``delta_map``, ``survey_mask``, ``n_bar``, ``f_sky``,
        ``nside``, ``npix``.
    """
    return _make_healpix_map(ra, dec, weights, nside, chunk_rows=chunk_rows)

make_healpix_mask

make_healpix_mask(nside: int, mask_fits_path: str | None = None, full_sky: bool = False, apodise: bool = False, apodisation_scale: float = 0.5, apodisation_type: str = 'C1') -> dict

Load or construct a HEALPix mask, optionally apodise it.

Either full_sky=True or mask_fits_path must be provided.

Parameters:

Name Type Description Default
nside int

HEALPix resolution parameter.

required
mask_fits_path str | None

Path to a HEALPix mask FITS file.

None
full_sky bool

Use a full-sky mask of ones instead of loading a file.

False
apodise bool

Apply C1 mask apodisation.

False
apodisation_scale float

Apodisation scale in degrees.

0.5
apodisation_type str

NaMaster apodisation type (default "C1").

'C1'

Returns:

Type Description
dict

dict with mask (list), nside, npix, f_sky,

dict

apodised, full_sky.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def make_healpix_mask(
    nside: int,
    mask_fits_path: str | None = None,
    full_sky: bool = False,
    apodise: bool = False,
    apodisation_scale: float = 0.5,
    apodisation_type: str = "C1",
) -> dict:
    """Load or construct a HEALPix mask, optionally apodise it.

    Either full_sky=True or mask_fits_path must be provided.

    Args:
        nside: HEALPix resolution parameter.
        mask_fits_path: Path to a HEALPix mask FITS file.
        full_sky: Use a full-sky mask of ones instead of loading a file.
        apodise: Apply C1 mask apodisation.
        apodisation_scale: Apodisation scale in degrees.
        apodisation_type: NaMaster apodisation type (default ``"C1"``).

    Returns:
        ``dict`` with ``mask`` (list), ``nside``, ``npix``, ``f_sky``,
        ``apodised``, ``full_sky``.
    """
    return _make_healpix_mask(
        nside,
        mask_fits_path=mask_fits_path,
        full_sky=full_sky,
        apodise=apodise,
        apodisation_scale=apodisation_scale,
        apodisation_type=apodisation_type,
    )

make_namaster_field

make_namaster_field(delta_map: list, mask: list, lmax: int, templates: list | None = None, spin: int = 0, field_maps_b: list | None = None) -> dict

Validate parameters for a NaMaster field and return metadata.

Dry-run validation — does NOT return an NmtField (not JSON-serialisable). Call this to confirm delta_map/mask/lmax/templates are mutually consistent before committing to a full run_power_spectrum call.

Parameters:

Name Type Description Default
delta_map list

HEALPix map (Q/E component for spin-2).

required
mask list

HEALPix survey mask.

required
lmax int

Maximum multipole.

required
templates list | None

Optional systematics template maps to check for deprojection compatibility.

None
spin int

Field spin weight (0 or 2).

0
field_maps_b list | None

Second spin component (U-map) when spin=2.

None

Returns:

Type Description
dict

dict with nside, npix, lmax, spin,

dict

has_templates, n_templates.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def make_namaster_field(
    delta_map: list,
    mask: list,
    lmax: int,
    templates: list | None = None,
    spin: int = 0,
    field_maps_b: list | None = None,
) -> dict:
    """Validate parameters for a NaMaster field and return metadata.

    Dry-run validation — does NOT return an NmtField (not JSON-serialisable).
    Call this to confirm delta_map/mask/lmax/templates are mutually consistent
    before committing to a full run_power_spectrum call.

    Args:
        delta_map: HEALPix map (Q/E component for spin-2).
        mask: HEALPix survey mask.
        lmax: Maximum multipole.
        templates: Optional systematics template maps to check for
            deprojection compatibility.
        spin: Field spin weight (0 or 2).
        field_maps_b: Second spin component (U-map) when spin=2.

    Returns:
        ``dict`` with ``nside``, ``npix``, ``lmax``, ``spin``,
        ``has_templates``, ``n_templates``.
    """
    return _make_namaster_field(
        delta_map, mask, lmax,
        templates=templates,
        spin=spin,
        field_maps_b=field_maps_b,
    )

resample_healpix_map

resample_healpix_map(input_path: str, nside_out: int, output_path: str | None = None, is_mask: bool = False) -> dict

Up/downgrade a HEALPix map or mask to nside_out (deterministic ud_grade).

Use this when a supplied mask/map is at a DIFFERENT HEALPix resolution than the analysis nside (which is global, pinned in session_context.json). The session-driven power-spectrum and covariance tools already reconcile a mismatched mask automatically on read; call this only to materialise a resampled map on disk (e.g. register a mask at the session nside). If the input is already at nside_out it is returned unchanged (no file written).

Parameters:

Name Type Description Default
input_path str

Path to the input HEALPix map/mask FITS file.

required
nside_out int

Target HEALPix resolution.

required
output_path str | None

Destination path; defaults next to input_path when omitted.

None
is_mask bool

Use nearest-neighbour-safe resampling appropriate for a binary/weight mask rather than a continuous map.

False

Returns:

Type Description
dict

{output_path, nside_in, nside_out, npix, changed, is_mask}.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def resample_healpix_map(
    input_path: str,
    nside_out: int,
    output_path: str | None = None,
    is_mask: bool = False,
) -> dict:
    """Up/downgrade a HEALPix map or mask to ``nside_out`` (deterministic ud_grade).

    Use this when a supplied mask/map is at a DIFFERENT HEALPix resolution than the
    analysis ``nside`` (which is global, pinned in session_context.json). The
    session-driven power-spectrum and covariance tools already reconcile a
    mismatched mask automatically on read; call this only to materialise a
    resampled map on disk (e.g. register a mask at the session nside). If the input
    is already at ``nside_out`` it is returned unchanged (no file written).

    Args:
        input_path: Path to the input HEALPix map/mask FITS file.
        nside_out: Target HEALPix resolution.
        output_path: Destination path; defaults next to `input_path` when
            omitted.
        is_mask: Use nearest-neighbour-safe resampling appropriate for a
            binary/weight mask rather than a continuous map.

    Returns:
        ``{output_path, nside_in, nside_out, npix, changed, is_mask}``.
    """
    return _resample_healpix_map(input_path, nside_out,
                                 output_path=output_path, is_mask=is_mask)