Skip to main content

GPU-accelerated weak lensing summary statistics with PyTorch

Project description

Weak Lensing Summary Statistics (PyTorch)

Tests Lint Documentation codecov PyPI version Python 3.8+ License: MIT

A GPU-accelerated PyTorch implementation for computing weak lensing summary statistics including:

  • Mono-scale peak counts
  • Wavelet (Starlet) peak counts
  • Wavelet L1-norm

This package provides a fast, pure-Python alternative to the C++-dependent CosmoStat implementation, with full GPU support via PyTorch.

Features

  • GPU Acceleration: All operations are PyTorch-based and can run on CUDA devices
  • No C++ Dependencies: Pure Python implementation, no compilation required
  • Batch Processing: Efficiently process multiple maps simultaneously
  • Memory Efficient: Optimized for large-scale cosmological simulations

Installation

pip install -e .

Or with development dependencies:

pip install -e ".[dev]"

Quick Start

import torch
from wl_stats_torch import WLStatistics

# Initialize with device (cpu or cuda)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
stats = WLStatistics(n_scales=5, device=device)

# Your convergence map and noise map
kappa_map = torch.randn(512, 512, device=device)
sigma_map = torch.ones(512, 512, device=device) * 0.01

# Compute statistics
results = stats.compute_all_statistics(
    kappa_map, 
    sigma_map,
    min_snr=-2, 
    max_snr=6, 
    nbins=31
)

# Access results
peak_counts = results['wavelet_peak_counts']  # Peak counts per scale
l1_norms = results['wavelet_l1_norms']  # L1-norms per scale
mono_peaks = results['mono_peak_counts']  # Mono-scale peak counts

Components

Starlet Transform

2D à trous wavelet transform with B3-spline kernel:

from wl_stats_torch.starlet import Starlet2D

starlet = Starlet2D(n_scales=5)
wavelet_coeffs = starlet(image)  # Returns (n_scales, H, W)

Peak Detection

Fast vectorized peak detection:

from wl_stats_torch.peaks import find_peaks_2d

peak_positions, peak_heights = find_peaks_2d(
    image, 
    threshold=3.0,
    mask=mask
)

Full Statistics Pipeline

from wl_stats_torch import WLStatistics

stats = WLStatistics(n_scales=5)
results = stats.compute_all_statistics(kappa, sigma)

Examples

See the examples/ directory for Python scripts and notebooks/ for Jupyter notebooks:

Python Scripts (examples/):

  • basic_usage.py - Simple example with synthetic data
  • cfis_example.py - Realistic CFIS-like simulation
  • batch_processing.py - Processing multiple maps efficiently

Jupyter Notebooks (notebooks/):

  • cuda_batch_demo.ipynb - GPU batch processing demonstration
  • des_mock_demo.ipynb - DES mock catalog analysis
  • pycs_demo.ipynb - PyCS integration example

Documentation

  • 📖 User Guide: See docs-md/ directory for detailed documentation
  • 🚀 Quick Start: docs-md/QUICKSTART.md
  • 📦 Installation: docs-md/INSTALL.md
  • 🔧 Contributing: docs-md/CONTRIBUTING.md
  • 🔍 API Reference: docs-md/API.md
  • Test Fixes: docs-md/TEST_FIXES.md

Build the full documentation with Sphinx:

make docs
# Open docs/_build/html/index.html

Citation

If you use this code, please cite:

  • Original CosmoStat package and relevant papers
  • This PyTorch implementation

License

MIT License - See LICENSE file

Authors

Andreas Tersenov

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wl_stats_torch-0.1.0.tar.gz (11.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wl_stats_torch-0.1.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file wl_stats_torch-0.1.0.tar.gz.

File metadata

  • Download URL: wl_stats_torch-0.1.0.tar.gz
  • Upload date:
  • Size: 11.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wl_stats_torch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b7eb87ed4c0bee614448033f82b822305114fb640cb22e0a4b152981649cde2
MD5 b7ce915fb2d01a1fa15839e1daaef14d
BLAKE2b-256 53dd43378b51e78e33e5a189acac5fb0c63280fa0a79346afd75270398fb1b35

See more details on using hashes here.

Provenance

The following attestation bundles were made for wl_stats_torch-0.1.0.tar.gz:

Publisher: publish.yml on AndreasTersenov/wl_stats_torch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wl_stats_torch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wl_stats_torch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wl_stats_torch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 668170e4f0407f5a4960e1c798dd85eb1349b092c8923de430202c02d99a4c32
MD5 4a9d795be079a34bbdc18499a9c81ae6
BLAKE2b-256 a4a0af0cd5291427ca3c57662402d8ab7dc733fdc02fef6f3bc24dec200f5714

See more details on using hashes here.

Provenance

The following attestation bundles were made for wl_stats_torch-0.1.0-py3-none-any.whl:

Publisher: publish.yml on AndreasTersenov/wl_stats_torch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page