From 04812faa1a716e296d1882d607d64276fdb4ddf3 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Tue, 7 Apr 2026 20:56:15 +0100 Subject: [PATCH] Add should_simulate utility for workspace auto-simulation When PYAUTO_WORKSPACE_SMALL_DATASETS=1 is active, existing datasets are deleted so simulators re-create them at the reduced 15x15 resolution. This avoids shape mismatches between full-resolution FITS files on disk and the mask/grid cap applied by the env var. Co-Authored-By: Claude Sonnet 4.6 --- autoarray/util/__init__.py | 1 + autoarray/util/dataset_util.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 autoarray/util/dataset_util.py diff --git a/autoarray/util/__init__.py b/autoarray/util/__init__.py index 32449961a..540440a52 100644 --- a/autoarray/util/__init__.py +++ b/autoarray/util/__init__.py @@ -29,3 +29,4 @@ from autoarray.operators import transformer_util as transformer from autoarray.util import misc_util as misc +from autoarray.util import dataset_util as dataset diff --git a/autoarray/util/dataset_util.py b/autoarray/util/dataset_util.py new file mode 100644 index 000000000..cc126744f --- /dev/null +++ b/autoarray/util/dataset_util.py @@ -0,0 +1,24 @@ +import os +import shutil + + +def should_simulate(dataset_path): + """ + Returns True if the dataset at ``dataset_path`` needs to be simulated. + + When ``PYAUTO_WORKSPACE_SMALL_DATASETS=1`` is active, any existing dataset + is deleted so the simulator re-creates it at the reduced resolution. This + avoids shape mismatches between full-resolution FITS files on disk and the + 15x15 mask/grid cap applied by the env var. + + Use this as a drop-in replacement for ``not path.exists(dataset_path)`` in + the workspace auto-simulation pattern:: + + if aa.util.dataset.should_simulate(dataset_path): + subprocess.run([sys.executable, "scripts/.../simulator.py"], check=True) + """ + if os.environ.get("PYAUTO_WORKSPACE_SMALL_DATASETS") == "1": + if os.path.exists(dataset_path): + shutil.rmtree(dataset_path) + + return not os.path.exists(dataset_path)