Variable stars and periods
Stationary variable sources, light curves and periods (Variable stars and light curves).
AsteroidPipeline._filter_high_snr Method
_filter_high_snr(detections, max_relative_error) -> Vectordetections (a table with x, y, flux, flux_err columns) restricted to rows with positive flux and flux_err / flux < max_relative_error — the S/N floor shared by photometric_scale and find_variable_sources, factored out so both apply exactly the same cut.
AsteroidPipeline.find_variable_sources Method
find_variable_sources(detections_per_frame, timestamps;
position_tolerance::Real=2.0,
min_frames::Integer=length(detections_per_frame),
chi2_threshold::Real=10.0,
normalize::Bool=true,
max_relative_error::Real=0.10,
systematic_error_fraction::Real=0.03)Match source detections across frames by consistent position (zero assumed motion) rather than link_candidates's linear-motion model, then keep only sources whose flux is statistically inconsistent with being constant — candidate variable stars or transients.
detections_per_frame holds per-frame detection tables (from detect_sources, with x, y, flux, flux_err columns); timestamps gives each frame's time, as for link_candidates.
Before the test:
S/N floor (
max_relative_error, 10%): detections withflux_err / fluxat or above it are dropped in every frame.Photometric normalization (
normalize): each frame's flux is rescaled byphotometric_scale. Setnormalize=falseiffluxis already calibrated, or on the ZOGY path.Systematic error floor (
systematic_error_fraction, 3%), passed tovariability_chi2, where its calibration is described.
Each frame-1 detection is matched to the closest detection within position_tolerance pixels in every other frame. Groups of at least min_frames points whose reduced chi-squared (chi2 / dof) exceeds chi2_threshold are kept. A small fraction of constant stars still pass: confirm a candidate independently (a VSX/SIMBAD match via crossmatch_catalog, or a period from recover_rotation_period). With the default min_frames, a field where few sources clear the S/N floor in every frame returns few or none.
On the ZOGY path (S_corr detections) a constant star isn't detected at all, so the test only filters subtraction residuals; on the raw path it is what separates a variable from a constant star.
Returns groups of (frame, x, y, flux, flux_err) named tuples sorted by frame, the shape link_candidates returns (with flux normalized when normalize=true), ready for astrometric_calibrate or, with timestamps, for recover_rotation_period.
AsteroidPipeline.photometric_scale Method
photometric_scale(detections_per_frame; position_tolerance::Real=2.0,
max_relative_error::Real=0.10, min_stars::Integer=5) -> Vector{Float64}Per-frame photometric scale factor, relative to frame 1, by ensemble differential photometry, independent of any zeropoint header keyword.
For each frame k, stars are matched to frame 1 by position (within position_tolerance pixels) and the factor is the median of flux_1 / flux_k over matches with flux_err / flux < max_relative_error in both frames, so one noisy or blended star can't swing it. It corrects any uniform per-frame offset, such as a fixed aperture enclosing a seeing-dependent fraction of the PSF (9-13% between ZTF frames).
If fewer than min_stars matches survive for some frame, its factor is left at 1.0 with a warning.
Returns a vector the same length as detections_per_frame; index 1 is always 1.0.
AsteroidPipeline.variability_chi2 Method
variability_chi2(flux, flux_err; systematic_error_fraction::Real=0.03) -> (chi2, dof)Chi-squared goodness of fit of flux against the constant-flux (non-variable) null hypothesis, using the error-weighted mean as the constant-flux estimate. dof is length(flux) - 1 (one free parameter, the mean).
The per-point error is sqrt(flux_err^2 + (systematic_error_fraction * flux)^2): a systematic floor, proportional to flux, added in quadrature. Without it a bright star's tiny formal error makes the test flag flat-fielding and PSF variations that flux_err doesn't model; on ZTF data the false positives were the brightest stars. The 3% default keeps three confirmed variables in three ZTF fields above chi2_threshold=10 while flagging 0.6-2% of constant stars; a 5% floor reaches 0% only by losing two of the variables.
A large chi2 / dof is evidence against the null hypothesis — i.e. evidence of genuine flux variability beyond both statistical noise and this systematic floor. Used by find_variable_sources; exposed separately since a caller may want the raw statistic rather than only a threshold decision.
AsteroidPipeline.fourier_period Method
fourier_period(times, mag; minimum_period, maximum_period, order=4, trend=false,
mag_err=nothing) -> (period, period_error, amplitude, rms, periods, chi2)An asteroid's rotation period from its light curve, the way asteroid photometry measures it: a Fourier series of the rotation phase to order harmonics, fitted to the magnitudes by least squares at each trial period between minimum_period and maximum_period (in the unit of times); the period is where the fit's χ² is least.
An elongated asteroid brightens twice per rotation, and its two maxima and two minima differ. One sinusoid, as in recover_rotation_period's periodogram, fits such a curve best at half the period; the second and higher harmonics tell the two halves apart. 4 is usual for a night or a few; a higher order fits more detail and needs more points. With trend, a straight line in time is fitted with the series, for a drift through the night that isn't the rotation (an unfiltered colour as the airmass changes). mag_err weights the points.
period_error is where χ² grows by 1 from its least, the residuals scaled to unit variance; amplitude is the fitted curve's peak to peak, and rms the residuals'. periods and chi2 (reduced) are the whole search, to see its other minima: half or twice the period, or aliases of the gaps between nights. When
AsteroidPipeline.light_curve Method
light_curve(fits_paths, ra::Real, dec::Real;
timestamp_key::AbstractString="MJD-OBS",
aperture_radius::Real=3.0) -> (times, flux, flux_err)Build a light curve for a confirmed object at a fixed sky position by forced aperture photometry: for each frame in fits_paths, its WCS (via load_wcs) gives the pixel position of (ra, dec), and flux is measured there directly rather than at a detect_sources-found peak — appropriate for rotation-period follow-up, where the object's position is already known precisely (from astrometric_calibrate output) and barely moves between exposures taken close together in time, unlike the original discovery epochs. For a target that moves appreciably over the follow-up sequence, ra/dec need to be recomputed per frame from an ephemeris — not done here.
Background/noise come from Photometry.Background.estimate_background as in detect_sources; flux_err is Photometry.photometry's propagated aperture error from a uniform per-pixel noise, not a full per-pixel variance map.
Returns times (Julian Date), flux, and flux_err, ready for recover_rotation_period.
AsteroidPipeline.moving_light_curve Method
moving_light_curve(fits_paths, positions; aperture_radius=5.0, annulus=(10.0, 15.0),
recentre_snr=5.0, timestamp_key=nothing, exptime_key="EXPTIME",
gain=nothing, reference_stars=nothing) -> TableThe light curve of a moving object: its calibrated brightness in every frame of fits_paths, measured where it is in each, whether or not it was detected there.
positions are rows with ra, dec (degrees) and epoch (JD UTC) — the object's tracklet from astrometric_calibrate, or an ephemeris. Linear motion in RA and Dec, fitted to them by least squares, gives its position at each frame's mid-exposure (frame_epoch); one position means a fixed target. Within a night this is better than an orbit, since it comes from the object itself; it doesn't follow curvature over days.
Each frame's WCS is refined against Gaia DR3 stars (reference_stars, or fetched once for the first frame's field); a frame without one, or whose header WCS can't be refined, is solved from its pointing (solve_wcs); one where none is found is kept, with a warning, as a row of NaN. Frames are measured in parallel on Julia's threads (start Julia with -t auto to use every core); the result doesn't depend on how many. The zero points come from the same comparison stars in every frame: catalogue stars inside all of them, measured with the object's aperture at signal-to-noise 30 or more, away from its track, and dropping any whose brightness varies far more than the others' (a saturated star). Each star's colour differs from the frames' band, unfiltered or not, by its own constant amount, which a fixed set of stars cancels from frame to frame; a set changing with each frame's detections would not. With fewer than 3 such stars, each frame's zero point is fitted on its own (photometric_zeropoint), as is a frame in which fewer than 3 were measured (under cloud), the others keeping theirs. Where the aperture's signal-to-noise reaches recentre_snr, it is moved to the object's flux-weighted centroid; elsewhere the flux is measured at the predicted position (forced photometry), which keeps faint frames in the curve without biasing them upward. The background is the median of annulus; flux_err combines its scatter, the error of that median and, with gain (e-/ADU, else the header's GAIN if it has one), the object's shot noise; mag_err adds the zero point's error, zeropoint_err (the comparison stars' spread about the frame's offset, over the square root of their number).
Returns a table, one row per frame: frame, epoch, ra, dec (where it was measured), x, y, recentred, star_nearby, flux, flux_err, mag, mag_err (Gaia G-equivalent; NaN where the frame has no zero point or the flux isn't positive), zeropoint and zeropoint_err. star_nearby marks a frame where a reference star bright enough to add a tenth of the object's flux (at most 2.5 mag fainter) lies within two aperture radii of it: crossing a star makes it look brighter, so leave those frames out before passing epoch and mag (or flux) to recover_rotation_period.
AsteroidPipeline.object_geometry Method
object_geometry(object, epochs; observatory=nothing) -> TableA solar-system object's geometry at each UTC Julian Date of epochs, from JPL Horizons (a live request): r and delta, its distances from the Sun and from the observer (AU), and phase, the Sun–object–observer angle (degrees). object is looked up among small bodies: a number (624), a designation ("2019 UA185") or a name. The observer is the MPC site observatory, or the Earth's centre.
AsteroidPipeline.recover_rotation_period Method
recover_rotation_period(times, flux; minimum_period, maximum_period) ->
(period, peak_period, power, false_alarm_probability, periodogram)Recover a periodic signal (a rotating object's changing brightness) from a light curve via the Lomb-Scargle periodogram (LombScargle.jl), searching periods between minimum_period and maximum_period (same time unit as times, e.g. days if times are Julian Dates as light_curve returns).
peak_period and power are the periodogram's highest peak, and false_alarm_probability (LombScargle.fap) the probability that noise alone would produce a peak at least this strong; a small value is what distinguishes a real periodic signal from a noise fluctuation.
A light curve with two maxima per cycle, as an elongated asteroid's, puts the highest peak at half the period. period is twice peak_period where alternate cycles differ: four harmonics of the double period fit significantly better (F-test, 0.1%) than two of the peak's. It needs the double period within maximum_period and the light curve to cover it; otherwise, or where the two halves can't be told apart, period is peak_period. fourier_period fits the period itself and gives its uncertainty. periodogram is the full LombScargle.Periodogram, for inspecting other peaks with LombScargle.jl's own tools directly.
AsteroidPipeline.reduced_magnitudes Method
reduced_magnitudes(epochs, mags, geometry; G=0.15) -> (epoch, mag)A moving object's light curve made comparable from night to night. Each magnitude becomes the object's at 1 AU from the Sun and from the observer, mag - 5 log10(r * delta), and each epoch moves back by the light time, to when the light left the object. geometry holds r, delta (AU) and phase (degrees) for each epoch, as object_geometry returns.
With G, the brightening toward opposition is removed as well, by the H-G phase function, which leaves the absolute magnitude H plus the rotation's variation; 0.15 is the usual slope when the object's own isn't known. G=nothing leaves it in, to be fitted together with the period.
Pass the result to recover_rotation_period.