Reproject FITS exposures onto a chosen reference image with cuPhoton xRep. Use for matching celestial WCS grids, preserving mask bits during resampling, or checking alignment before comparing images.
Capabilities
Align science images
For example, to put two exposures with science in HDU 1 onto the grid of HDU 2 in a
Carry variance and quality flags
Use the masked-array API when the user needs aligned variance and data-quality
Check the result
Report usable overlap for each exposure, including any with no finite coverage
Getting started
Full instructionsInstall the skill, then ask your AI tool for the task in plain words. The full SKILL.md below shows what it covers.
Instructions: SKILL.mdv1.0.0
Align exposures to a reference grid
Identify the destination image and science HDU. Its WCS, shape and orientation
define the output. Inspect the input science headers for a usable celestial WCS and
the pixel units. If the pointing solution is missing or unreliable, report which
input needs an astrometric solution before using xRep.
Align science images
For example, to put two exposures with science in HDU 1 onto the grid of HDU 2 in a
template, use the installed cuPhoton CLI:
cuphoton xrep reproject-stack --inputs a.fits,b.fits --hdu 1 \
--target-wcs template.fits --target-hdu 2 --mapping-grid-step 1 \
--backend cpu --write-fits --output-dir runs --name aligned
Choose a fresh run name. The input HDU index applies to every exposure. If their
science HDUs differ, run them separately against the same destination. A
mapping-grid step of 1 evaluates the mapping at each output pixel, including SIP
distortion. The default step of 100 interpolates the mapping between evaluations.
When only an input carries SIP terms, the resulting offset goes unreported. The
CPU backend provides a reproducible starting point. Use the requested backend
when one is specified.
Keep default area scaling for flux per pixel. For surface brightness, add
--disable-area-scaling so a uniform field retains its value when pixel size
changes. The corresponding Python setting for surface brightness is
area_scaling=False. If the units are unclear, resolve them before choosing the
scaling.
Open runs/aligned/summary.json. Read the cube at saved.stack_fits relative to
that run directory. Plane i corresponds to inputs[i]. Check target_wcs.hdu
and stack_shape against the expected plane count, target height and target width.
Each plane is a separate exposure. The 0.2.2 CLI writes a float32 FITS cube
without the science BUNIT. Report the input units. Set a common output unit only
after verifying or converting every exposure to that unit.
Carry variance and quality flags
Use the masked-array API when the user needs aligned variance and data-quality
planes. Select the actual HDUs and a spare invalid-footprint bit from the dataset's
mask definition. This example assumes extensions named SCI, VAR and DQ, a template
in HDU 2, flux per pixel, and bit value 1 reserved for missing coverage. When
extension names repeat, select the science, variance and mask for the same detector
and extension version. The example reads both WCS solutions together with their
files, so lookup-table distortions apply. For VAR or DQ without a celestial WCS,
confirm from the instrument documentation that the extension shares the SCI pixel
grid. The CLI assumes header-only WCS solutions. A CPDIS lookup table on an input or
the destination raises an error, and a D2IMDIS table is ignored without a
warning. In Python, build such a WCS with WCS(header, fobj=hdul).
import numpy as np
from astropy.io import fits
from astropy.wcs import WCS
from cuphoton.xrep import (
BBox, ReprojectionSpec, make_wcs_pair_transform, reproject_masked_array,
)
with fits.open("template.fits", memmap=False) as tpl:
target = tpl[2].header
target_wcs = WCS(target, fobj=tpl).celestial
with fits.open("a.fits", memmap=False) as src:
sci, var, dq = src["SCI"], src["VAR"], src["DQ"]
science_wcs = WCS(sci.header, fobj=src).celestial
ny, nx = sci.shape
x = np.array([0, nx - 1, 0, nx - 1, (nx - 1) / 2])
y = np.array([0, 0, ny - 1, ny - 1, (ny - 1) / 2])
sky = science_wcs.pixel_to_world(x, y)
for aux in (var, dq):
if aux.shape != sci.shape:
raise ValueError(f"{aux.name} and SCI have different shapes")
aux_wcs = WCS(aux.header, fobj=src)
if aux_wcs.has_celestial:
ax, ay = aux_wcs.celestial.world_to_pixel(sky)
if not np.all(np.hypot(ax - x, ay - y) <= 0.01):
raise ValueError(f"{aux.name} and SCI differ by more than 0.01 pixel")
spec = ReprojectionSpec(
mapping=make_wcs_pair_transform(
target_wcs, science_wcs,
),
output_bbox=BBox(0, 0, target["NAXIS1"], target["NAXIS2"]),
mapping_grid_step=1, area_scaling=True, invalid_mask_value=1,
)
aligned = reproject_masked_array(sci.data, var.data, dq.data, spec, backend="cpu")
Use a variance plane in squared science units and an integer or boolean mask on the
science grid. A boolean mask stays boolean. To distinguish missing coverage, choose
an integer dtype wide enough for every input flag and the footprint bit. The result
holds image, variance and mask. Mask bits propagate
by bitwise OR over contributing pixels. Flagged source values still enter the
interpolation. A NaN science pixel turns every aligned pixel that reads it into
NaN and sets no mask bit. Flag such pixels in DQ before the call, or require
np.isfinite(aligned.image) together with the mask. Apply the relevant bits of
the output mask before measuring the aligned images. The variance uses squared interpolation
weights and represents the diagonal only. If saving these arrays to FITS, give all
three the destination WCS and preserve their respective units and mask-bit
meanings.
For science and DQ alone, import reproject_array from cuphoton.xrep, set
interpolation="bilinear" on the spec, and use
reproject_array(sci.data, spec, source_mask=dq.data, backend="cpu") while the
file is open. This matches the CPU path's four-neighbor mask propagation to the
science interpolation and needs no variance plane. Keep the shape and grid check
for DQ, because reproject_array accepts a mask of another shape without an error.
Check the result
Report usable overlap for each exposure, including any with no finite coverage.
Compare a common isolated source in the overlap across aligned images, measuring
its centroid offset in destination pixels if the data support it. Matching output
headers alone cannot detect inaccurate input astrometry. To check the written
cube's WCS, use WCS(cube_header, naxis=2) and compare sky coordinates at the
center and corners with the destination HDU. For masked data, inspect the
propagated flags and distinguish the reserved footprint bit from defects within the
overlap.
Additional examples are in the cuPhoton 0.2.2 alignment guide.
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-align-fits
What does the cuphoton-align-fits skill do?
Reproject FITS exposures onto a chosen reference image with cuPhoton xRep. Use for matching celestial WCS grids, preserving mask bits during resampling, or checking alignment before comparing images. 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-align-fits skill?
Run `npx @skills-hub-ai/cli install skills-cuphoton-align-fits` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/skills-cuphoton-align-fits/ 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-align-fits work with?
cuphoton-align-fits 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-align-fits 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-align-fits after installing it?
In Claude Code, type `/skills-cuphoton-align-fits` (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-align-fits 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-align-fits)<a href="https://skills-hub.ai/skills/skills-cuphoton-align-fits"><img src="https://skills-hub.ai/api/badges/skill/skills-cuphoton-align-fits" alt="Install on Skills Hub"></a>More options in the badge docs.