Scene rendering & noise (wcc_sim.render)
Place PSF stamps on the detector grid and apply the ETC noise model.
- wcc_sim.render.RENDER_FLOATS_PER_PADDED_PIXEL = 12
float64 alive at the peak of render_subgrid per detector pixel of the stamp-padded footprint (accumulated output, one phase result, oaconvolve blocks); measured maximum 11.9 at k = 1 for stamps of 33-1025 px.
- class wcc_sim.render.StampBlend(w, model, halo, core_scale)[source]
Bases:
objectEverything about one stamp geometry that does not depend on the star.
w is a cosine taper (1 in the core, 0 at r >= half-width) and model is the diffraction wing on the stamp grid; blending the stamp’s outer annulus into the smooth model removes the Airy-ring texture that would otherwise end abruptly at the square stamp edge. halo is the measured scattered-light profile on the same grid, and core_scale the weight on the diffraction term – both inert (0 and 1) when there is no scatter model, which reproduces the diffraction-only rendering exactly.
- wcc_sim.render.wing_blend(n_stamp, wing, blend_start=0.8)[source]
Precompute the stamp->wing crossfade and halo for one stamp geometry.
- wcc_sim.render.unit_stamp(psf_os, sx, sy, oversample, wing=None, blend=None)[source]
Detector-resolution PSF stamp shifted by (sx, sy) fine samples, unit flux scale.
The oversampled PSF is rolled by (sy, sx) fine samples and binned to detector pixels. With a wing model the outer annulus is crossfaded into the smooth wing and the scattered-light halo is added (see wing_blend); the flux normalisation 1 / wing.flux_norm(half) is left to the caller. Shared by add_star (stars) and render_subgrid (images), so both draw the same stamp.
- wcc_sim.render.add_star(image, psf_os, x, y, flux_e, oversample, wing=None, floor_e=None, blend=None)[source]
Add one star at float pixel (x, y), sub-pixel placed, edge-clipped.
Sub-pixel shift is a fine-grid np.roll (error <= 1/(2*oversample) px); rolled wrap-around energy is negligible because stamp edges are ~0.
With a wing model (see wcc_sim.wings), the stamp’s outer annulus is crossfaded into the smooth wing profile and the halo is continued on a circular footprint out to where flux_e * profile(r) < floor_e. Star flux is renormalized by wing.flux_norm(half) for all stars so photometry stays magnitude-independent; the sub-floor halo of faint stars is simply not drawn.
A CombinedWing additionally carries the measured scattered-light halo, which is added across the stamp as well as beyond it.
- wcc_sim.render.render_subgrid(sub, psf_k, wing=None, blend=None)[source]
PSF-convolve light on a detector-aligned sub-grid and bin it to detector pixels.
sub is a resample.Subgrid (data per sub-pixel, k sub-pixels per detector pixel, origin y0, x0); psf_k is the PSF oversampled by the same k. Polyphase rendering: the sub-pixels at offset (p, q) inside their detector pixel all use the same shifted stamp (unit_stamp), so data[p::k, q::k] is convolved with it and the k*k results are summed. Identical to one add_star(floor_e=None) per sub-pixel, at detector resolution only. No halo is drawn beyond the stamp (as in render_extended). Returns a Subgrid with k = 1 whose origin is shifted by half a stamp (the convolution’s border); total_in is passed through.
- wcc_sim.render.render_peak_bytes(box, k, stamp_npix)[source]
Estimated peak memory [bytes] while render_subgrid runs; 0 if box is None.
box : (y0, y1, x0, x1) footprint on the detector; ny, nx = its size [detector px] k : sub-grid factor; the resampled sub-grid (n_sub values) is kept during rendering stamp_npix : PSF stamp [px]; the rendered output covers the stamp-padded footprint
(n_padded detector px)
- wcc_sim.render.render_scene(shape, xs, ys, fluxes_e, psf_os, oversample, wing=None, floor_e=None)[source]
Sum of PSF stamps (e-) for all stars on a float32 (ny, nx) grid.
- wcc_sim.render.star_saturated(satmask, x, y, radius=32)[source]
True if any saturated pixel lies within radius px of (x, y).
A window is used rather than the central pixel alone because the defocused PSFs are centrally depressed: a bright star can saturate its ring while its central pixel stays below full well. The 2-wave defocus PSF’s bright ring extends to ~29 px from center.
- wcc_sim.render.add_noise_and_digitize(image_sources_e, sim, exptime, n_reads, rng, add_noise=True, sky=None)[source]
Apply sky+dark, per-frame saturation, Poisson + read noise, ADU conversion.
ETC semantics (wcc_etc.simulation): read-noise variance scales with n_reads; saturation is evaluated on the per-frame expectation. sky [e-/s/pix, scalar or array broadcastable to the image] replaces the sky rate of sim (the grating sky differs between the two halves).