Skip to main content

cosmic-metrics

Per-observation quality metrics for NenuFAR Cosmic Dawn data. Read QUALITY statistics, calibration solutions, power spectra, horizon-filtered variance and the TEC fluctuations seen by nearby GNSS stations; inspect the resulting table, reject poor blocks and compute pspipe weights.

Documentation: Read the Docs

Cosmic Metrics object and data flow

How the objects work together explains the diagram.

Install

Requires Python 3.10+ and the NenuFAR processing stack (aoquality, ps_eor, pspipe), installed with it from PyPI:

python -m pip install cosmic-metrics

From a checkout, use python -m pip install -e . with the same extras.

Python workflow

A Dataset contains observation blocks, named source readers and a managed raw cache. Metric objects define calculations. compute_metrics() returns an independent MetricTable containing scalars and observation metadata.

import cosmic_metrics as cm
from cosmic_metrics import metrics as m

dataset = cm.Dataset.from_toml('metrics.toml')
noise = m.RegionPower('dt_V', **m.REG_B)
phase = m.PhaseChange(120, source='solutions_l2a')
table = dataset.compute_metrics([noise, phase], n_workers=1)
print(table.df)
print(table.missing_reasons)

# Example threshold only; choose science cuts for your dataset.
selection = table.select_blocks([
    cm.Rule(phase.name, '>', 3, scale='mad'),
], missing='reject')
weights = table.compute_weights(noise.name, selection=selection)
table.save('metrics.csv')
selection.save('selection.json', weights=weights)

print(dataset.cache.inspect())
preview = dataset.cache.clear(stale_only=True, dry_run=True)

Adapt examples/nt04_l3.toml to your input paths and save it as metrics.toml. QUALITY and calibration templates are resolved per block; source names choose which reader a metric uses. All block times are UTC MJD seconds. Cache validity uses exact time bounds and dependency signatures. For scripts with n_workers > 1, use a main guard.

Prepare the expensive raw arrays using only the dataset TOML, without defining metrics:

cosmic-metrics cache populate metrics.toml --dry-run
cosmic-metrics cache populate metrics.toml
cosmic-metrics cache status metrics.toml

The example uses Slurm/libpipe; set [worker].nodes="localhost" for local population, or use SSH host names/ranges. The CLI accepts the same host and worker overrides as nenucal, for example --hosts localhost --max-concurrent 4. It runs in the foreground; use a persistent terminal session for unattended work. Use --slurm-nodes 4 to override the Slurm allocation size for one run while retaining the account, partition and other Slurm options from the TOML. Valid cache entries are skipped; use --force to rebuild them explicitly. [cache].require=true makes later notebook computations raise on missing/stale PS or variance entries. QUALITY and calibration remain uncached. Run population before the Python example when using that configuration. See cache preparation for worker settings, progress logs and resuming interrupted jobs.

Command-line workflow

The dataset TOML can also define the metrics ([[metrics]]), selection stages ([[selection]]), an output directory and a report repository, so that no Python is needed:

cosmic-metrics compute metrics.toml --dry-run   # list blocks and metric columns
cosmic-metrics compute metrics.toml             # metrics.csv
cosmic-metrics groups metrics.toml              # optional: groups of failing metrics
cosmic-metrics select metrics.toml              # selection.json
cosmic-metrics publish metrics.toml             # push them to the report repository

The report repository builds the interactive pages from the published files. See the command-line guide.

For RFI checks in a specific frequency band, configure a variance source and compute m.BandVariance((67, 68)) or m.BandVarianceRatio((67, 68)). These reduce the horizon-filtered channel variance around 67–68 MHz; the ratio uses dt_V as its noise reference. See the band-variance guide for units, filtering and interpretation.

Documentation

Start with the complete synthetic example, which needs no input data. The guide and generated API reference cover the current implementation:

The earlier metrics prototype is retained on the eric-prototype branch.

Validate and build docs

python -m pip install -e '.[dev,docs]'
python -m pytest
python -m ruff check .
python -m sphinx -W --keep-going -b html docs docs/_build/html

Metadata

Release files for cosmic-metrics 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cosmic-metrics 0.3.1
File Size Uploaded Provenance Actions
cosmic_metrics-0.3.1.tar.gz 74.9 kB Without provenance Details for cosmic_metrics-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cosmic-metrics 0.3.1
File Interpreter ABI Platform Actions
cosmic_metrics-0.3.1-py3-none-any.whl Python 3 none any Details for cosmic_metrics-0.3.1-py3-none-any.whl

Total release size: 162.7 kB

Release files / cosmic_metrics-0.3.1.tar.gz

Download URL cosmic_metrics-0.3.1.tar.gz
Size 74.9 kB
Tags Source
SHA-256 checksum
How to use checksums
78f60dac0b5f1f9287478738515b878ff893bc23c67fe832acc3aadeeb027370
BLAKE2b-256 checksum
How to use checksums
9fd7707b3fa52cf89606e7ac49113faaa5bdb3ebadf5cba52d08232d6d902ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.4 Linux/7.3.0-10-generic

Release files / cosmic_metrics-0.3.1-py3-none-any.whl

Download URL cosmic_metrics-0.3.1-py3-none-any.whl
Size 87.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9056866c91023cec98000d557975c9f950e1b29a946cedcbb1422105019923ee
BLAKE2b-256 checksum
How to use checksums
8926f21a8dc7422ca5ba806f04a2912f5a10b0c0722c6f395917413b29c57ea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.4 Linux/7.3.0-10-generic

Security for cosmic-metrics 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page