Python Wrapper

The Cython extension module is named wlcovpy and exposes the wlcov class. The wrapper drives the same C core as the command-line executable.

Import

from wlcovpy import wlcov

Minimal Run

#!/usr/bin/env python3
"""Run a compact wlcov calculation through the Python wrapper."""

from wlcovpy import wlcov


model = wlcov(default=False)
model.set(
    {
        "clsfile": "tests/input/Cls_ep2.txt",
        "rootDir": "Output_python_example",
        "r": 0.01,
        "theta1": 0.01,
        "theta2": 0.012,
        "thetap1": 0.011,
        "thetap2": 0.013,
        "m": 0,
        "mp": 0,
        "ppp": 4,
        "ellmin": 1.0,
        "ellmax": 25.0,
        "Nr": 8,
        "rmin": 0.00232711,
        "rmax": 0.02,
        "numberThreads": 1,
        "verbose": 0,
        "verbose_log": 0,
        "options": "",
    }
)

try:
    cputime = model.Run()
finally:
    model.clean_all()

print(f"MainLoop CPU time: {cputime:.6g} s")

Run it from the repository root:

python3 docs/examples/python_wrapper.py

Wrapper Semantics

wlcov(default=False) constructs an empty model. Set all required runtime parameters with set before calling Run.

wlcov(default=True) pre-populates verbosity and thread parameters, but a scientific run should still set the geometry, integration range, input file, and output directory explicitly.

Run returns the measured MainLoop CPU time. The final radial integral is available with getIntegral after a successful run, and the C routines also print run diagnostics according to the verbosity settings.

Cleaning Up

Call clean_all after a run to release C-side state:

model = wlcov(default=False)
try:
    model.set(parameters)
    cputime = model.Run()
finally:
    model.clean_all()

Example Utilities

tests/python/kappa_cov.py runs one compact wrapper calculation and prints the returned integral. tests/python/covariance_example.py provides convenience functions that call the wrapper repeatedly and assemble covariance matrices in NumPy:

  • add_noise_to_column creates a noisy copy of a two-column input table;

  • calculate_integral runs one wlcovpy calculation and returns getIntegral;

  • build_mask and get_valid_indices define matrix entries to compute;

  • compute_cov_noise computes a symmetric covariance matrix and optionally writes it with numpy.savetxt.

See Notebook Covariance-Matrix Workflow for the main notebook example in tests/notebooks/example.ipynb and the matching command-line script run.

Current Limitations

The Python wrapper is intentionally thin. It does not yet expose individual intermediate arrays or structured numerical results. For production Python workflows, capture stdout or add dedicated C/Python accessors for the quantities needed by downstream analysis.