diff --git a/prototypes/starred_epsf_spike.py b/prototypes/starred_epsf_spike.py index 8708556..605c88a 100644 --- a/prototypes/starred_epsf_spike.py +++ b/prototypes/starred_epsf_spike.py @@ -31,11 +31,21 @@ ROOT = Path(__file__).resolve().parents[1] # Reduced outputs are gitignored and live only in the canonical checkout, not -# in the task worktree — resolve the field there, worktree-first. +# in a task worktree — resolve the field there too, worktree-first. A worktree's +# `.git` is a FILE pointing back into `/.git/worktrees/`, so +# the canonical checkout is derived from git rather than from a workspace path, +# which differs per machine and moves when the workspace is regrouped. In an +# ordinary clone `.git` is a directory and this collapses to ROOT. +_DOTGIT = ROOT / ".git" +MAIN = ( + Path(_DOTGIT.read_text().split(":", 1)[-1].strip()).parent.parent.parent + if _DOTGIT.is_file() + else ROOT +) _FIELD_NAME = "cosmos_web_ring_f115w" # richest clean-point-source count of the reduced fields _CANDIDATES = [ ROOT / "scripts" / "output" / _FIELD_NAME, - Path.home() / "Code/PyAutoLabs/PyAutoReduce/scripts/output" / _FIELD_NAME, + MAIN / "scripts" / "output" / _FIELD_NAME, ] FIELD = next((p for p in _CANDIDATES if (p / "data.fits").exists()), _CANDIDATES[0]) OUT = ROOT / "prototypes" / "output" / "starred_spike" diff --git a/prototypes/starred_vs_epsf_comparison.py b/prototypes/starred_vs_epsf_comparison.py index 324d1c6..81afad1 100644 --- a/prototypes/starred_vs_epsf_comparison.py +++ b/prototypes/starred_vs_epsf_comparison.py @@ -26,9 +26,21 @@ import numpy as np ROOT = Path(__file__).resolve().parents[1] +# Reduced outputs are gitignored and live only in the canonical checkout, not +# in a task worktree — resolve the field there too, worktree-first. A worktree's +# `.git` is a FILE pointing back into `/.git/worktrees/`, so +# the canonical checkout is derived from git rather than from a workspace path, +# which differs per machine and moves when the workspace is regrouped. In an +# ordinary clone `.git` is a directory and this collapses to ROOT. +_DOTGIT = ROOT / ".git" +MAIN = ( + Path(_DOTGIT.read_text().split(":", 1)[-1].strip()).parent.parent.parent + if _DOTGIT.is_file() + else ROOT +) _FIELD = "cosmos_web_ring_f115w" _CAND = [ROOT / "scripts/output" / _FIELD, - Path.home() / "Code/PyAutoLabs/PyAutoReduce/scripts/output" / _FIELD] + MAIN / "scripts/output" / _FIELD] FIELD = next((p for p in _CAND if (p / "data.fits").exists()), _CAND[0]) OUT = ROOT / "prototypes" / "output" / "starred_vs_epsf" NPZ = OUT / "compare.npz" diff --git a/prototypes/starred_vs_epsf_m92.py b/prototypes/starred_vs_epsf_m92.py index 7e01e8c..807a20e 100644 --- a/prototypes/starred_vs_epsf_m92.py +++ b/prototypes/starred_vs_epsf_m92.py @@ -24,10 +24,22 @@ import numpy as np ROOT = Path(__file__).resolve().parents[1] +# Reduced outputs are gitignored and live only in the canonical checkout, not +# in a task worktree — resolve the field there too, worktree-first. A worktree's +# `.git` is a FILE pointing back into `/.git/worktrees/`, so +# the canonical checkout is derived from git rather than from a workspace path, +# which differs per machine and moves when the workspace is regrouped. In an +# ordinary clone `.git` is a directory and this collapses to ROOT. +_DOTGIT = ROOT / ".git" +MAIN = ( + Path(_DOTGIT.read_text().split(":", 1)[-1].strip()).parent.parent.parent + if _DOTGIT.is_file() + else ROOT +) _FIELD = os.environ.get("M92_FIELD", "m92_f150w") # m92_f150w (SW) | m92_f277w (LW) _CAND = [ ROOT / "scripts/output" / _FIELD, - Path.home() / "Code/PyAutoLabs/PyAutoReduce/scripts/output" / _FIELD, + MAIN / "scripts/output" / _FIELD, ] FIELD = next((p for p in _CAND if (p / "data.fits").exists()), _CAND[0]) OUT = ROOT / "prototypes" / "output" / f"starred_vs_epsf_{_FIELD}" diff --git a/prototypes/starred_vs_epsf_omegacen.py b/prototypes/starred_vs_epsf_omegacen.py index e65468f..6353c50 100644 --- a/prototypes/starred_vs_epsf_omegacen.py +++ b/prototypes/starred_vs_epsf_omegacen.py @@ -20,10 +20,22 @@ import numpy as np ROOT = Path(__file__).resolve().parents[1] +# Reduced outputs are gitignored and live only in the canonical checkout, not +# in a task worktree — resolve the field there too, worktree-first. A worktree's +# `.git` is a FILE pointing back into `/.git/worktrees/`, so +# the canonical checkout is derived from git rather than from a workspace path, +# which differs per machine and moves when the workspace is regrouped. In an +# ordinary clone `.git` is a directory and this collapses to ROOT. +_DOTGIT = ROOT / ".git" +MAIN = ( + Path(_DOTGIT.read_text().split(":", 1)[-1].strip()).parent.parent.parent + if _DOTGIT.is_file() + else ROOT +) _FIELD = "omegacen_f606w" _CAND = [ ROOT / "scripts/output" / _FIELD, - Path.home() / "Code/PyAutoLabs/PyAutoReduce/scripts/output" / _FIELD, + MAIN / "scripts/output" / _FIELD, ] FIELD = next((p for p in _CAND if (p / "data.fits").exists()), _CAND[0]) OUT = ROOT / "prototypes" / "output" / "starred_vs_epsf_omegacen" diff --git a/scripts/reduce_cosmos_web_ring.py b/scripts/reduce_cosmos_web_ring.py index 44d6927..32d0797 100644 --- a/scripts/reduce_cosmos_web_ring.py +++ b/scripts/reduce_cosmos_web_ring.py @@ -18,6 +18,7 @@ import argparse import json +import os import sys from pathlib import Path @@ -30,14 +31,45 @@ RA, DEC = 150.10048, 1.89301 CACHE_ROOT = REPO / "scripts" / "cache" OUTPUT_ROOT = REPO / "scripts" / "output" -DEMO_ROOT = Path( - "/home/jammy/Code/PyAutoLabs/autolens_assistant/dataset/imaging/" - "cosmos_web_ring/wavebands" -) + +# The parity reference is a *sibling checkout*, not part of this repo and not +# shipped in the `pyautoreduce` distribution: autolens_assistant's demo +# cutouts. Resolve it, never name it — an absolute path is right on exactly one +# machine, and the checkouts beside us get grouped into family subdirectories +# (autolens_assistant -> lens/autolens_assistant) as the workspace grows. +DEMO_REL = Path("autolens_assistant/dataset/imaging/cosmos_web_ring/wavebands") BANDS = ("F115W", "F150W", "F277W", "F444W") +def default_demo_root() -> Path: + """Where autolens_assistant's parity cutouts are, resolved beside us. + + ``$AUTOREDUCE_DEMO_ROOT`` wins if set; otherwise look for the sibling + checkout one and two levels above this repo, at each level directly and one + family subdirectory deeper. That covers the flat workspace, the regrouped + one, and a bundle of task worktrees, without this library knowing anything + about the workspace tooling — `pyautoreduce` is released to users who have + no workspace at all, so it must not import the developer-box organs that + could answer this question. + + Only ever probes for directories, so it cannot raise: a missing demo + dataset stays an error for `compare` at run time, never an import failure, + and the guess returned when nothing is found names a plausible path. + """ + env = os.environ.get("AUTOREDUCE_DEMO_ROOT") + if env: + return Path(env).expanduser() + for root in (REPO.parent, REPO.parent.parent): + for cand in (root / DEMO_REL, *sorted(root.glob(f"*/{DEMO_REL}"))): + if cand.is_dir(): + return cand + return REPO.parent / DEMO_REL + + +DEMO_ROOT = default_demo_root() + + def spec_for(band: str, psf_backend: str = "epsf") -> TargetSpec: adapter = nircam_adapter_for_filter(band) # Demo cutouts: SW 419x419 @0.03 (12.57"), LW 209x209 @0.06 (12.54") — @@ -60,14 +92,14 @@ def spec_for(band: str, psf_backend: str = "epsf") -> TargetSpec: ) -def compare(band: str, out_dir: Path) -> dict: +def compare(band: str, out_dir: Path, demo_root: Path | None = None) -> dict: from astropy.io import fits from autoreduce.validation import registered_ratios new_data = fits.getdata(out_dir / "data.fits").astype(float) new_noise = fits.getdata(out_dir / "noise_map.fits").astype(float) - demo_dir = DEMO_ROOT / band + demo_dir = (demo_root or DEMO_ROOT) / band demo_data = fits.getdata(demo_dir / "data.fits").astype(float) demo_noise = fits.getdata(demo_dir / "noise_map.fits").astype(float) return { @@ -84,6 +116,12 @@ def main(): help="PSF back-end: photutils Tier-1 (default) or STARRED Tier-1b (#35; " "needs the pyautoreduce[starred] extra)", ) + parser.add_argument( + "--demo-root", type=Path, default=None, + help="autolens_assistant parity cutouts (default: the sibling checkout " + f"resolved beside this repo, currently {DEMO_ROOT}; or " + "$AUTOREDUCE_DEMO_ROOT)", + ) args = parser.parse_args() bands = BANDS if args.band == "all" else (args.band,) @@ -98,7 +136,7 @@ def main(): "correlated_noise_factor": record["noise"]["correlated_noise_factor"], "sky_over_err_floor": record["noise"].get("sky_over_err_floor"), "psf": record["psf"], - "parity": compare(band, out_dir), + "parity": compare(band, out_dir, args.demo_root), } print(f"[{band}] ---- validation ----") print(json.dumps(summary, indent=2))