Skip to content

Detection and linking ​

Sources in each frame, median differencing, and tracklets across frames.

AsteroidPipeline._refine_centroid Method
julia
_refine_centroid(subtracted, d1, d2, radius) -> (Float64, Float64)

Refine an integer pixel position (d1, d2) (indices into subtracted's 1st and 2nd dimensions respectively) to a sub-pixel flux-weighted centroid within a radius-pixel window around it — the same first-moment technique estimate_psf already uses per star stamp, applied here per detection instead.

Falls back to the unmodified (d1, d2) (as Float64s) whenever the refinement can't be trusted: the window would run off the array edge, the window's total flux isn't positive, or the computed shift exceeds radius itself (a sign the "centroid" is being pulled toward a neighbor or noise excursion, not the true peak) — never makes the position worse than the raw integer peak it started from.

source
AsteroidPipeline.detect_sources Method
julia
detect_sources(image::AbstractMatrix{<:Real}; threshold::Real,
                box_size::NTuple{2,Integer}=(5, 5), aperture_radius::Real=3.0,
                gain::Union{Nothing,Real}=nothing,
                mask::Union{Nothing,AbstractMatrix{Bool}}=nothing, min_sharpness::Real=-Inf)

Detect point sources in a FITS frame.

The background level and RMS noise are estimated with BackgroundMeshes.estimate_background (SourceExtractorBackground location, MADStdRMS scale — the same estimators used by SourceExtractor/photutils). Local maxima at least threshold sigma above the background, within grid boxes of box_size pixels, are extracted with Photometry.PeakMesh. Each detection's flux is then measured with circular aperture photometry of radius aperture_radius pixels on the background-subtracted image.

Each aperture is centered on a sub-pixel centroid (flux-weighted, within aperture_radius of the peak, or the peak itself when the refinement isn't trustworthy; see _refine_centroid), so the enclosed flux doesn't change with which integer pixel reads highest under noise. The centroid is returned as xcen/ycen, while x/y stay the integer peak; for astrometry the difference is up to half a pixel, and link_candidates uses xcen/ycen when a table has them.

mask (same size as image, true = invalid) excludes pixels with no sky signal: they are left out of the background estimate and set to the background level before peak finding. IASC/Pan-STARRS1 frames need it for the constant-valued gaps between detector cells (see fill_value_mask).

sharpness is the mean of a peak's four direct neighbours over the peak itself (background-subtracted): a star or asteroid spreads its light over several pixels (0.46-0.82 for IASC objects), a cosmic ray or hot pixel doesn't (≈0). Peaks below min_sharpness are dropped, off by default; 0.3 removes single-pixel spikes on stack_difference images and keeps real objects.

Returns a table with columns x, y (pixel position), peak (background- subtracted peak pixel value), flux (aperture sum), flux_err, xcen, ycen and sharpness. By default (gain=nothing) flux_err propagates only the uniform background noise used for detection. Passing gain (electrons/ADU, from the frame's GAIN keyword) adds each pixel's shot noise, sqrt(noise^2 + max(pixel, 0) / gain), which dominates for bright stars and matters for find_variable_sources's chi-squared test.

source
AsteroidPipeline.fill_value_mask Method
julia
fill_value_mask(image::AbstractMatrix{<:Real}; dilate::Integer=1) -> BitMatrix

Mask (true = invalid) of every constant-valued plateau in image: any pixel whose whole 3x3 neighbourhood shares exactly its value, plus that neighbourhood, grown by dilate more pixels. Real sky never does this — even a smooth background carries per-pixel noise — so a plateau is always something written into the frame rather than measured: a fill value, or a saturated star's clipped core.

IASC/Pan-STARRS1 frames need it: the gaps between the detector's cells hold one constant value, marked neither with BLANK nor NaN. Unmasked, each gap edge is a sharp step that background estimation and peak finding treat as signal. Finding plateaus, rather than a particular fill value, works for any survey. Pixels that are not finite, as other images mark theirs (Pan-STARRS1's single-exposure warps among them), are masked too.

Pass the result to detect_sources as mask.

source
AsteroidPipeline._merge_clusters Method
julia
_merge_clusters(detections, radius, max_extent) -> table

Resolve groups of detections that sit within radius pixels of one another (chained: a group is a connected component) in one frame. On a difference image a slow moving object stands alone, but two kinds of real signal fragment into groups of peaks:

  • a fast object's trail, which breaks into several peaks (~24 px at 480"/h in a 45 s exposure), none at its centre;

  • extended junk — a satellite trail hundreds of pixels long, the residual ring of a saturated star.

A group no wider than max_extent pixels (largest separation between its members) becomes one detection at its flux-weighted centroid — the trail's midpoint, i.e. the object's mid-exposure position — with the group's summed flux. Wider groups are dropped. Single detections pass unchanged.

Merging costs isolated objects almost nothing: on a typical difference image a lone object expects ~0.05 chance neighbours within 15 px.

source
AsteroidPipeline.stack_difference Method
julia
stack_difference(images, wcss; masks=nothing, min_valid::Integer=3,
                 bright_star_sigma::Real=50.0, bright_star_radius::Integer=4,
                 halo_factor::Real=3.0, noise_box::Integer=128, subpixel::Bool=false)
    -> (differences, masks)

Difference each frame of a short same-field sequence against the per-pixel median of the whole sequence — a numerical version of the "blink" a human does in Astrometrica, for sequences with no separate deep reference stack (an IASC image set is 4 exposures of one field, nothing else). Anything static (stars, galaxies) is in the median and subtracts away; a moving object is at a different position in each frame, so the median at any one position barely contains it, and it survives in that frame's difference only.

images are (y, x)-ordered matrices (as detect_sources takes), wcss their solutions, used only to align the frames: each frame is shifted onto the first frame's pixel grid by the whole-pixel offset its WCS implies at the image centre (frames of one sequence dither by a few pixels; only relative WCS accuracy matters here, not absolute). masks (true = invalid, e.g. from fill_value_mask) excludes pixels from the median; a pixel needs at least min_valid valid frames (3, so the median of a 4-frame set still out-votes one frame's mover).

Before taking the median each frame is background-subtracted and scaled to a common flux level, fitted from bright pixels, since transparency changes between exposures. Whole-pixel alignment and changing seeing still leave residuals around bright stars, so each connected region where the median exceeds bright_star_sigma times the difference noise is masked out to bright_star_radius plus halo_factor times its own equivalent radius (sqrt(area / π)): a brighter star has a wider halo too.

Each difference is divided by its own local noise, a robust (MAD) estimate in noise_box-pixel boxes, so it is a significance map like ZOGY's S_corr and detect_sources's threshold means the same everywhere, even where detector cells differ in noise.

subpixel=true aligns by the WCS's fractional offsets instead, with bilinear interpolation both ways. Off by default: on objects injected into IASC sets it halved the spurious tracklets near bright stars but recovered 5-9% fewer objects, as interpolation smooths faint ones too.

Returns each frame's normalized difference image, in that frame's own pixel grid (so its own WCS still applies to detections on it), and each frame's mask of pixels with no valid difference.

source
AsteroidPipeline.stack_search Method
julia
stack_search(images, wcss, epochs; masks=nothing, max_rate=100.0,
             peak_threshold=3.0, min_score=7.0, max_negative=Inf) -> (tracklets, threshold)

Find moving objects too faint to be detected in each frame on its own, by adding their light along trial motions. images are a same-field sequence ((y, x) matrices, as detect_sources takes) with their solutions wcss and epochs (Julian Dates), in time order; masks (true = invalid) as for stack_difference, whose normalized differences this searches. max_rate is in arcsec/hour; the slowest motions searched cross twice the FWHM over the sequence, as slower objects subtract themselves in its median.

Each difference is filtered with a Gaussian of the frames' measured FWHM and renormalized to unit noise. Peaks above peak_threshold in the first and the last frame are paired into motions, and each frame is read at the predicted position. The score is the faintest frame's value times √N: every frame must show the object, which keeps one frame's artifact from making a detection. On Pan-STARRS1 sets with injected asteroids it raised those recovered from 77 to 94, all added at V 21.6-23.0.

Several tracks through one spot are dropped, all of them: a point source makes one, a patch of extended light many.

What noise can reach is measured on the same frames: the search is repeated with the frames out of time order, where nothing real lines up, and the threshold is 1.1 times the best score that reaches, at least min_score. On a field whose noise is not Gaussian, the threshold rises and little is found, instead of false candidates.

The artifacts run_pipeline drops are dropped here too: peaks that recur on one detector pixel (_drop_detector_fixed) are masked before the search, and a track passing within 3 FWHM of a masked pixel, or over a bright star's light (_drop_on_bright_background), is left out. So is one whose light, within 4 FWHM, is drawn out into a line (axis ratio above 1.7 in most frames): a bright star's diffraction spike. With max_negative, so is one with a pixel that many σ below zero within 4 px in any frame's difference (_drop_dipoles).

Returns the tracklets as astrometric_calibrate does (id, frame, x, y, ra, dec, epoch, positions refined to a fraction of a pixel on the filtered images) and the threshold used.

source
AsteroidPipeline._closest_detection Method
julia
_closest_detection(detections, pred_x, pred_y, match_radius)

The detection in detections (a table with x, y columns) closest to (pred_x, pred_y), if within match_radius pixels; nothing otherwise.

source
AsteroidPipeline._filter_tracklets Method
julia
_filter_tracklets(tracklets, detections_per_frame, timestamps;
                  min_speed=0.0, max_flux_ratio=Inf, max_residual=Inf, min_frames=3) -> Vector

Drop tracklets that fail IASC's own "true signature" tests (its Signature Guide: a real asteroid moves in a straight line, at constant speed, at fairly constant brightness — "rejected because the magnitude fluctuates by more than 1"). Straight line and constant speed are what link_candidates already enforces; this adds the other two:

  • min_speed (pixels per unit of timestamps): the least-squares speed over the tracklet's own points must reach it. A tracklet barely moving is a static source matched to itself — on a difference image, a residual left by a star.

  • max_flux_ratio: brightest over faintest detection flux must not exceed it (2.5 is IASC's 1 magnitude). Chance alignments of noise peaks rarely keep a steady flux; a real object does. A tracklet longer than min_frames that fails only because of one point — the one farthest from the median flux — is kept without it if the rest passes every test: a faint object at signal-to-noise ~5 in one frame is still the same object.

  • max_residual (pixels): for a tracklet missing some frame, the RMS distance of its points from their own least-squares line must not exceed it. link_candidates accepts any point within match_radius of the line — 7.8 px for IASC sets, wide enough for real motion — so with a frame allowed missing, bent chance alignments of three noise peaks get through; four on one line by chance are rare, so complete tracklets are left alone. On IASC sets, partial tracklets of real objects sat 0.12-0.31 px from their line and spurious ones a median 2.6 px; complete tracklets of faint real objects reached 1.4 px, which is why they are exempt.

With all at their defaults, tracklets is returned unchanged.

source
AsteroidPipeline._linfit Method
julia
_linfit(t, y) -> (intercept, slope)

Ordinary least-squares fit of y = intercept + slope * t.

source
AsteroidPipeline._position Method
julia
_position(d) -> (x, y)

A detection's position: its sub-pixel centroid (xcen, ycen) when the row has one — as detect_sources's do — else its x, y.

source
AsteroidPipeline._refit_tracklet Method
julia
_refit_tracklet(tracklet, timestamps, detections_per_frame, match_radius, max_speed)

Refit tracklet's velocity by least squares over its own matched points (relative to tracklet's first frame's timestamp), then re-match every frame against the refined line. Returns nothing if the refit velocity exceeds max_speed, otherwise the refined tracklet (which may have more or fewer points than the input), sorted by frame.

source
AsteroidPipeline.link_candidates Method
julia
link_candidates(detections_per_frame, timestamps;
                 max_speed::Real=Inf, match_radius::Real=2.0,
                 min_frames::Integer=length(detections_per_frame))

Match source detections across a sequence of frames by consistent linear motion, producing asteroid candidate tracklets.

detections_per_frame is a vector of per-frame detection tables (as returned by detect_sources, each with x, y columns — or, when present, the sub-pixel xcen, ycen columns, used instead); timestamps gives the observation time of each frame, in the same time unit as max_speed (pixels per unit time).

Every pair of detections in the first two frames — or, when min_frames is less than the number of frames, in any two frames — is treated as a trial linear motion vector (rejected up front if its implied speed exceeds max_speed), and matched — closest detection within match_radius pixels of the linear extrapolation — against every other frame; this seed step alone is exact whenever frames 1 and 2's positions already pin down the true velocity. If that seed tracklet reaches at least 3 frames, its velocity is then refit by least squares over all of its matched points, and every frame is re-matched against the refined line — this is what makes the tracklet robust to the seed pair's own position error (from centroiding noise, say): a frame the noisy 2-point seed missed can be picked up by the refit, and conversely a frame it only matched by chance can drop out. If the refit's own velocity exceeds max_speed, the refit is discarded and the tracklet keeps its original seed-built points rather than being dropped outright (the seed itself already passed the max_speed check). min_frames is applied once, after any refit. Distinct seed pairs whose refit converges to the same final point set (more than one can lock onto the same real object) are deduplicated, and so is a tracklet sharing two or more detections with a longer one: two points fix the motion, so it is the same object, seen in fewer frames (in a long sequence, a seed pair far from the object's frames refits onto part of it).

When min_frames allows missing frames, any pair of frames can seed, so an object missing from frame 1 or 2 (a detector gap, a star, the field edge) can still be linked.

Returns a vector of tracklets; each tracklet is a vector of (frame, x, y) named tuples for detections consistent with the same linear motion, sorted by frame.

source