Skip to content

Conversation

@nikhil-sarin
Copy link
Owner

Implement lensing as a pluggable effect similar to extinction, allowing any base model to be modified with time delays and magnifications from multiple lensed images. Supports all transient types including supernovae, kilonovae, afterglows, TDEs, and more.

Implement lensing as a pluggable effect similar to extinction, allowing any base model to be modified with time delays and magnifications from multiple lensed images. Supports all transient types including supernovae, kilonovae, afterglows, TDEs, and more.
@nikhil-sarin nikhil-sarin added the enhancement New feature or request label Nov 15, 2025
claude and others added 12 commits November 15, 2025 22:44
- Add unit tests for core lensing functions (_perform_lensing, _evaluate_lensing_model)
- Add integration tests for all lensing wrapper functions (supernova, kilonova, TDE, etc.)
- Add tests for multiple image configurations (2, 3, 4 images)
- Add tests for both flux_density and magnitude output formats
- Add get_lensing_priors() function for programmatic prior generation
- Add prior files for 2, 3, and 4 image lensing configurations
- Add tests for prior file loading and sampling
- Fix negative time handling by only evaluating base model for positive times
- Update test parameters to use appropriate time values larger than delays
- Fix _get_correct_function to handle callable base models properly
- Simplify spectra output to apply magnification only (no time delays in spectra mode)
- Use 'bessellb' band instead of 'ztfg' to avoid remote data fetching
The existing TestModels tests iterate over all .prior files in the main priors directory and expect matching model functions. Since lensing priors are effect parameters (like extinction), they belong in non_default_priors.
Add comprehensive tests for previously untested code paths:
- Spectra output mode with magnification sum
- Special base_model names (thin_shell_supernova, homologous_expansion_supernova)
- Additional wrapper functions (stellar_interaction, general_synchrotron, afterglow)
- Edge cases: empty arrays, large image counts, zero magnification, boundary conditions
- Model library verification and parameter handling tests

Increases test count from 34 to 52 tests in lensing_test.py (63 total with priors)
New tests cover:
- Error paths for invalid base_model types (non-string, non-callable)
- Integrated flux afterglow model type verification
- 5-image lensing systems (Einstein Cross + central image)
- Flux output format (not just flux_density)
- Core loop edge cases: nimages=0, simultaneous arrivals
- Staggered arrival patterns with multiple delayed images
- Module structure verification (functions exist, correct types)

Total tests increased to 78 (67 lensing_test + 11 priors)
New tests added:
- Direct _evaluate_lensing_model() testing with callable models
- Parameter removal verification (dt_i, mu_i stripped from base kwargs)
- Spectra output mode code path coverage (lines 187-227)
- Citation wrapper verification
- Complete base model list content checks
- Numerical precision tests (very small/large magnifications)

Total: 94 tests (83 lensing + 11 priors) - comprehensive coverage
The lensing_test.py and lensing_priors_test.py were not included in the
CI test matrix, so they weren't contributing to Coveralls coverage reports.
Added both test files to Group 4 (lighter tests) in the workflow.
Replace mock spectra tests that threw exceptions with real model tests
that execute the complete spectra code path (lines 187-227):
- Test 3-image spectra mode with supernova
- Test kilonova flux output through spectra path
- Test TDE magnitude output through spectra path

These tests ensure full execution of the magnification summation loop
and sed.get_correct_output_format_from_spectra() integration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants