Compute error bars from cuPhoton by carrying variance planes through alignment, subtraction and measurement, correcting for correlated noise, and reading the transient chain's error budget. Use when a user asks for a flux or position error, a correlation factor, what uq_valid or an _err_ column means, or whether error bars are right. Not for launching the chain or for generic statistics.
Capabilities
Establish the variance planes
Each image needs a plane of per-pixel variance in squared image units
Follow the noise through the difference
Use the basis and kernel size of the user's own subtraction
Correct for correlated noise
Resampling and kernel convolution correlate neighboring pixels
Read the transient chain's error budget
The chain writes _err = sqrt(fit^2 + corr^2 + kfit^2 + kmatch^2 + mis^2)
Getting started
Full instructionsExample command
python -c "import cuphoton, sys; print(cuphoton.__version__, sys.version.split()[0])"Instructions: SKILL.mdv1.0.0
Propagate uncertainty through cuPhoton measurements
Everything here runs on a CPU. Probe the install first.
python -c "import cuphoton, sys; print(cuphoton.__version__, sys.version.split()[0])"
If the import fails, install into a new environment and leave existing ones
alone. The wheels are Linux only, for CPython 3.12 to 3.14.
uv venv --python 3.12 --seed .venv-cuphoton
.venv-cuphoton/bin/python -m pip install "cuphoton==0.2.2"
On macOS or Windows, or where you cannot install, say so and stop before any
step that imports cuPhoton. The two catalog scripts of the last section also
need the catalog extra.
With every error bar, report which variance it used, which effects it includes,
which it leaves out and why, and whether it was checked against data. A NaN
error or a false validity flag is a result to report with its cause. Never fill
it from another column or drop the row silently. Label synthetic results as such.
Establish the variance planes
Each image needs a plane of per-pixel variance in squared image units. Read the
extension name, BUNIT and comments first. A weight map is usually inverse
variance, with 0 marking an unusable pixel. Check sqrt(median variance)
against the robust scatter of an empty region. Convert a weight map with
1 / weight, and set unusable pixels to NaN in the variance and in the image.
A bad pixel that is flagged only in the variance is not always dropped.
forced_flux_at and fit_single_sources drop a pixel whose variance is not
finite or not positive. solve_constant_kernel drops a target pixel whose
variance is not finite, and raises variance must be strictly positive on a
zero. fit_dipoles needs mask= to exclude the pixel. Without it the call
raises variance must be finite and positive on included pixels.
The reference image has no such protection. xRep resamples every finite pixel,
and the kernel fit takes no reference variance. A bad reference value left in
the image shifts the kernel, the flux and the error without a warning.
Without a plane the options narrow.
| Call | Without a variance plane |
|---|---|
fit_dipoles |
runs, and scales the covariance by the fit's reduced chi-square |
fit_single_sources, forced_psf_photometry |
not available, variance is required |
forced_flux_at |
unit weights, and flux_error is not a noise estimate |
Reduced-chi-square errors take one noise level from the stamp's residuals. They
are too small where the noise peaks under the source, and they absorb model
mismatch. With a plane the covariance is not rescaled. A reduced chi-square
near 1 then supports the plane. fit_dipoles takes backend="numpy" on a CPU.
Follow the noise through the difference
| Step | Call | Returns | Leaves out |
|---|---|---|---|
| Align | reproject_masked_array (xRep) |
reference variance on the target grid, through squared interpolation weights | covariance between output pixels |
| Subtract | standardize_constant_kernel_residual (xPois) |
marginal_residual_variance, standardized_residual, valid_mask |
pixel covariance and the kernel fit's own uncertainty |
| Measure | forced_flux_at (xPois), fit_single_sources, forced_psf_photometry, fit_dipoles (xFit) |
flux_error, covariance, standard_errors, uncertainty_valid |
everything not in the variance passed in |
import numpy as np
from cuphoton.xpois import (GaussianBasisComponent, correlation_factor, empirical_correlation_factor,
empty_positions, forced_flux_at, psf_weights, solve_constant_kernel,
standardize_constant_kernel_residual, window_stamps)
from cuphoton.xrep import (BBox, ReprojectionSpec, make_wcs_pair_transform, prepare_reprojection,
reproject_masked_array, resampling_weights_at)
# target, target_var, ref, ref_var: float64 planes; target_wcs, ref_wcs: astropy WCS
# xy: (N, 2) array of (x, y) pixels; psf_sigma: Gaussian PSF sigma in pixels
ref = np.where(np.isfinite(ref_var) & (ref_var > 0), ref, np.nan) # keep bad pixels out of the kernel fit
spec = ReprojectionSpec(mapping=make_wcs_pair_transform(target_wcs, ref_wcs),
output_bbox=BBox(0, 0, target.shape[1], target.shape[0]))
prepared = prepare_reprojection(spec, source_shape=ref.shape)
aligned = reproject_masked_array(ref, ref_var, np.zeros(ref.shape, bool), spec,
backend="cpu", prepared=prepared)
basis = [GaussianBasisComponent(0.7, 2), GaussianBasisComponent(1.5, 2)]
size = 2 * int(np.ceil(5 * psf_sigma)) + 1 # the window the transient chain uses
keep, h = np.ones(target.shape, bool), size // 2 # a changed source inside the fit pulls the kernel
for x, y in np.rint(xy[np.isfinite(xy).all(axis=1)]).astype(int):
keep[max(y - h, 0):max(y + h + 1, 0), max(x - h, 0):max(x + h + 1, 0)] = False
fit = solve_constant_kernel(aligned.image, target, basis, kernel_shape=(11, 11),
variance=target_var, fit_mask=keep, backend="cpu")
noise = standardize_constant_kernel_residual(fit.residual, kernel=fit.kernel, target_variance=target_var,
reference_variance=aligned.variance)
diff, diff_var = fit.residual, noise.marginal_residual_variance
phot = forced_flux_at(diff, xy, psf_sigma, window=size, variance=diff_var, local_sky=False)
Use the basis and kernel size of the user's own subtraction. fit_mask=keep
leaves each candidate's window out of the kernel fit. A source that changed
pulls the kernel when it stays in: one half as bright as the reference source
under it came out 13 percent low. forced_flux_at defaults to
local_sky=True, which subtracts each window's median. Pass local_sky=False
on a difference or any background-subtracted image. Errors are NaN where
uncertainty_valid or valid is false. A forced flux error assumes the
position and PSF width are right. Take the width from stars, never from the
candidate's own fit. For alignment options use cuphoton-align-fits.
A reference without a variance plane has no closed form. Delete the line that
sets ref to NaN, pass np.zeros(ref.shape) as ref_var, and skip the
closed-form lines of the next block, which would return a factor of exactly 1.
diff_var is then the target plane, and the measured factor also holds the
reference noise.
Correct for correlated noise
Resampling and kernel convolution correlate neighboring pixels. A variance
plane holds per-pixel variance only, with no covariance between pixels. The
error of a weighted sum of pixels (a PSF flux, a fitted position) is therefore
understated. The correlation factor f is the variance of the sum with pixel
covariance included, divided by the variance that the plane predicts. The
corrected error is error * sqrt(f). Never quote a resampled image's
per-pixel error as the error bar. The block computes f two ways. The
measured factor comes from forced fluxes at empty positions. The closed form
comes from the kernel, both variance planes and the resampling weights.
# measured: the spread of the same forced flux at empty positions over its own error
valid, scaled = noise.valid_mask, noise.standardized_residual
empty, _ = empty_positions(valid, exclude_xy=xy, window=size, count=500, loud=(scaled, 5.0))
whole = window_stamps(valid, empty, size, fill=0).all(axis=(1, 2)) # every pixel usable
blank = forced_flux_at(diff, empty[whole], psf_sigma, window=size, variance=diff_var, local_sky=False)
pull = (blank.flux / blank.flux_error)[blank.valid]
n, measured, se = pull.size, np.nan, np.nan # unreliable below 20 usable positions
if n >= 2:
measured = (1.4826 * np.median(np.abs(pull - np.median(pull)))) ** 2
se = measured * np.sqrt(2 / (0.3675 * (n - 1))) # a lower bound where windows overlap
fixed = empirical_correlation_factor(diff, diff_var, psf_weights(psf_sigma, size), empty[whole])
# closed form: from the kernel, both variance planes and the resampling weights
taps = resampling_weights_at(spec, xy[:, 0], xy[:, 1], prepared=prepared, source_shape=ref.shape)
weights = psf_weights(psf_sigma, size, offset=xy - np.rint(xy)) / window_stamps(diff_var, xy, size)
closed = correlation_factor(weights, kernel=fit.kernel, target_variance=target_var,
reference_variance=aligned.variance, resampling_weights=taps.weights,
positions=xy, residual_variance=diff_var, is_translation=taps.is_translation)
error = phot.flux_error * np.sqrt(np.maximum(closed.factor, 1.0))
- Which to quote. With both, apply the closed form floored at 1, and
report the measured factor withnandse. The measured factor is a
background value. Compare it with the median closed form atempty[whole]
(the same three calls withempty[whole]in place ofxy), not with the
candidate's. Where it exceeds 1 and that median by more than twose, the
closed form under-predicts. Use the larger of the measured factor and the
candidate's closed form there, as the chain does. Rule out a background
gradient first, which widens the pulls the same way. A sky ramp of one pixel
sigma to each side of a 128 pixel frame raised a factor of 1.6 to 11.7 under
a constant background, andbackground_degree=1insolve_constant_kernel
brought it back. - One image. The measured factor needs only an image and its variance
plane. It works on any resampled image or coadd. Setvalidto the pixels
with a finite value and a finite, positive variance, andscaledto
image / np.sqrt(variance). The closed form also needs the kernel, the
reference plane and the resampling weights. Without them, apply the
measured factor. - Match the estimator.
fdepends on the weights. Measure it with the
weights of the estimator whose error it corrects, local variance and mask
included. The forced flux weights each pixel by PSF over variance. For the
closed form pass those weights, orpsf_weightswithderivative="x"for a
position. Pass asresidual_variancethe variance the measurement used. If
that is the target variance plane,falso includes the reference noise. - Fixed weights.
fixed.factorapplies one stamp to every window. It
equals the forced-flux factor only where the variance is uniform across each
window and no pixel is masked. On windows whose correlated 3 x 3 core has 61
times the background variance, fixed PSF weights give 8.6 and the forced
flux 1.3. Withderivative="x"in the stamp it measures a position's
factor, under the same condition. - Empty windows are background. They lack a bright candidate's own photon
noise, its mask, and the noise of a reference source under it. Where those
shape the weights, use the closed form or label the measured factor as a
background value. Under a bright reference source the background factor is
too small (2.2 against 11.6 in one simulation). Only the closed form applies
there, together with the kernel fit term. - Kernel fit. No factor holds the uncertainty of the fitted kernel, which
grows with the reference flux under the candidate. With the closed form
alone the pull width was 1.05 on a reference source 7 times the candidate's
flux, 1.14 at 20 times and 1.39 at 67 times. Add the term's variance to
error ** 2there, with both calls fromcuphoton.xpois. First
cov = kernel_fit_covariance(fit, reference=aligned.image, target_variance=target_var, reference_variance=aligned.variance, resampling_weights=taps.weights[0]),
with the stamp of a position the reference covers, then
kernel_fit_variance(cov, reference=aligned.image, positions=xy, weights=np.nan_to_num(weights) * phot.flux_error[:, None, None] ** 2).
The three widths became 1.02, 1.03 and 1.02. A flux offset of 0.2 percent of
the reference flux remained. That is kernel mismatch, the chain'skmatch
term, and no error bar here includes it. - The measurement is noisy.
seassumes independent positions, and empty
windows overlap. On a 96 x 96 frame with 300 positions the scatter was 1.45
timesse. Exclude sources withexclude_xyandloud, and statenand
se. Below 20 usable positions report the factor as unreliable, withn,
and do not apply it. The chain measures none there. - A factor below 1. Do not shrink the error bar on that basis. Flooring at
1 is the chain's policy. For a flux a value well below 1 says the plane
overstates the noise for those weights. Report it, and check for noise
counted twice or a plane already inflated for covariance. For a position a
value below 1 can be right where the noise is smoothed wider than the PSF.
closed.factor is NaN for one of three reasons. A measured factor can still
diagnose the noise, labeled as a background measurement. It never replaces an
undefined closed form.
| Cause | Sign | Do |
|---|---|---|
| The grid mapping is not locally a shift, as on a rotated or rescaled reference | closed.n_rotated counts the positions. taps.is_translation is false where taps.jacobian differs from the identity by more than 1e-3 |
Report the corrected error as undefined with that cause, and the diagonal error as uncorrected |
| A window pixel is not finite | closed.n_rotated == 0, and taps.weights is not all zero at the position |
Pass valid=noise.valid_mask to correlation_factor. The factor then covers the usable pixels, and closed.n_masked counts the rest |
| The reference does not cover the position | taps.weights is all zero there |
Nothing restores it, valid= included. Report the error as undefined with that cause |
A position that is not finite or lies off the target grid has no closed form
either. resampling_weights_at raises on it (x and y must be finite,
positions must lie inside the prepared output grid). Leave such rows out of
the three calls and report their error as undefined.
Read the transient chain's error budget
The chain writes <q>_err = sqrt(fit^2 + corr^2 + kfit^2 + kmatch^2 + mis^2)
for center_x, center_y, positive_x, positive_y and psf_flux, with each
term in <q>_err_<term>. To configure and launch the chain use
cuphoton-run-transient-chain. Term inputs, uq keys and summary fields are
in references/BUDGET.md.
- Quote
<q>_err.<q>_err_fitalone is not the budget. Open the item's
summary.jsonfirst.uq_termslists the terms that went in, and
uq.excludedgives the reason for each one left out. An excluded term is
written as 0, which does not mean the effect is zero. Thepsf_fluxterm
columns are NaN instead where forced photometry did not run. A reference
without a variance plane excludescorr. Themeasuredentries under
uq.correlationthen hold the measured factor, which the chain does not
apply. <q>_erris NaN where fewer than half of the quantity's window is usable, a
center's lobe lies beyonduq.max_lobe_reach_px, the fitted position is off
the image, its correlation factor is undefined, or its fit error is not
finite. The term columns keep their values. A finite<q>_err_fitbeside a
NaN<q>_erris not a substitute.uq.invalid_windowcounts the first
three causes,uq.center_reach_exceededthe second, and
uq.undefined_factoranduq.rotated_gridthe fourth.uq_validsays every computed error bar of the row is defined, not that all
terms were available or that the bars are calibrated. A false row can still
hold a finite error for one quantity.- With
uq.enabled: false,<q>_errequals<q>_err_fit, the terms are 0,
no one-lobe refit runs,uq_validis true on every row without any check,
and the summary holds"disabled": true. Present such a catalog as fit-only. sky_err_arcsecis the absolute astrometry the user supplied. It is in
arcseconds, reported apart, and never part of a pixel-frame<q>_err.
Check the error bars against data
| Check | How | Reads as |
|---|---|---|
| Pulls on injected sources | inject known fluxes, measure them as the candidates are measured, take (measured - true) / error |
width near 1 and mean near 0 for calibrated errors |
| Repeat test | repeat_catalogs.py on per-item catalogs of repeated exposures |
positions only, psf_flux is not scored. Chi-square per degree of freedom near 1, per arm with one term removed |
| Reference catalog | compare_catalogs.py --ours ... --reference ... |
counts, match fractions and the largest relative difference of the dipole parameters per item. For pulls, match individual rows. Add their variances only for independent errors. For shared data, include covariance as described in the budget reference |
A pull width above 1 points to missing variance, such as covariance, gain, read
noise, PSF or background. Below 1 points to noise counted twice, selection, or
shared noise. A mean away from 0 is a flux bias (a wrong PSF width, leftover
background) that no error bar includes. Give a width with its sampling error.
Injecting into the difference tests fixed-position photometry only. To test
detection or fitted positions, inject into the input exposures and rerun. The
repeat test cannot see noise or bias shared by every exposure. Both scripts
ship in examples/transient-chain/ of the source at tag v0.2.2, not the
wheel, and import pandas at startup. On the base install even --help fails
with ModuleNotFoundError: No module named 'pandas'. Install
python -m pip install "cuphoton[catalog]==0.2.2" before running them.
The bars are first order, assume the variance planes describe the noise, and
do not cover a mismatched PSF model or the absolute astrometry. Sources:
uncertainty guide,
uncertainty quantification,
how the error bar is built.
Explore more skills
Browse all- Web Performance AuditorAI-powered web performance auditor for frontend and web developers. Use it to audit a website or web app, diagnose poor…
- Deepstream DevNVIDIA DeepStream SDK development with Python pyservicemaker API. Use when building video analytics pipelines,…
- Cdf Event Video GenerationRun the CDF Orchestration Event Video Generation DAG on Kubernetes or OSMO - image-to-video anomaly generation,…
- I4h Catheter NavigationOverview of `workflows/catheter_navigation/` (fluorosim DRR, XPBD physics, vasculature digital twin). Use when the user…
- Doca RmaxDOCA Rivermax (doca_rmax) receive streams for timing-precise media over IP (SMPTE ST 2110 video / audio, market data,…
- Tao Train SegformerSegFormer for semantic segmentation. Lightweight transformer-based architecture with hierarchical feature extraction,…
Security
Signing
SignedSLSA L2- Signed by
- skills-hub.ai distributor
- Method
- Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
- Key
- skills-hub-ed25519-2026-11
- Signed
Reviews (0)
More from skills
View source →Frequently asked questions about cuphoton-propagate-uncertainty
What does the cuphoton-propagate-uncertainty skill do?
Compute error bars from cuPhoton by carrying variance planes through alignment, subtraction and measurement, correcting for correlated noise, and reading the transient chain's error budget. Use when a user asks for a flux or position error, a correlation factor, what uq_valid or an _err_ column means, or whether error bars are right. Not for launching the chain or for generic statistics. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the cuphoton-propagate-uncertainty skill?
Run `npx @skills-hub-ai/cli install skills-cuphoton-propagate-uncertainty` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/skills-cuphoton-propagate-uncertainty/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does cuphoton-propagate-uncertainty work with?
cuphoton-propagate-uncertainty runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the cuphoton-propagate-uncertainty skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use cuphoton-propagate-uncertainty after installing it?
In Claude Code, type `/skills-cuphoton-propagate-uncertainty` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the cuphoton-propagate-uncertainty skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.
Badge for your README
Show that this skill is on Skills Hub. The badge links back to this page and shows the live install count.
[](https://skills-hub.ai/skills/skills-cuphoton-propagate-uncertainty)<a href="https://skills-hub.ai/skills/skills-cuphoton-propagate-uncertainty"><img src="https://skills-hub.ai/api/badges/skill/skills-cuphoton-propagate-uncertainty" alt="Install on Skills Hub"></a>More options in the badge docs.