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
14 changes: 12 additions & 2 deletions prototypes/starred_epsf_spike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<canonical>/.git/worktrees/<name>`, 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"
Expand Down
14 changes: 13 additions & 1 deletion prototypes/starred_vs_epsf_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<canonical>/.git/worktrees/<name>`, 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"
Expand Down
14 changes: 13 additions & 1 deletion prototypes/starred_vs_epsf_m92.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<canonical>/.git/worktrees/<name>`, 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}"
Expand Down
14 changes: 13 additions & 1 deletion prototypes/starred_vs_epsf_omegacen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<canonical>/.git/worktrees/<name>`, 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"
Expand Down
52 changes: 45 additions & 7 deletions scripts/reduce_cosmos_web_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import argparse
import json
import os
import sys
from pathlib import Path

Expand All @@ -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") —
Expand All @@ -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 {
Expand All @@ -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,)

Expand All @@ -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))
Expand Down
Loading