Skip to content
Open
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
171 changes: 101 additions & 70 deletions astra.yaml

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions docs/source/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ recognise passes straight through to snakemake with the right profile and state
directory, which is the escape hatch for `sp --unlock`, `sp --dag` or
`sp exp_psf ...`.

## Exposure-grid categories

Tile detection writes `SEG_LABEL`, the segmentation check-image label before the catalogue join, alongside `SEG_VIGNET`.
The join changes `NUMBER` and the tile segmentation stamps but retains `SEG_LABEL`.
The multi-epoch vignetmaker takes `segmentation` as its fourth positional input, after `sexcat`, `log_exp_headers` and `exp_numbers`.
It maps the full segmentation labels to catalogue `NUMBER`s; detections absent from the joined catalogue have label −1 and sky has label 0.

Each `image_vignet` epoch entry contains three categorical arrays with the image stamp's shape: `SEG_VIGNET` (int32), `NEIGHBOUR` (bool) and `OFF_TILE` (bool).
The native stamp's `INT_POS` defines every exposure pixel centre; `OFFSET` retains the same subpixel centroid remainder as the image extraction.
Vignetmaker maps those zero-based centres through the exposure WCS and the tile WCS, then samples the nearest tile cell with `floor(x + 0.5)` on each axis, including upward half-cell ties.
No image, detector flag, weight, background or RMS stamp is resampled.
A nearest cell outside the full tile rectangle sets `OFF_TILE`; it is not sky or a neighbour.

Both blend handlings use the full registered segmentation, including cells beyond the original tile VIGNET support.
`NEIGHBOUR` marks every foreign nonzero segmentation label, including −1.
`noisefill` replaces light on that full neighbour footprint, independently of the tile VIGNET's intensity markers.
`uberseg` recomputes the nearest-segment Voronoi partition on the exposure-grid labels before applying its configured dilation.
Ngmix reads these arrays before its defect mask, masked-fraction cut, central veto and footprint diagnostics; it applies no CCD flip to them.
The tile-grid `SEG_VIGNET` still supplies the catalogue-level `neighbour_flag`.
`SEG_LABEL` and both tile stamp columns are omitted from final catalogues when stamp removal is enabled.
There are no additional product files or final-catalogue columns.

Image vignette stores without registered categories fail with an instruction to rerun vignetmaker.
Detection catalogues without `SEG_LABEL` require tile detection and the join to run with the matching segmentation check image.
Use a single code revision and this input contract across a campaign, including calibration simulations; image and categorical products from different extractions must not be mixed.

## The two static invocations

The exposure job set is *derived from data the run itself produces* — a tile's
Expand Down
43 changes: 4 additions & 39 deletions example/cfis_image_sims/config_tile_PiViVi_canfar_sx.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN_NAME = run_sp_tile_ViVi

# Module name, single string or comma-separated list of valid module runner names

MODULE = vignetmaker_runner, vignetmaker_runner, vignetmaker_runner
MODULE = vignetmaker_runner, vignetmaker_runner

# Parallel processing mode, SMP or MPI
MODE = SMP
Expand Down Expand Up @@ -93,9 +93,10 @@ PREFIX = weight

INPUT_DIR = run_sp_tile_Sx:sextractor_runner, run_sp_tile_Mh_exp:merge_headers_runner, last:find_exposures_runner

FILE_PATTERN = sexcat, log_exp_headers, exp_numbers
# @sc [decision:preparation.categorical_registration]
FILE_PATTERN = sexcat, log_exp_headers, exp_numbers, segmentation

FILE_EXT = .fits, .sqlite, .txt
FILE_EXT = .fits, .sqlite, .txt, .fits

# NUMBERING_SCHEME (optional) string with numbering pattern for input files
NUMBERING_SCHEME = -000-000
Expand Down Expand Up @@ -124,39 +125,3 @@ PREFIX =
ME_IMAGE_EXP_DIR = $SP_EXP
ME_IMAGE_EXP_RUNNERS = split_exp_runner, split_exp_runner, split_exp_runner
ME_IMAGE_PATTERN = flag, image, weight


[VIGNETMAKER_RUNNER_RUN_3]

# Cut per-object coadd-frame segmentation stamps from the tile SExtractor
# SEGMENTATION check image (config_tile_Sx.ini: CHECKIMAGE = BACKGROUND,
# SEGMENTATION). Integer labels, no interpolation, zero-padded — CLASSIC mode
# guarantees this. Row-aligned to the tile catalogue on the same XWIN/YWIN
# centres and 51x51 grid as the coadd VIGNET, so ngmix can overlay the seg
# stamp directly for uberseg neighbour masking (shapepipe#776).

INPUT_DIR = run_sp_tile_Sx:sextractor_runner

FILE_PATTERN = sexcat, segmentation

FILE_EXT = .fits, .fits

# NUMBERING_SCHEME (optional) string with numbering pattern for input files
NUMBERING_SCHEME = -000-000

MASKING = False
MASK_VALUE = 0

# CLASSIC: cut stamps at object positions in the coadd (tile) frame.
MODE = CLASSIC

# Coordinate frame type, one in PIX (pixel frame), SPHE (spherical coordinates)
COORD = PIX
POSITION_PARAMS = XWIN_IMAGE,YWIN_IMAGE

# Vignet size in pixels — MUST equal the coadd VIGNET size (51) so the seg
# stamp overlays the galaxy stamp on an identical grid.
STAMP_SIZE = 51

# Output file name prefix, file name is <PREFIX>_vignet.fits
PREFIX = seg
3 changes: 3 additions & 0 deletions example/cfis_image_sims/config_tile_Sx.ini
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ BKG_FROM_HEADER = False
# OBJECTS, -OBJECTS, SEGMENTATION, APERTURES
CHECKIMAGE = BACKGROUND, SEGMENTATION

# Retain tile-grid labels and the pre-join label for exposure registration.
SEG_VIGNET = True

# File name suffix for the output sextractor files (optional)
SUFFIX = sexcat

Expand Down
44 changes: 22 additions & 22 deletions scripts/validation/masked_pixels/dr6_epochs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
Inputs:
* one MegaCam exposure with its weight and flag maps (vos:cfis/pitcairn,
vos:cfis/weights, vos:cfis/flags), e.g. 2086786p.fits.fz;
* the DR6 tile catalogue with VIGNET (-1e30 neighbour and off-tile
markers) and SEG_VIGNET columns, as read_ext_sexcat writes it from
CFIS.<tile>.r.cat and CFIS.<tile>.r.seg.fits.fz
(sexcat-<xxx>-<yyy>.fits).
* the tile catalogue with SEG_LABEL and its matching full segmentation
check image in the same directory (sexcat-<xxx>-<yyy>.fits and
segmentation-<xxx>-<yyy>.fits).

The epoch stamps are cut as vignetmaker does: 51x51 around the rounded
pixel of the object's (XWIN_WORLD, YWIN_WORLD) in the CCD's own WCS, CCDs
numbered as split_exp names them (HDU index - 1). The tile VIGNET and seg
stamp are MegaCam-flipped onto the epoch and split into neighbour and
off-tile pixels (split_tile_markers); the off-tile pixels get zero weight,
as prepare_postage_stamps gives them. The background is a sigma-clipped
numbered as split_exp names them (HDU index - 1). Full tile categories are
sampled on each native exposure grid with register_categories; off-tile
pixels get zero weight as in prepare_postage_stamps. The background is a sigma-clipped
median over the clean pixels of a 257x257 box around the object, and the
background RMS is constant over the stamp; the pipeline takes both from
SExtractor's maps instead. Only the survey flag and weight maps mark
Expand All @@ -37,11 +35,10 @@
from scipy.ndimage import find_objects, label

from shapepipe.modules.ngmix_package.ngmix import (
Ngmix,
defect_mask,
split_tile_markers,
)
from shapepipe.modules.vignetmaker_package.vignetmaker import get_stamps
from shapepipe.modules.vignetmaker_package.vignetmaker import get_stamps, register_categories
from shapepipe.modules.sextractor_package.match_catalogue import relabel

RAD = 25
N = 2 * RAD + 1
Expand All @@ -52,9 +49,13 @@
def read_tile(sexcat):
with fitsio.FITS(sexcat) as f:
hdu = [h for h in f if h.get_extname() == "LDAC_OBJECTS"][0]
return hdu.read(columns=["NUMBER", "XWIN_WORLD", "YWIN_WORLD",
"MAG_AUTO", "FLUX_RADIUS", "VIGNET",
"SEG_VIGNET"])
data = hdu.read(columns=["NUMBER", "XWIN_WORLD", "YWIN_WORLD",
"MAG_AUTO", "FLUX_RADIUS", "SEG_LABEL"])
seg_path = sexcat.replace("sexcat-", "segmentation-")
tile = {name: data[name] for name in data.dtype.names}
tile["segmentation"] = relabel(fits.getdata(seg_path), data["SEG_LABEL"], data["NUMBER"])
tile["wcs"] = WCS(fits.getheader(seg_path))
return tile


def tile_name(sexcat):
Expand All @@ -75,11 +76,10 @@ def ccd_positions(hdus, ra, dec):
return out


def tile_overlay(tile, i, ccd):
tile_vign = Ngmix.MegaCamFlip(np.copy(tile["VIGNET"][i]), ccd)
seg = Ngmix.MegaCamFlip(np.copy(tile["SEG_VIGNET"][i]), ccd)
neighbour, off_tile = split_tile_markers(tile_vign, (N, N))
return seg.astype(np.int32), neighbour, off_tile
def epoch_categories(tile, i, epoch_wcs, int_pos):
maps = register_categories(tile["segmentation"], tile["wcs"], epoch_wcs,
int_pos, (N, N), tile["NUMBER"][i])
return maps["SEG_VIGNET"], maps["NEIGHBOUR"], maps["OFF_TILE"]


def components(defect, flag, off_tile):
Expand Down Expand Up @@ -119,7 +119,7 @@ def cut(hdus, ext, pos, tile, i):
good = (wgt[box] > 0) & (flg[box] == 0)
_, bkg, rms = sigma_clipped_stats(img[box][good], sigma=3.0)
stamps["gal"] = stamps["gal"] - bkg
seg, neighbour, off_tile = tile_overlay(tile, i, ccd)
seg, neighbour, off_tile = epoch_categories(tile, i, WCS(hdus[0][ext].header), int_pos[0])
stamps["weight"][off_tile] = 0
stamps.update(
bkg_rms=np.full((N, N), rms), seg=seg, neighbour=neighbour,
Expand All @@ -138,8 +138,8 @@ def scan(hdus, tile):
continue
wgt = get_stamps(hdus[1][ext].data, pos, RAD)[0]
flg = get_stamps(hdus[2][ext].data, pos, RAD)[0].astype(np.int32)
for i, w, f in zip(rows, wgt, flg):
seg, neighbour, off_tile = tile_overlay(tile, i, ext - 1)
for i, w, f, centre in zip(rows, wgt, flg, np.round(pos).astype(int)):
seg, neighbour, off_tile = epoch_categories(tile, i, WCS(hdus[0][ext].header), centre)
w[off_tile] = 0
defect = defect_mask(w, f)
if not defect.any():
Expand Down
20 changes: 11 additions & 9 deletions scripts/validation/masked_pixels/tile_defect_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
--plot scripts/validation/masked_pixels/tile_defect_flags-TILE.png

All stores open read-only; nothing is written beneath an input directory.
SEXCAT must carry the committed workflow's SEG_VIGNET column. Omit
SEXCAT must carry SEG_VIGNET and image epochs must carry native-grid
SEG_VIGNET, NEIGHBOUR and OFF_TILE categories. Omit
--background only for already background-subtracted images; omit --rms when the run
used stamp-estimated RMS. Pass the production blend/fill choices explicitly.
The output contains every tile row, including unavailable PSFs, zero-kept-
Expand All @@ -37,7 +38,7 @@
from sqlitedict import SqliteDict

from shapepipe.modules.ngmix_package.ngmix import (
EPOCH_INTERPOLATED_DEFECT_RADIUS, Ngmix, Tile_cat, centre_distance,
EPOCH_INTERPOLATED_DEFECT_RADIUS, Postage_stamp, Tile_cat, centre_distance,
prepare_postage_stamps,
)

Expand Down Expand Up @@ -102,13 +103,14 @@ def store(path):
continue
flags = vignet.flag_vign_cat[key]
data["n_candidate"][i] = len(psf)
if footprint.any() and not data["footprint_clipped"][i]:
bits = 0
for name in psf:
own = Ngmix.MegaCamFlip(footprint, int(name.split("-")[1]))
values = np.asarray(flags[name]["VIGNET"])[own]
bits |= int(np.bitwise_or.reduce(values.astype(np.int64)))
data["precut_imaflags_iso"][i] = bits
precut = Postage_stamp()
for name in psf:
epoch_seg = gal[name]["SEG_VIGNET"]
precut.record_footprint_defects(
flags[name]["VIGNET"], np.zeros(epoch_seg.shape, bool),
epoch_seg, obj_id,
)
data["precut_imaflags_iso"][i] = precut.imaflags_iso
# Reuse the fetched flag row when the production preparation reads
# it; no second SQLite fetch is needed for the pre-cut comparison.
per_object = SimpleNamespace(**(vars(vignet) | {
Expand Down
6 changes: 3 additions & 3 deletions src/shapepipe/modules/make_cat_package/make_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def read_sextractor_data(sexcat_path, remove_vignet=True):
sexcat_path : str
Path to SExtractor catalogue
remove_vignet : bool
If ``True`` will not keep the ``VIGNET`` and ``SEG_VIGNET`` stamp
fields
If ``True``, omit ``VIGNET``, ``SEG_VIGNET`` and the registration
bookkeeping field ``SEG_LABEL``.

Returns
-------
Expand All @@ -110,7 +110,7 @@ def read_sextractor_data(sexcat_path, remove_vignet=True):
columns = {
name: data[name]
for name in data.dtype.names
if not (remove_vignet and name in ("VIGNET", "SEG_VIGNET"))
if not (remove_vignet and name in ("VIGNET", "SEG_VIGNET", "SEG_LABEL"))
}

tile_name = os.path.basename(sexcat_path)
Expand Down
Loading
Loading