Skip to content

Astrometry ​

World coordinates, exposure times, refitting a frame's astrometry to Gaia DR3, and plate solving.

AsteroidPipeline._strip_fits_cards Method
julia
_strip_fits_cards(header, keywords) -> String

header with any 80-character FITS card whose keyword starts with one of keywords removed. Used by load_wcs to drop the specific legacy keywords that trigger a real wcslib parsing bug — see its docstring.

source
AsteroidPipeline.astrometric_calibrate Method
julia
astrometric_calibrate(tracklets, wcs_per_frame, timestamps)

Convert the pixel positions in tracklets (as returned by link_candidates) to sky coordinates, producing candidates ready for crossmatch_catalog.

wcs_per_frame[k] is the WCS.WCSTransform describing frame k's astrometric solution (see load_wcs); timestamps[k] is that frame's observation epoch (Julian Date), matching the timestamps used by link_candidates.

Returns a flat table with one row per tracklet point, with columns id (the tracklet's index in tracklets), frame, x, y, ra, dec (degrees), and epoch (Julian Date). Since it already carries id, ra, dec, and epoch, this table's rows can be passed directly to crossmatch_catalog.

source
AsteroidPipeline.frame_epoch Method
julia
frame_epoch(header::FITSHeader; timestamp_key=nothing, exptime_key="EXPTIME") -> Float64

A frame's observation epoch as a UTC Julian Date at mid-exposure — what MPC reports require, and what Astrometrica writes into IASC reports.

timestamp_key names the header keyword holding the time: a number is read as a Modified Julian Date (as a Julian Date if the keyword names one, or if it is above 2,400,000), a string as an ISO-8601 date-time (fractional seconds kept). Left nothing, the first of the usual keywords the header has is used: DATE-OBS (with TIME-OBS, UT or UTC when it holds only the date), MJD-OBS, OBSMJD, MJD_OBS, JD, OBSJD, JD-OBS — so images from any telescope that follows one of these conventions need no setting. DATE-OBS first matters for Pan-STARRS1: its MJD-OBS is the shutter time in TAI, 37 s later than its DATE-OBS (UTC), despite TIMESYS = 'UTC'. ZTF has no DATE-OBS; its OBSMJD (UTC) is found.

If the header has exptime_key (seconds), half of it is added: both surveys stamp the start of the exposure. exptime_key=nothing skips that, for a timestamp that already marks mid-exposure.

source
AsteroidPipeline.load_wcs Method
julia
load_wcs(header::AbstractString) -> WCSTransform

Parse the astrometric solution (WCS) from a raw FITS header string — e.g. FITSIO.read_header(hdu, String) — returning the primary WCS.WCSTransform.

Throws an error if the header defines no celestial (RA/Dec) WCS solution: IRAF writes a pixel-to-pixel one (WCSDIM, LTM1_1…) into frames it processed, which would otherwise pass for a solution. If it defines more than one (e.g. alternate WCS descriptions with an a/b/... suffix), the first celestial one is returned.

Pan-STARRS1 headers carry CNPIX1/CNPIX2, a legacy IRAF keyword pair that wcslib takes for the start of a second, implicit WCS; it builds that from uninitialised fields and fails with an error that depends on heap state ("singular", "Invalid parameter value"). On any wcslib error from a header carrying those keywords, the parse is retried with only those two removed.

For a frame with no WCS at all, see solve_wcs, which needs only the pointing, or plate_solve (nova.astrometry.net).

source
AsteroidPipeline.pix_to_sky Method
julia
pix_to_sky(wcs::WCSTransform, x::Real, y::Real) -> (ra, dec)

Convert a single 1-based pixel position (x, y) — matching both Julia's array indexing and the FITS convention — to sky coordinates (right ascension, declination, in degrees) using the astrometric solution wcs.

source
AsteroidPipeline._field_reference_stars Method
julia
_field_reference_stars(image, wcs, epoch_jd) -> Table

gaia_reference_stars covering all of image's footprint (through wcs), with a 10% margin for the header WCS's own error.

source
AsteroidPipeline._gnomonic Method
julia
_gnomonic(ra, dec, crval) -> (xi, eta)

Standard (tangent-plane) coordinates of (ra, dec) about tangent point crval, in degrees — FITS's intermediate world coordinates for a TAN projection, so a linear fit of pixels to these is a TAN WCS solution.

source
AsteroidPipeline._vote_offset Method
julia
_vote_offset(det_xy, predicted, max_offset; bin=2.0) -> ((dx, dy), significance)

The global pixel offset (detected minus predicted) most detection/star pairs agree on: every pair within max_offset votes for its own offset in bin-pixel cells, and the winning cell's pairs are averaged. Random pairings spread their votes thinly over the whole max_offset square; true pairings all land in one cell, so this finds the header's error without needing it to already be small.

Also returns the winning cell's significance: its excess over the median cell, in robust standard deviations of the cells (at least the median's Poisson noise). A frame with thousands of spurious detections fills every cell, and its winner is no higher than chance makes the highest of a few thousand cells, about 4. Inf when most cells are empty: random pairs can't fill a winner then, however few stars a frame holds.

source
AsteroidPipeline.gaia_cache_dir Method
julia
gaia_cache_dir() -> String

Where gaia_reference_stars keeps the answers it got: $XDG_CACHE_HOME (default ~/.cache) /AsteroidPipeline/gaia. Deleting it only costs the queries again.

source
AsteroidPipeline.gaia_reference_stars Method
julia
gaia_reference_stars(ra, dec, radius_deg; epoch_jd::Real, mag_range=(12.0, 21.0),
                     cache=gaia_cache_dir()) -> Table

Gaia DR3 stars within radius_deg of (ra, dec) (degrees), with G magnitude inside mag_range, from the first of three copies of the catalogue that answers: the ESA Gaia archive (gaiadr3.gaia_source), VizieR (I/355/gaiadr3, Strasbourg) and NOIRLab's Astro Data Lab (gaia_dr3.gaia_source, Tucson). One is tried after another on a network error, a timeout or a 5xx status: the first two, both in Europe, were down together for days in October 2026. A service that failed is tried last for the next 15 minutes.

Gaia DR3 doesn't change, so each answer is kept in cache (a directory; nothing to keep none) and the same query is answered from it after, without the network: a field analyzed again, or observed again, costs no query. Offline (analyze_set(...; offline=true)), a query not kept throws OfflineAnswerMissing.

Positions are propagated by proper motion from Gaia DR3's own epoch (J2016.0) to epoch_jd (a Julian Date, normally the frame's own); stars without a proper motion keep their catalogued position. A decade of proper motion is easily a significant fraction of an arcsecond for nearby stars, which is the whole error budget refine_wcs is trying to beat.

Returns a table with columns ra, dec (degrees, at epoch_jd) and gmag, ready to pass to refine_wcs.

source
AsteroidPipeline.refine_wcs Method
julia
refine_wcs(image, wcs, stars; threshold=10.0, mask=nothing, max_offset=60.0,
           match_radius=2.0, min_matches=6, clip_sigma=3.0, min_significance=8.0)
    -> (wcs, refined, n_matches, rms_arcsec, offset_px, n_detections, matches)

Re-derive a frame's astrometric solution from reference stars actually detected in it, rather than trusting the header's — the same job Astrometrica's "Data Reduction" does before any measurement is reported.

image is in the (y, x) order detect_sources takes; wcs is the header's approximate solution; stars is a table of reference stars with ra, dec columns (degrees, at the frame's epoch), e.g. from gaia_reference_stars. Stars are detected at threshold sigma (mask is forwarded to detect_sources), and every catalog star is projected through wcs. The header's error is found first as one global pixel offset — the peak of a vote over every detection/star pair within max_offset pixels — then each star is matched to the nearest detection within match_radius pixels of its offset-corrected position, and a linear tangent-plane (TAN) solution — 6 parameters: shift, scale, rotation, shear — is fitted by least squares to those matches, rejecting matches beyond clip_sigma times the residual RMS and refitting until none are rejected.

If the offset's vote stands less than min_significance robust standard deviations above the other offsets', the frame is left unrefined: a damaged frame (smeared, or full of detector defects) gives thousands of detections, and random pairs then make a false offset win, with hundreds of matches whose RMS is that of chance, match_radius / √2.

Pan-STARRS1 headers can be off by several arcseconds, although their CERROR claims 0.06", far beyond the <1" an MPC report needs; refitted, the residual RMS is ~0.2".

Returns a named tuple: the refined wcs (a plain TAN WCSTransform, tangent point at wcs's own crval), refined (false if fewer than min_matches stars matched — wcs is then the input, unchanged — so a caller can warn instead of failing outright), n_matches, rms_arcsec (the fit's residual RMS; NaN if not refined), and offset_px (the global (dx, dy) offset found, detected minus predicted), and n_detections (sources detected at threshold — compared with the catalog's star count it flags frames full of detector defects; see run_pipeline), and matches (the matched stars, (x, y, ra, dec), before the fit's clipping — what refine_wcs_set pools across frames).

source
AsteroidPipeline.refine_wcs_set Method
julia
refine_wcs_set(images, wcss, stars; masks=nothing, wide_offset_arcsec=77.0,
               max_rms=1.0, iterations=5, rematch_arcsec=2.0, kwargs...) -> Vector

refine_wcs for the frames of one field taken in sequence, fitted together: one result per frame, as refine_wcs's, plus joint (whether the frame's solution came from the joint fit) and shift_only (whether only the header's offset was corrected — see below).

Fitted one frame at a time, a solution rests on the few reference stars matched in that frame (6 to 16 on IASC's Pan-STARRS1 chips), and frames can disagree by several pixels, which makes every star seem to move. The headers' relative alignment is reliable even when their absolute position is 30″ off, so each frame's matches are carried to every other frame's pixels through the headers, and each frame is fitted to all of them. The joint solutions are kept if the headers bear that out: every frame has 3 or more stars of its own, which fitted again with an offset of their own may not need one larger than 3 standard errors plus 0.25 px, and the RMS may not exceed max_rms arcseconds.

Each frame is first matched as refine_wcs does (kwargs are passed on); one that fails is retried searching wide_offset_arcsec, as some headers are further off than refine_wcs's default search, and also solved from its stars (solve_wcs, near the header's centre and scale), the solution matching more stars kept: a raw frame's header may hold only the telescope's pointing, a minute of arc off and turned and scaled enough (half a degree, half a percent) that one offset matches only the stars near the centre. Then the stars are matched again from the fitted solution (within rematch_arcsec), up to iterations times while more of them match: the header's error isn't one offset across a whole chip, so the first match finds only part of the stars. A frame left with under 60% of the best frame's stars starts again from the best one's solution, carried over through the headers and searched for an offset, as raw headers' relative pointing can be several arcseconds off. If the joint fit is rejected, a frame whose own fit failed but with 4 or more stars agreeing on the header's offset gets that offset corrected (shift_only), which keeps it aligned with the others.

source
AsteroidPipeline._astrometry_job_done Method
julia
_astrometry_job_done(job_id) -> Union{Nothing,Bool}

true once job_id has solved successfully; errors immediately on a reported failure (no point continuing to poll); nothing while still processing.

source
AsteroidPipeline._astrometry_poll Method
julia
_astrometry_poll(check, timeout, poll_interval, description) -> Any

Call check() (which returns nothing if not ready yet, or the result to return once it's ready) every poll_interval seconds until it returns non-nothing or timeout seconds have elapsed, in which case this errors mentioning description.

source
AsteroidPipeline._astrometry_submission_job Method
julia
_astrometry_submission_job(subid) -> Union{Nothing,Integer}

The submission's first job id, once it has one; nothing if it doesn't yet (still processing — the API can report a reserved-but-unassigned job slot as a JSON null, i.e. nothing once parsed, as well as an empty jobs array; both mean "not ready").

source
AsteroidPipeline._header_or_solved_wcs Method
julia
_header_or_solved_wcs(image, header_string, header, epoch, cache) -> (wcs, solved)

The frame's WCS from its header (load_wcs) or, when it has none, from solve_wcs at its pointing (frame_pointing). Gaia stars are fetched for the first frame of a field and kept in cache (a _SolveCache) with the scale found, so the other frames of the field are solved from them, or, where too few of their stars match, from the WCS of the frame solved there nearest in time, refined (refine_wcs). Every field is kept: a telescope whose header gives the pointing in two equinoxes, frame by frame, queries Gaia twice, not at every change; and a frame of a known field that none of this solves is not queried for again. With reference_stars, a new field is solved from them before Gaia is queried. solved says which.

source
AsteroidPipeline.frame_pointing Method
julia
frame_pointing(header) -> Union{Nothing,Tuple{Float64,Float64}}

Where the telescope pointed, (ra, dec) in degrees, from the first pair of the usual header keywords: OBJCTRA/OBJCTDEC, RA/DEC, TELRA/TELDEC, RA_OBJ/DEC_OBJ, OBJRA/OBJDEC. A number is degrees; text is sexagesimal, hours for RA. nothing if none is there.

source
AsteroidPipeline.plate_solve Method
julia
plate_solve(image_path; api_key, timeout=300, poll_interval=5) -> WCSTransform

Solve for a FITS image's astrometric (WCS) solution via the nova.astrometry.net web API, for frames with none already in the header that load_wcs can parse — this requires an api_key rather than any local plate-solving dependency.

Runs the full submit/poll/fetch cycle: login with api_key for a session token, upload image_path, poll for a submission to produce a job, poll that job until it succeeds or fails (both loops give up after timeout seconds total, checking every poll_interval seconds), then download and parse the resulting WCS with load_wcs.

Errors (with the service's own message where given) on a login failure, an upload failure, a job that fails to solve, or either poll loop timing out — a frame astrometry.net cannot solve is a real failure, not something to silently pass through.

The round trip is tested against astrometry.net's recorded answers, and live when ENV["ASTROMETRY_API_KEY"] is set.

source
AsteroidPipeline.solve_wcs Method
julia
solve_wcs(image, ra, dec, stars; scale_range=(0.2, 3.0), search_radius=600.0,
          threshold=10.0, mask=nothing, n_bright=30, min_matches=6)
    -> (wcs, refined, n_matches, rms_arcsec, offset_px, n_detections, matches, scale)

A frame's astrometric solution when its header has none, found here rather than by a web service: only the approximate pointing (ra, dec) (degrees, within search_radius arcseconds; frame_pointing reads it from a header) is needed. The pixel scale, anywhere in scale_range (″/px), the orientation and a mirrored axis are found from the stars themselves.

image is in detect_sources's (y, x) order, and stars has ra, dec and gmag for every star the field could hold, e.g. from gaia_reference_stars around the pointing. Triangles of neighbouring stars are compared by the ratios of their sides, which no shift, rotation, scale or mirror changes: the n_bright brightest detections against as many catalogue stars per field area, for each scale tried. Each matching pair of triangles gives a transformation, kept if the most detections land on catalogue stars, and refine_wcs then fits the solution to every star. scale is the solution's pixel scale; refined is false, and wcs nothing, when no transformation put min_matches detections on stars.

source