Skip to content

Commit 8cf7041

Browse files
Jammy2211claude
authored andcommitted
Remove duplicated critical curve/caustic helpers from autolens
- Delete tracer_util.critical_curves_from, caustics_from, lines_of_planes_from (all unused outside plot code; duplicated LensCalc logic) - Collapse autolens/plot/plot_utils.py to a re-export from autogalaxy - Update all callers to import _critical_curves_from/_caustics_from from autogalaxy.plot.plot_utils and numpy_lines from autoarray.plot.utils Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 70d8a2c commit 8cf7041

6 files changed

Lines changed: 12 additions & 148 deletions

File tree

autolens/imaging/plot/fit_imaging_plots.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
from autoarray.plot.array import plot_array, _zoom_array_2d
99
from autoarray.plot.utils import save_figure
10-
from autolens.plot.plot_utils import (
11-
_to_lines,
12-
_critical_curves_from,
13-
_caustics_from,
14-
)
10+
from autoarray.plot.utils import numpy_lines as _to_lines
11+
from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from
1512

1613

1714
def _get_source_vmax(fit):

autolens/interferometer/plot/fit_interferometer_plots.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
from autoarray.plot.array import plot_array
99
from autoarray.plot.utils import save_figure
10-
from autolens.plot.plot_utils import (
11-
_to_lines,
12-
_critical_curves_from,
13-
)
10+
from autoarray.plot.utils import numpy_lines as _to_lines
11+
from autogalaxy.plot.plot_utils import _critical_curves_from
1412

1513

1614
def _plot_yx(y, x, ax, title, xlabel="", ylabel=""):

autolens/lens/plot/sensitivity_plots.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def subplot_tracer_images(
2020
use_log10: bool = False,
2121
):
2222
"""6-panel subplot showing lensed images and residuals from a perturbed tracer."""
23-
from autolens.lens.tracer_util import critical_curves_from, caustics_from
24-
from autolens.plot.plot_utils import _to_lines
23+
from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from
24+
from autoarray.plot.utils import numpy_lines as _to_lines
2525

2626
grid = aa.Grid2D.from_mask(mask=mask)
2727

@@ -36,13 +36,13 @@ def subplot_tracer_images(
3636
unmasked_grid = mask.derive_grid.unmasked
3737

3838
try:
39-
tan_cc_p, rad_cc_p = critical_curves_from(tracer=tracer_perturb, grid=unmasked_grid)
39+
tan_cc_p, rad_cc_p = _critical_curves_from(tracer_perturb, unmasked_grid)
4040
perturb_cc_lines = _to_lines(list(tan_cc_p), list(rad_cc_p))
4141
except Exception:
4242
perturb_cc_lines = None
4343

4444
try:
45-
tan_ca_p, rad_ca_p = caustics_from(tracer=tracer_perturb, grid=unmasked_grid)
45+
tan_ca_p, rad_ca_p = _caustics_from(tracer_perturb, unmasked_grid)
4646
perturb_ca_lines = _to_lines(list(tan_ca_p), list(rad_ca_p))
4747
except Exception:
4848
perturb_ca_lines = None

autolens/lens/plot/tracer_plots.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77

88
from autoarray.plot.array import plot_array
99
from autoarray.plot.utils import save_figure
10-
from autolens.plot.plot_utils import (
11-
_to_lines,
12-
_to_positions,
13-
_critical_curves_from,
14-
_caustics_from,
15-
)
10+
from autoarray.plot.utils import numpy_lines as _to_lines, numpy_positions as _to_positions
11+
from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from
1612

1713

1814
def subplot_tracer(

autolens/lens/tracer_util.py

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def time_delays_from(
374374
)
375375

376376
# Final time delay in days
377-
return (D_dt_m / c) * fermat_potential * factor
377+
return (D_dt_m / c) * fermat_potential * factor11
378378

379379

380380
def ordered_plane_redshifts_with_slicing_from(
@@ -436,80 +436,4 @@ def ordered_plane_redshifts_with_slicing_from(
436436
return plane_redshifts[0:-1]
437437

438438

439-
def critical_curves_from(tracer, grid):
440-
"""
441-
Compute tangential and radial critical curves for the tracer via LensCalc and
442-
return them as plain lists of numpy arrays.
443-
444-
Returns
445-
-------
446-
tuple[list, list]
447-
``(tangential_critical_curves, radial_critical_curves)`` where each element
448-
is a list of (N, 2) numpy arrays. *radial_critical_curves* may be an empty
449-
list when the radial curve area is below the pixel-scale threshold.
450-
"""
451-
from autogalaxy.operate.lens_calc import LensCalc
452-
import numpy as np
453-
454-
od = LensCalc.from_mass_obj(tracer)
455-
456-
tangential_critical_curves = od.tangential_critical_curve_list_from(grid=grid)
457-
458-
radial_critical_curve_area_list = od.radial_critical_curve_area_list_from(grid=grid)
459-
if any(area > grid.pixel_scale for area in radial_critical_curve_area_list):
460-
radial_critical_curves = od.radial_critical_curve_list_from(grid=grid)
461-
else:
462-
radial_critical_curves = []
463-
464-
return tangential_critical_curves, radial_critical_curves
465-
466-
467-
def caustics_from(tracer, grid):
468-
"""
469-
Compute tangential and radial caustics for the tracer via LensCalc and
470-
return them as plain lists of numpy arrays.
471-
472-
Returns
473-
-------
474-
tuple[list, list]
475-
``(tangential_caustics, radial_caustics)`` where each element is a list
476-
of (N, 2) numpy arrays.
477-
"""
478-
from autogalaxy.operate.lens_calc import LensCalc
479-
480-
od = LensCalc.from_mass_obj(tracer)
481-
482-
tangential_caustics = od.tangential_caustic_list_from(grid=grid)
483-
radial_caustics = od.radial_caustic_list_from(grid=grid)
484-
485-
return tangential_caustics, radial_caustics
486-
487-
488-
def lines_of_planes_from(tracer, grid):
489-
"""
490-
For each plane in the tracer return the appropriate line overlays:
491-
- plane 0 (image plane): critical curves
492-
- plane 1+ (source planes): caustics
493-
494-
Returns
495-
-------
496-
list[list[np.ndarray]]
497-
One entry per plane; each entry is a (possibly empty) list of (N, 2) numpy
498-
arrays suitable for passing as ``lines=`` to ``_plot_array``.
499-
"""
500-
tan_cc, rad_cc = critical_curves_from(tracer=tracer, grid=grid)
501-
tan_ca, rad_ca = caustics_from(tracer=tracer, grid=grid)
502-
503-
critical_curve_lines = list(tan_cc) + list(rad_cc)
504-
caustic_lines = list(tan_ca) + list(rad_ca)
505-
506-
lines_of_planes = []
507-
for plane_index in range(len(tracer.planes)):
508-
if plane_index == 0:
509-
lines_of_planes.append(critical_curve_lines)
510-
else:
511-
lines_of_planes.append(caustic_lines)
512-
513-
return lines_of_planes
514-
515439

autolens/plot/plot_utils.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1 @@
1-
import numpy as np
2-
3-
4-
def _to_lines(*items):
5-
"""Convert multiple line sources into a flat list of (N, 2) numpy arrays."""
6-
result = []
7-
for item in items:
8-
if item is None:
9-
continue
10-
if isinstance(item, list):
11-
for sub in item:
12-
try:
13-
arr = np.array(sub.array if hasattr(sub, "array") else sub)
14-
if arr.ndim == 2 and arr.shape[1] == 2 and len(arr) > 0:
15-
result.append(arr)
16-
except Exception:
17-
pass
18-
else:
19-
try:
20-
arr = np.array(item.array if hasattr(item, "array") else item)
21-
if arr.ndim == 2 and arr.shape[1] == 2 and len(arr) > 0:
22-
result.append(arr)
23-
except Exception:
24-
pass
25-
return result or None
26-
27-
28-
def _to_positions(*items):
29-
"""Convert multiple position sources into a flat list of (N, 2) numpy arrays."""
30-
return _to_lines(*items)
31-
32-
33-
def _critical_curves_from(tracer, grid):
34-
"""Return (tangential_critical_curves, radial_critical_curves) as lists of arrays."""
35-
from autolens.lens import tracer_util
36-
37-
try:
38-
tan_cc, rad_cc = tracer_util.critical_curves_from(tracer=tracer, grid=grid)
39-
return list(tan_cc), list(rad_cc)
40-
except Exception:
41-
return [], []
42-
43-
44-
def _caustics_from(tracer, grid):
45-
"""Return (tangential_caustics, radial_caustics) as lists of arrays."""
46-
from autolens.lens import tracer_util
47-
48-
try:
49-
tan_ca, rad_ca = tracer_util.caustics_from(tracer=tracer, grid=grid)
50-
return list(tan_ca), list(rad_ca)
51-
except Exception:
52-
return [], []
1+
from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from

0 commit comments

Comments
 (0)