Skip to content

Commit 67fd418

Browse files
committed
Fix all Copilot review issues in plot module
- __init__.py: use backend != "default" instead of substring test - output.py: use format == "show" instead of substring test - array.py: guard on array.size == 0 instead of np.all(array == 0) so zero-valued images (residuals, masks) still render - array.py: compute LogNorm vmax with np.nanmax to handle NaN-containing arrays; guard against non-finite / degenerate ranges - yx.py: remove np.count_nonzero(y) == 0 guard so all-zero series still plots; keep only None / empty / all-NaN guards - inversion.py: compute LogNorm vmax from pixel_values (np.nanmax) instead of passing None, matching array.py behaviour - inversion.py: add plt.colorbar to the InterpolatorRectangularUniform (imshow) branch so both rectangular paths consistently show a colorbar https://claude.ai/code/session_01B9sVEV54XWCa2LJw1C8gvv
1 parent 095f16c commit 67fd418

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

autoarray/plot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def _set_backend():
44
from autoconf import conf
55

66
backend = conf.get_matplotlib_backend()
7-
if backend not in "default":
7+
if backend != "default":
88
matplotlib.use(backend)
99
try:
1010
hpc_mode = conf.instance["general"]["hpc"]["hpc_mode"]

autoarray/plot/array.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def plot_array(
131131
except AttributeError:
132132
array = np.asarray(array)
133133

134-
if array is None or np.all(array == 0):
134+
if array is None or array.size == 0:
135135
return
136136

137137
# convert overlay params (safe for None and already-numpy inputs)
@@ -165,7 +165,15 @@ def plot_array(
165165
except Exception:
166166
log10_min = 1.0e-4
167167
clipped = np.clip(array, log10_min, None)
168-
norm = LogNorm(vmin=vmin or log10_min, vmax=vmax or clipped.max())
168+
vmin_log = vmin if (vmin is not None and np.isfinite(vmin)) else log10_min
169+
if vmax is not None and np.isfinite(vmax):
170+
vmax_log = vmax
171+
else:
172+
with np.errstate(all="ignore"):
173+
vmax_log = np.nanmax(clipped)
174+
if not np.isfinite(vmax_log) or vmax_log <= vmin_log:
175+
vmax_log = vmin_log * 10.0
176+
norm = LogNorm(vmin=vmin_log, vmax=vmax_log)
169177
elif vmin is not None or vmax is not None:
170178
norm = Normalize(vmin=vmin, vmax=vmax)
171179
else:

autoarray/plot/inversion.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ def plot_inversion_reconstruction(
8585

8686
# --- colour normalisation --------------------------------------------------
8787
if use_log10:
88-
norm = LogNorm(vmin=vmin or 1e-4, vmax=vmax)
88+
vmin_log = vmin if (vmin is not None and np.isfinite(vmin)) else 1e-4
89+
if vmax is not None and np.isfinite(vmax):
90+
vmax_log = vmax
91+
elif pixel_values is not None:
92+
with np.errstate(all="ignore"):
93+
vmax_log = float(np.nanmax(np.asarray(pixel_values)))
94+
if not np.isfinite(vmax_log) or vmax_log <= vmin_log:
95+
vmax_log = vmin_log * 10.0
96+
else:
97+
vmax_log = vmin_log * 10.0
98+
norm = LogNorm(vmin=vmin_log, vmax=vmax_log)
8999
elif vmin is not None or vmax is not None:
90100
norm = Normalize(vmin=vmin, vmax=vmax)
91101
else:
@@ -177,14 +187,15 @@ def _plot_rectangular(ax, pixel_values, mapper, norm, colormap, extent):
177187
pixel_scales=mapper.mesh_geometry.pixel_scales,
178188
origin=mapper.mesh_geometry.origin,
179189
)
180-
ax.imshow(
190+
im = ax.imshow(
181191
pix_array.native.array,
182192
cmap=colormap,
183193
norm=norm,
184194
extent=pix_array.geometry.extent,
185195
aspect="auto",
186196
origin="upper",
187197
)
198+
plt.colorbar(im, ax=ax)
188199
else:
189200
y_edges, x_edges = mapper.mesh_geometry.edges_transformed.T
190201
Y, X = np.meshgrid(y_edges, x_edges, indexing="ij")

autoarray/plot/output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def output_path_from(self, format):
9696
Absolute path to the output directory, or ``None`` for
9797
``format == "show"``.
9898
"""
99-
if format in "show":
99+
if format == "show":
100100
return None
101101

102102
if self.format_folder:

autoarray/plot/yx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def plot_yx(
8383
x = x.array if hasattr(x, "array") else np.asarray(x)
8484

8585
# guard: nothing to draw
86-
if y is None or np.count_nonzero(y) == 0 or np.isnan(y).all():
86+
if y is None or len(y) == 0 or np.isnan(y).all():
8787
return
8888

8989
owns_figure = ax is None

0 commit comments

Comments
 (0)