Image¶
Image reprojection, convolution, and point-source stamp extraction.
Point-source PSF construction lives in the nested
PSF page (noobase.image.psf). Adaptive aperture mask
construction lives in the nested Aperture page
(noobase.aperture).
make_pixel_corners(target_shape, *, target_pixel_to_world, source_world_to_pixel, coarse_step=None)
¶
Build the pixel_corners array consumed by reproject_exact.
Maps every node of the target pixel grid (the frame you are
aligning onto) through target_pixel_to_world and then
source_world_to_pixel to obtain the corresponding location in
the source image's pixel coordinate system (the image you are
reprojecting). The half-pixel corner offset required by the astropy
/ gwcs convention (integer (x, y) is the center of a pixel)
is applied internally so the caller does not have to remember it.
The terminology follows image registration: source is the image
being reprojected (the data you have), target is the frame you
are aligning onto (the goal). In a later call to
reproject_exact, source will be passed as image and
the corner array produced here projects each target pixel into the
source's pixel coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_shape
|
tuple of (int, int)
|
|
required |
target_pixel_to_world
|
callable
|
Forward transform on the target WCS. Signature:: where |
required |
source_world_to_pixel
|
callable
|
Inverse transform on the source WCS. Signature:: where the inputs are the world arrays produced by
|
required |
coarse_step
|
sequence of (int, int)
|
Any 2-element sequence of positive ints — tuple, list, or
ndarray are all accepted. If given as |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Notes
Without coarse_step, the callables are evaluated once on the
full (H_target + 1, W_target + 1) corner grid in a single
vectorised call.
With coarse_step, the bicubic upsampling uses Catmull-Rom
cubic weights with linear extrapolation at the boundary (exact
reconstruction for linear corner fields, residual ~h^2 * curvature
in the boundary cells for smooth fields). For typical astronomical
WCS pairs with coarse_step in the 16-128 range, the residual on
the corner positions is well below 0.01 source-pixel, which is
negligible compared to reprojection's polygon-clip accuracy.
reproject_exact(image, pixel_corners, *, error=None)
builtin
¶
Surface-brightness-conserving exact reprojection of a 2-D image.
The caller supplies an input image on its own pixel grid plus a corner field that gives, for every node of the output pixel grid, the corresponding location in the input image's pixel coordinates. Each output pixel is then computed by polygon-clipping the input pixels that fall under the quadrilateral defined by the four output corners and taking the area-weighted mean of the contributing input values.
This package intentionally does NOT compute the corner field itself: WCS handling belongs in astropy.wcs / gwcs / equivalent. The caller is expected to map output-pixel corners through the two WCSs (output → sky → input) once and hand the resulting array to this function. The reprojection then runs entirely in input-pixel coordinates and does not require any spherical-geometry primitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Input image of shape |
required |
pixel_corners
|
ndarray
|
Corner field of shape |
required |
error
|
ndarray
|
1-sigma error image, same shape and dtype as |
None
|
Returns:
| Type | Description |
|---|---|
ReprojectResult
|
A frozen result object whose
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
Spherical curvature is not corrected: this is a planar polygon clip
in input-pixel space. The residual error is the curvature of the
input projection over a single output pixel, which is negligible for
any reasonable astronomical image. Callers who need an explicit
spherical treatment should pre-correct pixel_corners accordingly.
convolve_psf(image, psf)
builtin
¶
Convolve a 2-D image with a fixed, centered PSF (true convolution).
The PSF is flipped (both axes reversed) before correlation, so this
is genuine convolution: an asymmetric ePSF keeps its orientation.
NaN / +-inf pixels are treated as missing and excluded from both the
weighted sum and its normalizer, and image edges are likewise
missing — this NaN-as-missing renormalization is the image
subsystem's single convention (same as reproject_exact), so there
is deliberately no boundary or renormalize switch.
PSF normalization is the caller's responsibility: a sum-normalized PSF gives an interior identity with the renorm acting only at NaN / edges (flux conserving); an unnormalized PSF yields a local weighted mean instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
2-D image, dtype |
required |
psf
|
ndarray
|
2-D PSF with odd dimensions, same dtype as |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The convolved image, same shape and dtype as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
convolve_gaussian_axis(image, *, sigma, axis=0, normalization='l2', boundary='zero', renormalize=False)
builtin
¶
Correlate every lane along axis with a 1-D Gaussian — the grism
emission-line matched filter.
The kernel is built with the requested normalization ("l2"
makes the peak response the matched-filter S/N-optimal statistic).
This is a correlation; a Gaussian is symmetric so it coincides with
convolution. renormalize=False (the matched filter's natural
mode) uses boundary for out-of-bounds taps; renormalize=True
uses NaN-as-missing renormalization and boundary is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
2-D image, dtype |
required |
sigma
|
float
|
Gaussian sigma in pixels along |
required |
axis
|
int
|
|
0
|
normalization
|
(sum, l2, none)
|
Kernel normalization. Default |
"sum"
|
boundary
|
(zero, reflect, nearest)
|
Out-of-bounds handling, used only when |
"zero"
|
renormalize
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The filtered image, same shape and dtype as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
build_stamp(cutout, stamp_size, *, error=None, mask=None, weight_fwhm=3.0, max_iter=10, tol=0.001)
builtin
¶
Locate an init-quality centroid in a rough cutout, pick an integer-aligned odd square window, and slice a fixed-size stamp.
Single-image leaf for scheme C: the caller loops over N stars, cuts a
rough cutout per star (via its own WCS / distortion), calls
build_stamp on each, filters out the None returns, and stacks
the survivors for build_epsf / build_extended_psf. The
sub-pixel offset is recorded only, never applied (a sub-pixel shift
would correlate the noise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutout
|
ndarray
|
Rough cutout of any shape |
required |
stamp_size
|
int
|
Edge length of the square output stamp. Must be odd. |
required |
error
|
ndarray
|
1-sigma error, same shape and dtype as |
None
|
mask
|
ndarray of bool
|
|
None
|
weight_fwhm
|
float
|
FWHM (pixels) of the Gaussian centroid window. Default |
3.0
|
max_iter
|
int
|
Centroid iteration cap. Default |
10
|
tol
|
float
|
Centroid convergence tolerance (pixels). Default |
0.001
|
Returns:
| Type | Description |
|---|---|
StampResult or None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
StampResult
¶
Result of build_stamp: the integer-window stamp plus the recorded
sub-pixel offset. Constructed by build_stamp; not instantiable
directly.
delta
property
¶
The recorded sub-pixel offset (delta_row, delta_col) =
centroid - round(centroid); each component in [-0.5, 0.5).
error
property
¶
The windowed 1-sigma error of shape (stamp_size, stamp_size),
dtype float64, or None when no error was supplied.
origin
property
¶
(row, col) of the window's top-left corner in cutout-local
indices. Add the caller's own cutout origin to map back to the
source frame.
stamp
property
¶
The extracted stamp of shape (stamp_size, stamp_size), dtype
float64. Carries the original cutout values; no background is
removed (the centroid background subtraction is internal only).
valid
property
¶
Per-pixel validity of shape (stamp_size, stamp_size), dtype
bool. True means valid (positive polarity -- the opposite
of the input mask whose True means invalid).