Skip to content

Commit c154673

Browse files
committed
Remove plot_utils.py wrappers; use autoarray plot_array/plot_grid directly
- Strip plot_utils.py down to autolens-specific utilities only: _to_lines, _to_positions, _save_subplot, _critical_curves_from, _caustics_from. - Remove _zoom_array, _auto_mask_edge, _numpy_lines, _numpy_positions, _prepare_array — these are now handled inside autoarray's plot_array/ plot_grid directly (Array2D/Grid2D objects accepted natively). - Remove plot_array and plot_grid adapter functions from plot_utils.py. - All callers now import plot_array from autoarray.plot.plots.array and plot_grid from autoarray.plot.plots.grid. - plot/__init__.py re-exports plot_array/plot_grid from autoarray. - fit_imaging_plots.py uses _zoom_array_2d from autoarray for _symmetric_vmax computation. https://claude.ai/code/session_01CzJBy8KvFXiNchoNdk5i9k
1 parent 63fd855 commit c154673

8 files changed

Lines changed: 11 additions & 153 deletions

File tree

autolens/analysis/plotter_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from autolens.lens.tracer import Tracer
1616
from autolens.lens.plot.tracer_plots import subplot_galaxies_images
17-
from autolens.plot.plot_utils import plot_array
17+
from autoarray.plot.plots.array import plot_array
1818

1919

2020
class PlotterInterface(AgPlotterInterface):

autolens/imaging/plot/fit_imaging_plots.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import autoarray as aa
66
import autogalaxy as ag
77

8+
from autoarray.plot.plots.array import plot_array, _zoom_array_2d
89
from autolens.plot.plot_utils import (
9-
plot_array,
1010
_to_lines,
1111
_save_subplot,
1212
_critical_curves_from,
1313
_caustics_from,
14-
_zoom_array,
1514
)
1615

1716

@@ -508,7 +507,7 @@ def subplot_fit_combined_log10(
508507
def _symmetric_vmax(array) -> float:
509508
"""Return abs-max finite value for symmetric colormap scaling."""
510509
try:
511-
vals = _zoom_array(array).native.array
510+
vals = _zoom_array_2d(array).native.array
512511
except AttributeError:
513512
vals = np.asarray(array)
514513
finite = vals[np.isfinite(vals)]

autolens/interferometer/plot/fit_interferometer_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import autoarray as aa
66
import autogalaxy as ag
77

8+
from autoarray.plot.plots.array import plot_array
89
from autolens.plot.plot_utils import (
9-
plot_array,
1010
_to_lines,
1111
_save_subplot,
1212
_critical_curves_from,

autolens/lens/plot/sensitivity_plots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import autoarray as aa
77

8-
from autolens.plot.plot_utils import plot_array, _save_subplot
8+
from autoarray.plot.plots.array import plot_array
9+
from autolens.plot.plot_utils import _save_subplot
910

1011

1112
def subplot_tracer_images(

autolens/lens/plot/subhalo_plots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import matplotlib.pyplot as plt
33
from typing import Optional
44

5-
from autolens.plot.plot_utils import plot_array, _save_subplot
5+
from autoarray.plot.plots.array import plot_array
6+
from autolens.plot.plot_utils import _save_subplot
67
from autolens.imaging.plot.fit_imaging_plots import _plot_source_plane
78

89

autolens/lens/plot/tracer_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import autoarray as aa
66
import autogalaxy as ag
77

8+
from autoarray.plot.plots.array import plot_array
89
from autolens.plot.plot_utils import (
9-
plot_array,
1010
_to_lines,
1111
_to_positions,
1212
_save_subplot,

autolens/plot/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
# ---------------------------------------------------------------------------
2424
# Standalone plot helpers
2525
# ---------------------------------------------------------------------------
26-
from autolens.plot.plot_utils import plot_array, plot_grid
26+
from autoarray.plot.plots.array import plot_array
27+
from autoarray.plot.plots.grid import plot_grid
2728

2829
# ---------------------------------------------------------------------------
2930
# subplot_* public API

autolens/plot/plot_utils.py

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,6 @@
11
import os
22
import numpy as np
33
import matplotlib.pyplot as plt
4-
from typing import List, Optional
5-
6-
7-
def _zoom_array(array):
8-
"""Apply zoom_around_mask from config if requested."""
9-
try:
10-
from autoconf import conf
11-
zoom_around_mask = conf.instance["visualize"]["general"]["general"]["zoom_around_mask"]
12-
except Exception:
13-
zoom_around_mask = False
14-
15-
if zoom_around_mask and hasattr(array, "mask") and not array.mask.is_all_false:
16-
try:
17-
from autoarray.mask.derive.zoom_2d import Zoom2D
18-
return Zoom2D(mask=array.mask).array_2d_from(array=array, buffer=1)
19-
except Exception:
20-
pass
21-
return array
22-
23-
24-
def _auto_mask_edge(array) -> Optional[np.ndarray]:
25-
"""Return edge-pixel (y, x) coords from array.mask, or None."""
26-
try:
27-
if not array.mask.is_all_false:
28-
return np.array(array.mask.derive_grid.edge.array)
29-
except AttributeError:
30-
pass
31-
return None
32-
33-
34-
def _numpy_lines(lines) -> Optional[List[np.ndarray]]:
35-
"""Convert lines (Grid2DIrregular or list) to list of (N,2) numpy arrays."""
36-
if lines is None:
37-
return None
38-
result = []
39-
try:
40-
for line in lines:
41-
try:
42-
arr = np.array(line.array if hasattr(line, "array") else line)
43-
if arr.ndim == 2 and arr.shape[1] == 2:
44-
result.append(arr)
45-
except Exception:
46-
pass
47-
except TypeError:
48-
pass
49-
return result or None
50-
51-
52-
def _numpy_positions(positions) -> Optional[List[np.ndarray]]:
53-
"""Convert positions to list of (N,2) numpy arrays."""
54-
if positions is None:
55-
return None
56-
try:
57-
arr = np.array(positions.array if hasattr(positions, "array") else positions)
58-
if arr.ndim == 2 and arr.shape[1] == 2:
59-
return [arr]
60-
except Exception:
61-
pass
62-
if isinstance(positions, list):
63-
result = []
64-
for p in positions:
65-
try:
66-
result.append(np.array(p.array if hasattr(p, "array") else p))
67-
except Exception:
68-
pass
69-
return result or None
70-
return None
71-
72-
73-
def _prepare_array(array):
74-
"""Zoom and extract (arr_2d, extent, mask) from an Array2D-like object.
75-
76-
Returns a plain (N, M) numpy array suitable for passing to
77-
``autoarray.plot.plots.array.plot_array``, along with the spatial *extent*
78-
and edge-pixel *mask* overlays.
79-
"""
80-
array = _zoom_array(array)
81-
try:
82-
arr = array.native.array
83-
extent = array.geometry.extent
84-
except AttributeError:
85-
arr = np.asarray(array)
86-
extent = None
87-
mask = _auto_mask_edge(array) if hasattr(array, "mask") else None
88-
return arr, extent, mask
89-
90-
91-
def plot_array(
92-
array,
93-
ax=None,
94-
title="",
95-
lines=None,
96-
positions=None,
97-
colormap="jet",
98-
use_log10=False,
99-
vmin=None,
100-
vmax=None,
101-
output_path=None,
102-
output_filename="array",
103-
output_format="png",
104-
):
105-
"""Plot an Array2D (or numpy array) via autoarray's plot_array."""
106-
from autoarray.plot.plots.array import plot_array as _aa_plot_array
107-
108-
arr, extent, mask = _prepare_array(array)
109-
_aa_plot_array(
110-
array=arr,
111-
ax=ax,
112-
extent=extent,
113-
mask=mask,
114-
positions=positions if isinstance(positions, list) else _numpy_positions(positions),
115-
lines=lines if isinstance(lines, list) else _numpy_lines(lines),
116-
title=title,
117-
colormap=colormap,
118-
use_log10=use_log10,
119-
vmin=vmin,
120-
vmax=vmax,
121-
output_path=output_path if ax is None else None,
122-
output_filename=output_filename,
123-
output_format=output_format,
124-
structure=array,
125-
)
126-
127-
128-
def plot_grid(
129-
grid,
130-
ax=None,
131-
title="",
132-
output_path=None,
133-
output_filename="grid",
134-
output_format="png",
135-
):
136-
"""Plot a Grid2D via autoarray's plot_grid."""
137-
from autoarray.plot.plots.grid import plot_grid as _aa_plot_grid
138-
139-
_aa_plot_grid(
140-
grid=np.array(grid.array),
141-
ax=ax,
142-
title=title,
143-
output_path=output_path if ax is None else None,
144-
output_filename=output_filename,
145-
output_format=output_format,
146-
)
1474

1485

1496
def _to_lines(*items):
@@ -177,7 +34,6 @@ def _to_positions(*items):
17734

17835
def _save_subplot(fig, output_path, filename, output_format="png"):
17936
"""Save a subplot figure to disk (or show it when output_path is None)."""
180-
# Normalise: format may be a list (e.g. ['png']) or a plain string.
18137
if isinstance(output_format, (list, tuple)):
18238
fmts = output_format
18339
else:

0 commit comments

Comments
 (0)