Skip to content

Work on cluster lensing, add LOS lens draw method to lens_pop.py, optimize _image_position_from_source for multi_plane="Source" lenses#434

Open
simonjs830 wants to merge 4 commits into
LSST-strong-lensing:mainfrom
simonjs830:main
Open

Work on cluster lensing, add LOS lens draw method to lens_pop.py, optimize _image_position_from_source for multi_plane="Source" lenses#434
simonjs830 wants to merge 4 commits into
LSST-strong-lensing:mainfrom
simonjs830:main

Conversation

@simonjs830

Copy link
Copy Markdown
Collaborator

No description provided.

…tes an entire field of source galaxies rather than only returning a single source

Optimized Lens._image_position_from_source for multi_plane="Source" lenses

Added option to have the Lens class automatically move source galaxies in front of deflector to field galaxieswq
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@simonjs830 simonjs830 changed the title Add multi-source lensing draw method Work on cluster lensing, add LOS lens draw method to lens_pop.py, optimize _image_position_from_source for multi_plane="Source" lenses Jun 15, 2026
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 15.00000% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.07%. Comparing base (47f9dd7) to head (4a78b69).

Files with missing lines Patch % Lines
slsim/Lenses/lens_pop.py 4.16% 46 Missing ⚠️
slsim/Lenses/lens.py 33.33% 4 Missing ⚠️
slsim/Pipelines/skypy_pipeline.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #434      +/-   ##
==========================================
- Coverage   98.65%   98.07%   -0.59%     
==========================================
  Files         106      106              
  Lines        8340     8398      +58     
==========================================
+ Hits         8228     8236       +8     
- Misses        112      162      +50     
Files with missing lines Coverage Δ
...flectors/DeflectorPopulation/cluster_deflectors.py 100.00% <100.00%> (ø)
slsim/Pipelines/skypy_pipeline.py 94.23% <75.00%> (-1.61%) ⬇️
slsim/Lenses/lens.py 98.46% <33.33%> (-0.51%) ⬇️
slsim/Lenses/lens_pop.py 68.87% <4.16%> (-30.16%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sibirrer sibirrer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @simonjs830!
I made some comments. You also see that you did not add tests. Let me know if you have questions!

Comment thread slsim/Lenses/lens.py
z_source_convention=self.max_redshift_source_class.redshift,
use_jax=use_jax,
multi_plane=bool(self.multi_plane),
multi_plane=bool(self.multi_plane) if multi_plane is None else multi_plane,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code works. Perhaps it is better to see how self.multi_plane is initialized and adapt that instead of additional criteria here

Comment thread slsim/Lenses/lens_pop.py Outdated
while True:
# draw random deflector
_deflector = self._lens_galaxies.draw_deflector()
cluster_id = _deflector._deflector._deflector_dict["cluster_id"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line of code seems only to work for clusters and accesses a private variable. This should be avoided. Do you need that?

Comment thread slsim/Lenses/lens_pop.py Outdated
_deflector = self._lens_galaxies.draw_deflector()
cluster_id = _deflector._deflector._deflector_dict["cluster_id"]

### compute smallest square containing all deflector subhalos, to avoid computing unnecessary caustics and source galaxies

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feature to calculate the influence area where to check for sources behind should be generalized and be part of the the Deflector() class

Comment thread slsim/Lenses/lens_pop.py Outdated
bbox = [[np.inf, -np.inf], [np.inf, -np.inf]]
max_dist = 20

for s in _deflector._deflector._subhalos:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, access to a private variable that may not be generally supported

Comment thread slsim/Lenses/lens_pop.py Outdated
if self._cached_caustics[cluster_id] == -1:
continue

ra_caustic_list, dec_caustic_list = self._cached_caustics[cluster_id]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you cache here the caustics for individual deflectors/clusters. Not sure this is needed, or you can generalize it to deflector IDs. The danger here is that this will use up a lot of memory when having many (potential) deflectors. Do you need to save the caustics or do you only need the area?

Comment thread slsim/Lenses/lens_pop.py Outdated
use_jax=self._use_jax,
)
lens_model_object, model_params = (
_dummy_lens.deflector_mass_model_lenstronomy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be a way that you don't need a dummy Lens() instance. You need the deflector model for a high-redshift source only

Comment thread slsim/Lenses/lens_pop.py Outdated
center_y=center[1],
compute_window=2 * radius,
# compute_window = 150,
grid_scale=2.0, # 0.5, #TODO experiment with grid_scale

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a 2 arc second grid you would not see images appearing closer than 2" together. I know this is expensive and might not be needed to quantify whether there are at least two images.

Comment thread slsim/Lenses/lens_pop.py
(ra_caustic_list - s.extended_source_position[0]) ** 2
+ (dec_caustic_list - s.extended_source_position[1]) ** 2
)
< 5**2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand that part

Comment thread slsim/Lenses/lens_pop.py
source_class=_source_cut,
cosmo=self.cosmo,
use_jax=self._use_jax,
multi_plane="Source",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might not be as general

@review-notebook-app

review-notebook-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

sibirrer commented on 2026-06-22T20:06:24Z
----------------------------------------------------------------

Line #1.    import slsim.Sources as sources

add a markdown sell above with a title, and a short description of what it does


@review-notebook-app

review-notebook-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

sibirrer commented on 2026-06-22T20:06:25Z
----------------------------------------------------------------

Line #2.    import slsim.Pipelines as pipelines

would be nice to have a bit more documentation of the code cells


@review-notebook-app

review-notebook-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

sibirrer commented on 2026-06-22T20:06:25Z
----------------------------------------------------------------

Line #1.    cluster_catalog = Table.read("../data/redMaPPer/clusters_example.fits")

describe this catalogue


@review-notebook-app

review-notebook-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

sibirrer commented on 2026-06-22T20:06:26Z
----------------------------------------------------------------

Line #1.    def debug_plot_objects(lens_cluster_class: Lens, ax):

remove "debug"


@review-notebook-app

review-notebook-app Bot commented Jun 22, 2026

Copy link
Copy Markdown

View / edit / reply to this conversation on ReviewNB

sibirrer commented on 2026-06-22T20:06:27Z
----------------------------------------------------------------

Line #1.    # for (lens_cluster_class, image_rgb) in saved_renders.keys():

can you label the axis in the plots (i.e. arcsec)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants