How lsst-strong-lensing/slsim works
1. What this repository is
SLSim is a Python package for strong gravitational lensing simulation for Rubin/LSST-era science, with support for related survey configurations such as Roman, Euclid, and LSST-like setups. It is an object-oriented simulation framework rather than an app or service.
2. Core architectural shape
The code is organized as a set of domain subsystems under slsim/, with shared utilities underneath and survey-specific pipelines at the top. The main simulation flow is:
catalogs / parameter distributions → source and deflector populations → lens assembly → line-of-sight / halo effects → image simulation → survey-specific output.
3. Source modeling subsystem
slsim/Sources/ models the background objects being lensed. It is split into:
- SourceTypes: concrete source representations such as point sources, extended galaxies, quasars, supernova events, and hybrid point+extended sources.
- SourcePopulation: population builders that generate ensembles of sources.
- SourceCatalogues: adapters to external or curated catalogs, including COSMOS/HST COSMOS, quasar catalogs, supernova catalogs, and SkyPy-based galaxy catalogs.
- SourceVariability: time-domain behavior for AGN, sinusoidal variability, light-curve interpolation, and accretion-disk reprocessing.
- Supernovae: supernova-specific population and host-matching logic.
This layer is the main input side of the simulator.
4. Deflector / lens-plane modeling
slsim/Deflectors/ handles the foreground mass that produces the lensing:
- DeflectorTypes contains physical lens models such as EPL/EPL+Sérsic and NFW-based cluster/galaxy-halo forms.
- DeflectorPopulation builds populations of lens galaxies, elliptical lenses, cluster deflectors, and compound halo+galaxy deflectors.
- MassLightConnection provides empirical/analytic bridges between observables and mass: light-to-mass, richness-to-mass, velocity dispersion, and special DP0.2 massive deflector handling.
This subsystem is the main foreground mass boundary in the architecture.
5. Lens assembly and selection
slsim/Lenses/ combines sources and deflectors into complete lens systems. It defines the lens object model, lens populations, population-level base classes, and selection logic. This layer is where source-side and deflector-side objects become a single simulated lensing system.
6. Line-of-sight and halo effects
slsim/LOS/ and slsim/Halos/ add environmental structure beyond the main deflector:
- LOS modules model individual and population-level line-of-sight perturbations.
- Halo modules build halo populations, lens-halo interactions, ray-tracing, halo statistics, and Glass-based computations.
These are separate from the main lens plane and act as secondary gravitational contributions and statistical perturbations.
7. Image generation
slsim/ImageSimulation/ is the rendering boundary:
- image_simulation.py is the general image-generation layer.
- image_quality_lenstronomy.py suggests dependence on lensing/image-quality tooling from the lenstronomy ecosystem.
- roman_image_simulation.py is a survey-specific renderer for Roman-like images.
This subsystem consumes the assembled lens system plus observational assumptions and produces image-level outputs.
8. Survey and observing-pipeline integration
slsim/LsstSciencePipeline/ and slsim/Pipelines/ adapt the simulator to specific external survey workflows:
- LSST science pipeline utilities and OpSim-style cadence handling.
- Survey pipelines for SkyPy, SL-Hammocks, Roman speclite/filter handling, and halo-based inputs.
These modules are the main orchestration layer for converting science catalogs and survey metadata into simulation-ready inputs.
9. Microlensing branch
slsim/Microlensing/ is a separate physics branch for substructure/time-variable magnification:
- light curves,
- magnification maps,
- lens-model coupling,
- source morphology variants for AGN, Gaussian, and supernova-like sources.
This is a specialized side pipeline that can enrich time-domain lens simulations without being part of the core static lens flow.
10. False-positive simulations
slsim/FalsePositives/ models astrophysical impostors that can mimic lensing signals. This is architecturally distinct from true lens generation and likely serves classification, validation, and survey yield studies.
11. Shared utilities and parameterization
slsim/Util/ contains cross-cutting support:
- cosmology and astrophysical conversions,
- catalog utilities,
- magnitude/error handling,
- color and K-corrections,
- parameter distributions and Gaussian-mixture-based sampling,
- COOLEST interface helpers.
This layer is dependency support for most higher-level subsystems and is where common numerical assumptions are centralized.
12. Data and external assets
The data/ directory stores reusable reference assets: filters, SkyPy configuration files, COSMOS/SL-Hammocks/Glass inputs, redMaPPer examples, and DC2-like galaxy counts. These files are consumed by population builders, survey pipelines, and tutorials rather than by core runtime logic alone.
13. Documentation and validation workflow
The repo has a large docs/tutorial surface (docs/, notebooks/, tests/). The notebooks mirror major use cases: galaxy-galaxy lensing, cluster lenses, AGN variability, supernovae, microlensing, Roman configuration, and validation. The tests are structured to map almost one-to-one to package subsystems, which reflects the intended architectural boundaries.
14. Build, QA, and release boundary
Packaging is standard Python (setup.py, requirements*.txt, tox.ini, pre-commit, GitHub Actions). CI is focused on unit tests, style checks, and docs validation, indicating the repository’s primary contract is a scientific library with reproducible simulations rather than a deployed runtime system.
Main entry points: image_simulation.py Image sim · source_pop_base.py Populations · deflectors_base.py Lens pops · lens_pop.py Lensed pops
Components 21
Sources
Background source modeling, catalog adapters, and intrinsic variability.
- Source types · Concrete source object models for points, galaxies, quasars, supernovae, and composites.
slsim/Sources/SourceTypes/source_base.py - Catalogs · Adapters to COSMOS, quasar, supernova, and SkyPy-like source catalogs.
slsim/Sources/SourceCatalogues/skypy_galaxy_catalog.py - Populations · Factories for source ensembles such as galaxies, point sources, and point-plus-extended systems.
slsim/Sources/SourcePopulation/source_pop_base.py - Variability · AGN, sinusoidal, interpolation, and accretion-disk reprocessing variability models.
slsim/Sources/SourceVariability/variability.py - Supernovae · Supernova lightcone, host matching, and population logic.
slsim/Sources/Supernovae/supernovae_pop.py
Deflectors
Foreground lens-mass models and mass-light mappings.
- Lens types · Physical lens mass profiles including EPL, EPL+Sérsic, and NFW variants.
slsim/Deflectors/DeflectorTypes/deflector_base.py - Lens pops · Populations of galaxy, elliptical, cluster, and compound halo+galaxy deflectors.
slsim/Deflectors/DeflectorPopulation/deflectors_base.py - Mass-light · Bridges from observables to mass: light-to-mass, richness-to-mass, and velocity dispersion.
slsim/Deflectors/MassLightConnection/light2mass.py
Lens systems
Assembly of sources, deflectors, line-of-sight terms, halos, and false positives.
- Lens systems · Core lens object model that combines source and deflector into one system.
slsim/Lenses/lens.py - Lensed pops · Population-level lens assembly and base classes for lensed systems.
slsim/Lenses/lens_pop.py - Selection · Lens selection and sample curation logic.
slsim/Lenses/selection.py - Line of sight · Individual and population line-of-sight contributions to lensing.
slsim/LOS/los_individual.py - Halos · Halo populations, ray tracing, halo statistics, and Glass-based computations.
slsim/Halos/halos.py - False positives · Astrophysical non-lenses that mimic lensing signals.
slsim/FalsePositives/false_positive.py
Rendering & pipelines
Image generation and survey-specific orchestration.
- Image sim · General image-generation layer.
slsim/ImageSimulation/image_simulation.py - Roman renderer · Roman-specific image simulation boundary.
slsim/ImageSimulation/roman_image_simulation.py - LSST pipeline · LSST science pipeline integration and OpSim cadence handling.
slsim/LsstSciencePipeline/lsst_science_pipeline.py - Survey pipes · SkyPy, SL-Hammocks, Roman speclite, and halo-oriented survey workflows.
slsim/Pipelines/skypy_pipeline.py
Shared support
Cross-cutting utilities, parameterization, and reference assets.
- Utilities · Cosmology, catalog, magnitude, color, K-correction, and parameter helpers.
slsim/Util/astro_util.py - Param dist · Gaussian-mixture and other parameter-distribution utilities.
slsim/Util/ParamDistributions/gaussian_mixture_model.py - Data assets · Reusable survey, catalog, filter, halo, and validation inputs under data/.
data/SkyPy/lsst-like.yml
Connections 24
- Catalogs → Populations: seed · Catalog adapters populate source ensembles.
- Source types → Populations: instantiate · Concrete source types are assembled into populations.
- Variability → Source types: decorate · Variability augments time-dependent source objects.
- Supernovae → Populations: transients · Supernova-specific population logic feeds the source layer.
- Lens types → Lens pops: build · Physical lens models are grouped into deflector populations.
- Mass-light → Lens pops: calibrate · Mass-light mappings parameterize deflector populations.
- Populations → Lensed pops: provide sources · Source ensembles enter lens population assembly.
- Lens pops → Lensed pops: provide lenses · Deflector ensembles enter lens population assembly.
- Lensed pops → Lens systems: compose · Population assembly yields individual lens systems.
- Selection → Lensed pops: filter · Selection logic constrains the lens population.
- Line of sight → Lens systems: perturb · Line-of-sight structure modifies the lens system.
- Halos → Lens systems: add structure · Halo contributions augment the main lens model.
- False positives → Lensed pops: alternate sample · False positives form a parallel sample to true lenses.
- Lens systems → Image sim: render · Assembled lens systems are rendered into images.
- Image sim → Roman renderer: specialize · Roman rendering extends the generic image simulator.
- Image sim → LSST pipeline: observe · Survey cadence and pipeline context drive image generation.
- Survey pipes → Image sim: configure · Survey workflows feed simulation settings into rendering.
- Utilities → Populations: support · Shared numerical helpers support source population generation.
- Utilities → Lens pops: support · Shared utilities support deflector construction.
- Utilities → Image sim: support · Utility functions support rendering and calibration.
- Param dist → Lens pops: sample · Parameter distributions drive population sampling.
- Data assets → Catalogs: load · Reference catalog and filter assets feed source adapters.
- Data assets → Survey pipes: configure · Survey YAML and reference inputs configure pipelines.
- Data assets → Halos: initialize · Halo and Glass reference files seed halo computations.