Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoarray/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions autoarray/util/dataset_util.py
Original file line number Diff line number Diff line change
@@ -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)
Loading