# lsst-strong-lensing/slsim architecture

> Architecture diagram of the GitHub repository lsst-strong-lensing/slsim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lsst-strong-lensing/slsim
- Repository: https://github.com/lsst-strong-lensing/slsim

## Overview

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: [`slsim/ImageSimulation/image_simulation.py`](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/ImageSimulation/image_simulation.py) (Image sim), [`slsim/Sources/SourcePopulation/source_pop_base.py`](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourcePopulation/source_pop_base.py) (Populations), [`slsim/Deflectors/DeflectorPopulation/deflectors_base.py`](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/DeflectorPopulation/deflectors_base.py) (Lens pops), [`slsim/Lenses/lens_pop.py`](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/lens_pop.py) (Lensed pops)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_sources["Sources"]
  node_sources_base["Source types<br/>domain models<br/>[source_base.py]"]
  node_sources_catalogs["Catalogs<br/>catalog adapters"]
  node_sources_pop["Populations<br/>population builders<br/>[source_pop_base.py]"]
  node_sources_variability["Variability<br/>time-domain models<br/>[variability.py]"]
  node_sources_sn["Supernovae<br/>transient models<br/>[supernovae_pop.py]"]
end

subgraph group_grp_deflectors["Deflectors"]
  node_deflector_types["Lens types<br/>mass models<br/>[deflector_base.py]"]
  node_deflector_pop["Lens pops<br/>population builders<br/>[deflectors_base.py]"]
  node_mass_light["Mass-light<br/>scaling relations<br/>[light2mass.py]"]
end

subgraph group_grp_lensing["Lens systems"]
  node_lens_model["Lens systems<br/>system model<br/>[lens.py]"]
  node_lens_pop["Lensed pops<br/>population assembly<br/>[lens_pop.py]"]
  node_selection["Selection<br/>filtering logic<br/>[selection.py]"]
  node_los["Line of sight<br/>perturbations<br/>[los_individual.py]"]
  node_halos["Halos<br/>environment models<br/>[halos.py]"]
  node_false_pos["False positives<br/>impostor models<br/>[false_positive.py]"]
end

subgraph group_grp_rendering["Rendering & pipelines"]
  node_image_sim["Image sim<br/>rendering"]
  node_roman_img["Roman renderer<br/>survey renderer"]
  node_lsst_pipe["LSST pipeline<br/>survey integration"]
  node_survey_pipes["Survey pipes<br/>workflow adapters<br/>[skypy_pipeline.py]"]
end

subgraph group_grp_support["Shared support"]
  node_util["Utilities<br/>shared support<br/>[astro_util.py]"]
  node_param_dist["Param dist<br/>sampling helpers"]
  node_assets[("Data assets<br/>reference data<br/>[lsst-like.yml]")]
end

node_sources_catalogs -->|"seed"| node_sources_pop
node_sources_base -->|"instantiate"| node_sources_pop
node_sources_variability -->|"decorate"| node_sources_base
node_sources_sn -->|"transients"| node_sources_pop
node_deflector_types -->|"build"| node_deflector_pop
node_mass_light -->|"calibrate"| node_deflector_pop
node_sources_pop -->|"provide sources"| node_lens_pop
node_deflector_pop -->|"provide lenses"| node_lens_pop
node_lens_pop -->|"compose"| node_lens_model
node_selection -->|"filter"| node_lens_pop
node_los -->|"perturb"| node_lens_model
node_halos -->|"add structure"| node_lens_model
node_false_pos -->|"alternate sample"| node_lens_pop
node_lens_model -->|"render"| node_image_sim
node_image_sim -->|"specialize"| node_roman_img
node_image_sim -->|"observe"| node_lsst_pipe
node_survey_pipes -->|"configure"| node_image_sim
node_util -->|"support"| node_sources_pop
node_util -->|"support"| node_deflector_pop
node_util -->|"support"| node_image_sim
node_param_dist -->|"sample"| node_deflector_pop
node_assets -->|"load"| node_sources_catalogs
node_assets -->|"configure"| node_survey_pipes
node_assets -->|"initialize"| node_halos

click node_sources_base "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceTypes/source_base.py"
click node_sources_catalogs "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceCatalogues/skypy_galaxy_catalog.py"
click node_sources_pop "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourcePopulation/source_pop_base.py"
click node_sources_variability "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceVariability/variability.py"
click node_sources_sn "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/Supernovae/supernovae_pop.py"
click node_deflector_types "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/DeflectorTypes/deflector_base.py"
click node_deflector_pop "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/DeflectorPopulation/deflectors_base.py"
click node_mass_light "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/MassLightConnection/light2mass.py"
click node_lens_model "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/lens.py"
click node_lens_pop "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/lens_pop.py"
click node_selection "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/selection.py"
click node_los "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/LOS/los_individual.py"
click node_halos "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Halos/halos.py"
click node_false_pos "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/FalsePositives/false_positive.py"
click node_image_sim "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/ImageSimulation/image_simulation.py"
click node_roman_img "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/ImageSimulation/roman_image_simulation.py"
click node_lsst_pipe "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/LsstSciencePipeline/lsst_science_pipeline.py"
click node_survey_pipes "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Pipelines/skypy_pipeline.py"
click node_util "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Util/astro_util.py"
click node_param_dist "https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Util/ParamDistributions/gaussian_mixture_model.py"
click node_assets "https://github.com/lsst-strong-lensing/slsim/blob/main/data/SkyPy/lsst-like.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sources_base,node_sources_catalogs,node_sources_pop,node_sources_variability,node_sources_sn toneBlue
class node_deflector_types,node_deflector_pop,node_mass_light toneAmber
class node_lens_model,node_lens_pop,node_selection,node_los,node_halos,node_false_pos toneMint
class node_image_sim,node_roman_img,node_lsst_pipe,node_survey_pipes toneRose
class node_util,node_param_dist,node_assets toneIndigo
```

## Components

### Sources

Background source modeling, catalog adapters, and intrinsic variability.

- [Source types](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceTypes/source_base.py): domain models · Concrete source object models for points, galaxies, quasars, supernovae, and composites. · `slsim/Sources/SourceTypes/source_base.py`
- [Catalogs](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceCatalogues/skypy_galaxy_catalog.py): catalog adapters · Adapters to COSMOS, quasar, supernova, and SkyPy-like source catalogs. · `slsim/Sources/SourceCatalogues/skypy_galaxy_catalog.py`
- [Populations](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourcePopulation/source_pop_base.py): population builders · Factories for source ensembles such as galaxies, point sources, and point-plus-extended systems. · `slsim/Sources/SourcePopulation/source_pop_base.py`
- [Variability](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/SourceVariability/variability.py): time-domain models · AGN, sinusoidal, interpolation, and accretion-disk reprocessing variability models. · `slsim/Sources/SourceVariability/variability.py`
- [Supernovae](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Sources/Supernovae/supernovae_pop.py): transient models · Supernova lightcone, host matching, and population logic. · `slsim/Sources/Supernovae/supernovae_pop.py`

### Deflectors

Foreground lens-mass models and mass-light mappings.

- [Lens types](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/DeflectorTypes/deflector_base.py): mass models · Physical lens mass profiles including EPL, EPL+Sérsic, and NFW variants. · `slsim/Deflectors/DeflectorTypes/deflector_base.py`
- [Lens pops](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/DeflectorPopulation/deflectors_base.py): population builders · Populations of galaxy, elliptical, cluster, and compound halo+galaxy deflectors. · `slsim/Deflectors/DeflectorPopulation/deflectors_base.py`
- [Mass-light](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Deflectors/MassLightConnection/light2mass.py): scaling relations · 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](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/lens.py): system model · Core lens object model that combines source and deflector into one system. · `slsim/Lenses/lens.py`
- [Lensed pops](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/lens_pop.py): population assembly · Population-level lens assembly and base classes for lensed systems. · `slsim/Lenses/lens_pop.py`
- [Selection](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Lenses/selection.py): filtering logic · Lens selection and sample curation logic. · `slsim/Lenses/selection.py`
- [Line of sight](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/LOS/los_individual.py): perturbations · Individual and population line-of-sight contributions to lensing. · `slsim/LOS/los_individual.py`
- [Halos](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Halos/halos.py): environment models · Halo populations, ray tracing, halo statistics, and Glass-based computations. · `slsim/Halos/halos.py`
- [False positives](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/FalsePositives/false_positive.py): impostor models · Astrophysical non-lenses that mimic lensing signals. · `slsim/FalsePositives/false_positive.py`

### Rendering & pipelines

Image generation and survey-specific orchestration.

- [Image sim](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/ImageSimulation/image_simulation.py): rendering · General image-generation layer. · `slsim/ImageSimulation/image_simulation.py`
- [Roman renderer](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/ImageSimulation/roman_image_simulation.py): survey renderer · Roman-specific image simulation boundary. · `slsim/ImageSimulation/roman_image_simulation.py`
- [LSST pipeline](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/LsstSciencePipeline/lsst_science_pipeline.py): survey integration · LSST science pipeline integration and OpSim cadence handling. · `slsim/LsstSciencePipeline/lsst_science_pipeline.py`
- [Survey pipes](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Pipelines/skypy_pipeline.py): workflow adapters · 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](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Util/astro_util.py): shared support · Cosmology, catalog, magnitude, color, K-correction, and parameter helpers. · `slsim/Util/astro_util.py`
- [Param dist](https://github.com/lsst-strong-lensing/slsim/blob/main/slsim/Util/ParamDistributions/gaussian_mixture_model.py): sampling helpers · Gaussian-mixture and other parameter-distribution utilities. · `slsim/Util/ParamDistributions/gaussian_mixture_model.py`
- [Data assets](https://github.com/lsst-strong-lensing/slsim/blob/main/data/SkyPy/lsst-like.yml): reference data · Reusable survey, catalog, filter, halo, and validation inputs under data/. · `data/SkyPy/lsst-like.yml`

## Connections

- 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.
