Skip to content

Latest commit

 

History

History
123 lines (96 loc) · 5.5 KB

File metadata and controls

123 lines (96 loc) · 5.5 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

LensTools is a scientific Python package for Weak Gravitational Lensing analysis used in astrophysics and cosmology research. It provides tools for convergence maps, shear analysis, N-body simulations, ray tracing, and statistical analysis of cosmic structure.

Development Commands

Installation and Build

# Modern installation (preferred method)
pip install -e .

# Or with dependencies from requirements file
pip install -r requirements.txt
pip install -e .

# Legacy installation with C extensions (if GSL/FFTW3 available)
python setup.py build_ext -i --gsl=/usr/local --fftw3=/usr/local  
python setup.py install --gsl=/usr/local --fftw3=/usr/local

Testing

# Test C extensions and NumPy 2.x compatibility (recommended)
python -m pytest test_cextensions.py -v

# Test specific working functionality
python -m pytest lenstools/tests/test_contours.py -v

# Run all tests (many require external data files and will fail)
python -m pytest lenstools/tests/ -v --tb=short

# Manual verification of C extensions
python -c "
import lenstools
from lenstools.extern import _topology, _gadget2, _nbody, _pixelize
import numpy as np
test_data = np.random.rand(50, 50).astype(np.float64)
grad = _topology.gradient(test_data, None, None)
print('✓ All C extensions working with NumPy', np.__version__)
"

Note on Testing: Most tests in lenstools/tests/ require external data files that are downloaded from Dropbox. The test_cextensions.py file provides comprehensive testing of C extensions and NumPy 2.x compatibility without external dependencies.

GitHub Actions CI/CD

The repository includes a comprehensive GitHub Actions workflow that tests:

  • All Python versions: 3.10 through 3.13
  • All dependencies: GSL, FFTW3, and all system dependencies installed
  • All C extensions enabled: Tests that all C extensions compile and work correctly
  • NumPy 2.x compatibility: Verifies C extensions work with modern NumPy
  • Pytest testing: Uses modern pytest framework for all tests

Modernization Status ✅ COMPLETE

The package has been successfully modernized with the following improvements:

  • Modern packaging: Added pyproject.toml with modern build system
  • NumPy 2.x compatibility: ✅ COMPLETE - All C extensions now work with NumPy 2.0+
  • Updated dependencies: Modern versions of scipy, matplotlib, astropy, emcee
  • C extensions: ✅ WORKING - All C extensions compile and run correctly
  • Cross-platform Python support: Python 3.10+ compatibility
  • Modern Python support: Requires Python 3.10 or later

C Extensions Status:

  • ✅ All C extensions (_topology, _gadget2, _nbody, _pixelize, _design, _nicaea) are enabled and working
  • ✅ NumPy 2.x C API compatibility issues resolved using compatibility macros
  • ✅ All PyArray_DATA, PyArray_DIM calls updated for NumPy 2.x

Testing & Compatibility:

  • ✅ All deprecated NumPy aliases (np.float, np.complex) have been updated
  • ✅ Database compatibility issues with pandas merges resolved
  • ✅ SQLAlchemy 2.0 compatibility implemented
  • ✅ All tests passing with NumPy 2.x and modern pandas
  • Minor: pkg_resources warnings can be addressed by migrating to importlib.resources

External Dependencies

The package requires these external C libraries:

  • GSL (GNU Scientific Library) - for mathematical functions
  • FFTW3 - for fast Fourier transforms
  • NICAEA (optional) - for cosmological calculations

Configure library paths in setup.cfg if not in /usr/local.

Architecture

Core Package Structure

  • image/ - Convergence maps, shear maps, flexion maps, CMB analysis
  • statistics/ - Ensemble analysis, constraints, contours, MCMC samplers
  • simulations/ - N-body simulation I/O (Gadget2, FastPM), ray tracing engine
  • catalog/ - Galaxy catalog handling and mock generation
  • pipeline/ - Simulation pipeline management, cluster computing, MPI support
  • observations/ - Real survey data handling (CFHT lens survey)
  • utils/ - FFT utilities, MPI helpers, algorithms
  • extern/ - C extensions for performance-critical computations
  • tests/ - Comprehensive test suite using nose framework

Key Classes and Concepts

  • ConvergenceMap - Primary class for weak lensing convergence field analysis
  • ShearMap/FlexionMap - Shear and higher-order lensing field handling
  • Catalog classes - Galaxy catalog management with astropy integration
  • Ensemble - Statistical ensemble analysis framework for parameter estimation
  • RayTracer - Ray tracing through simulated dark matter structures
  • Design - Optimal experimental design for cosmological surveys

External Integrations

  • N-body simulations: Gadget2, FastPM format support
  • Cosmological codes: CAMB, NICAEA parameter calculations
  • Observational data: CFHT lens survey, DES-like mock catalogs
  • Parallel computing: MPI support for cluster environments

Performance Features

  • C extensions in extern/ for computationally intensive operations (topology analysis, Gadget I/O, pixelization)
  • MPI parallelization throughout the codebase
  • Efficient FFT implementations via FFTW3
  • NumPy/SciPy vectorized operations

Testing Framework

Uses nose testing framework with coverage reporting. Tests are organized by functionality and located in lenstools/tests/. The CI system (Travis) runs tests on Python 3.6/3.7 with external library dependencies.