GPU-accelerated weak lensing summary statistics with PyTorch
Project description
Weak Lensing Summary Statistics (PyTorch)
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 datacfis_example.py- Realistic CFIS-like simulationbatch_processing.py- Processing multiple maps efficiently
Jupyter Notebooks (notebooks/):
cuda_batch_demo.ipynb- GPU batch processing demonstrationdes_mock_demo.ipynb- DES mock catalog analysispycs_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b7eb87ed4c0bee614448033f82b822305114fb640cb22e0a4b152981649cde2
|
|
| MD5 |
b7ce915fb2d01a1fa15839e1daaef14d
|
|
| BLAKE2b-256 |
53dd43378b51e78e33e5a189acac5fb0c63280fa0a79346afd75270398fb1b35
|
Provenance
The following attestation bundles were made for wl_stats_torch-0.1.0.tar.gz:
Publisher:
publish.yml on AndreasTersenov/wl_stats_torch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wl_stats_torch-0.1.0.tar.gz -
Subject digest:
1b7eb87ed4c0bee614448033f82b822305114fb640cb22e0a4b152981649cde2 - Sigstore transparency entry: 640870433
- Sigstore integration time:
-
Permalink:
AndreasTersenov/wl_stats_torch@18f5cd083205651715653915735150632c85ccc0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AndreasTersenov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@18f5cd083205651715653915735150632c85ccc0 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
668170e4f0407f5a4960e1c798dd85eb1349b092c8923de430202c02d99a4c32
|
|
| MD5 |
4a9d795be079a34bbdc18499a9c81ae6
|
|
| BLAKE2b-256 |
a4a0af0cd5291427ca3c57662402d8ab7dc733fdc02fef6f3bc24dec200f5714
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wl_stats_torch-0.1.0-py3-none-any.whl -
Subject digest:
668170e4f0407f5a4960e1c798dd85eb1349b092c8923de430202c02d99a4c32 - Sigstore transparency entry: 640870446
- Sigstore integration time:
-
Permalink:
AndreasTersenov/wl_stats_torch@18f5cd083205651715653915735150632c85ccc0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/AndreasTersenov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@18f5cd083205651715653915735150632c85ccc0 -
Trigger Event:
release
-
Statement type: