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
22 changes: 22 additions & 0 deletions autoarray/util/dataset_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,25 @@ def should_simulate(dataset_path):
shutil.rmtree(dataset_path)

return not Path(dataset_path).exists()

SMALL_DATASETS_N_CATALOGUE = 25


def cap_catalogue_size_for_small_datasets(n: int) -> int:
"""
Cap a catalogue-style dataset size (e.g. the number of weak-lensing background
galaxies) to the small-datasets limit when ``PYAUTO_SMALL_DATASETS=1`` is active.

Catalogue datasets have no pixel grid, so the (15, 15) array cap above does not
apply to them; the number of catalogue entries is their size lever. Returns ``n``
unchanged when the env var is not set to ``"1"`` or ``n`` is already at-or-below
the cap (25).

Simulators should apply this to *generated* catalogue sizes only (e.g. a
requested number of random positions) — never to a user-provided grid or
catalogue, which must round-trip unmodified.
"""
if os.environ.get("PYAUTO_SMALL_DATASETS") != "1":
return n

return min(n, SMALL_DATASETS_N_CATALOGUE)
14 changes: 14 additions & 0 deletions test_autoarray/util/test_catalogue_cap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from autoarray.util import dataset_util


def test__cap_catalogue_size__inactive_without_env_var(monkeypatch):
monkeypatch.delenv("PYAUTO_SMALL_DATASETS", raising=False)

assert dataset_util.cap_catalogue_size_for_small_datasets(200) == 200


def test__cap_catalogue_size__caps_when_active(monkeypatch):
monkeypatch.setenv("PYAUTO_SMALL_DATASETS", "1")

assert dataset_util.cap_catalogue_size_for_small_datasets(200) == 25
assert dataset_util.cap_catalogue_size_for_small_datasets(10) == 10
Loading