Skip to content

Commit 095f16c

Browse files
committed
Add private aliases in array.py; allow save_figure to accept multiple formats
- autoarray/plot/array.py: add module-level aliases _zoom_array_2d and _mask_edge_coords pointing at the imported zoom_array / auto_mask_edge helpers for use by downstream packages (e.g. autogalaxy) - autoarray/plot/utils.py: save_figure now accepts format as either a str or a list/tuple of strings; iterates over all formats so a single call can write png + pdf (or any combination) simultaneously https://claude.ai/code/session_01B9sVEV54XWCa2LJw1C8gvv
1 parent 1519fb6 commit 095f16c

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

autoarray/plot/array.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
numpy_positions,
2121
)
2222

23+
_zoom_array_2d = zoom_array
24+
_mask_edge_coords = auto_mask_edge
25+
2326

2427
def plot_array(
2528
array,

autoarray/plot/utils.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ def save_figure(
345345
filename
346346
File name without extension.
347347
format
348-
File format passed to ``fig.savefig`` (e.g. ``"png"``, ``"pdf"``).
348+
File format(s) passed to ``fig.savefig``. Either a single string
349+
(e.g. ``"png"``) or a list/tuple of strings (e.g. ``["png", "pdf"]``)
350+
to save in multiple formats in one call.
349351
dpi
350352
Resolution in dots per inch.
351353
structure
@@ -355,29 +357,31 @@ def save_figure(
355357
"""
356358
if path:
357359
os.makedirs(path, exist_ok=True)
358-
if format == "fits":
359-
if structure is not None and hasattr(structure, "output_to_fits"):
360-
structure.output_to_fits(
361-
file_path=os.path.join(path, f"{filename}.fits"),
362-
overwrite=True,
363-
)
360+
formats = format if isinstance(format, (list, tuple)) else [format]
361+
for fmt in formats:
362+
if fmt == "fits":
363+
if structure is not None and hasattr(structure, "output_to_fits"):
364+
structure.output_to_fits(
365+
file_path=os.path.join(path, f"{filename}.fits"),
366+
overwrite=True,
367+
)
368+
else:
369+
logger.warning(
370+
f"save_figure: fits format requested for {filename} but no "
371+
"compatible structure was provided; skipping."
372+
)
364373
else:
365-
logger.warning(
366-
f"save_figure: fits format requested for {filename} but no "
367-
"compatible structure was provided; skipping."
368-
)
369-
else:
370-
try:
371-
fig.savefig(
372-
os.path.join(path, f"{filename}.{format}"),
373-
dpi=dpi,
374-
bbox_inches="tight",
375-
pad_inches=0.1,
376-
)
377-
except Exception as exc:
378-
logger.warning(
379-
f"save_figure: could not save {filename}.{format}: {exc}"
380-
)
374+
try:
375+
fig.savefig(
376+
os.path.join(path, f"{filename}.{fmt}"),
377+
dpi=dpi,
378+
bbox_inches="tight",
379+
pad_inches=0.1,
380+
)
381+
except Exception as exc:
382+
logger.warning(
383+
f"save_figure: could not save {filename}.{fmt}: {exc}"
384+
)
381385
else:
382386
plt.show()
383387

0 commit comments

Comments
 (0)