Skip to content

Commit 43213ea

Browse files
authored
Merge pull request #261 from PyAutoLabs/feature/small-datasets-resimulate
Add should_simulate utility for auto-simulation with small datasets
2 parents 2f19ea5 + 04812fa commit 43213ea

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

autoarray/util/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929

3030
from autoarray.operators import transformer_util as transformer
3131
from autoarray.util import misc_util as misc
32+
from autoarray.util import dataset_util as dataset

autoarray/util/dataset_util.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import shutil
3+
4+
5+
def should_simulate(dataset_path):
6+
"""
7+
Returns True if the dataset at ``dataset_path`` needs to be simulated.
8+
9+
When ``PYAUTO_WORKSPACE_SMALL_DATASETS=1`` is active, any existing dataset
10+
is deleted so the simulator re-creates it at the reduced resolution. This
11+
avoids shape mismatches between full-resolution FITS files on disk and the
12+
15x15 mask/grid cap applied by the env var.
13+
14+
Use this as a drop-in replacement for ``not path.exists(dataset_path)`` in
15+
the workspace auto-simulation pattern::
16+
17+
if aa.util.dataset.should_simulate(dataset_path):
18+
subprocess.run([sys.executable, "scripts/.../simulator.py"], check=True)
19+
"""
20+
if os.environ.get("PYAUTO_WORKSPACE_SMALL_DATASETS") == "1":
21+
if os.path.exists(dataset_path):
22+
shutil.rmtree(dataset_path)
23+
24+
return not os.path.exists(dataset_path)

0 commit comments

Comments
 (0)