src/core/data.js
Light curve inputs: synthetic generation and text parsing.
Import: import { … } from './src/core/data.js' — no DOM, runs in Node and the browser.
synthesize
function synthesize(values, ldLaw, o)Simulate an observation of the current system.
o: { exptimeMin, noisePpm, baselineHr (out-of-transit time on each side), airmass (bool), k, seed,
nEpochs (transits observed, default 1), epochStep (orbits between them, default 1) }
The number of points follows from the length of the observation and the exposure.
With several epochs the first is at values.tmid, each has its own noise, and the result
carries the per-point epoch index (see combineEpochs).TIME_SYSTEMS
const TIME_SYSTEMS---- reading files ------------------------------------------------------------------
FLUX_UNITS
const FLUX_UNITSNo description in the source.
TIME_STANDARDS
const TIME_STANDARDS---- time standards --------------------------------------------------------------------------------------------- The offset (TIME_SYSTEMS) says where day zero is; the standard says what the days are: where the clock sits (Earth, Sun, barycentre) and which time scale it keeps (UTC, TDB). Fits want BJD_TDB. A JD in UTC differs from it by up to ±8.3 min plus 69 s, an HJD in UTC by up to ±4 s plus 69 s, a BJD in UTC by 69 s (in 2017-2026).
detectTimeStandard
function detectTimeStandard({ dateType = '', column = '', comments = [], offsetKey = '' } = {})The time standard a file states, from the AAVSO DATE_TYPE line, the time column's name, and comment lines that name it. offsetKey is the TIME_SYSTEMS key the reader chose (BTJD and BKJD are BJD_TDB by definition). Returns { key, from } with key a TIME_STANDARDS key and from saying what it was read from.
heliocentricDelay
function heliocentricDelay(jdUtc, raDeg, decDeg)Light-travel time [days] from the Earth to the Sun's centre along a J2000 target direction (HJD − JD in one scale).
toBjdTdb
function toBjdTdb(t, standard, raDeg, decDeg)One absolute time in a TIME_STANDARDS standard -> BJD_TDB, for a target at J2000 ra, dec (degrees).
JD_UTC: leap seconds, TT − UTC, TDB − TT and the barycentric light time (src/core/fits.js utcToBjdTdb, the photometry
page's conversion). HJD_UTC: the heliocentric light time is taken off first (two iterations). BJD_UTC: TDB − UTC only.parseLightCurve
function parseLightCurve(text, name = 'Uploaded light curve', opts = {})Parse a light curve from text. Understands:
- comma, semicolon, tab, pipe or whitespace separated columns (or an AAVSO "#DELIM=" line)
- a header row, or a header written as the last comment line
("#DATE,DIFF,ERR,DETREND_1,DETREND_2", "# BJD_TDB,Orbital Phase,Flux,Uncertainty,Model,Airmass")
- AAVSO exoplanet reports and EXOTIC FinalLightCurve files, including their "#KEY=VALUE" metadata
- time in JD/BJD, MJD, RJD, BTJD, BKJD or relative days; flux, magnitudes or millimagnitudes
opts.time / opts.flux override the automatic guess ('auto' or a key of TIME_SYSTEMS / FLUX_UNITS).
Time standard: read from DATE_TYPE, the time column's name or comments (detectTimeStandard), or opts.timeStandard
(a TIME_STANDARDS key). JD_UTC, HJD_UTC and BJD_UTC are converted to BJD_TDB when opts.coords = { ra, dec } (J2000
degrees) is given (BJD_UTC needs no position); otherwise a note says plainly that they were not. opts.convertTime
false keeps the times as they are. The result carries timeStandard, timeStandardFrom, timeConverted, timeShiftSec.
Returns { t, f, e, airmass|null, tRef, timeSystem, fluxUnits, meta, notes } or throws a readable error.colName
function colName(h)A column header as a detrending name: centroids are xc and yc, background sky, PSF width fwhm; others lower-cased.
applyDetrend
function applyDetrend(d, detrend)A light curve with its systematics model: from `d.columns` (one array per point, by name) and `detrend` =
{ columns: [names], poly: 0-3, pld: ['pld1', ...], kernel: null | { features: [names], neighbors } } (src/core/detrend.js).
Returns a NEW dataset carrying `detrend`, `regressors` (standardised within each epoch) or null, `kernel` (built epoch by
epoch, so no point borrows neighbours from another night; its n is the number of points) or null, and
`detrendInfo` { names, dropped: [{ name, why }], kernel: features | null }. A null `detrend` takes the model off.nearestEpoch
function nearestEpoch(tmid, per, t)Move tmid by whole periods so the nearest transit falls inside the data.
epochList
function epochList(d)Start, end, size and airmass flag of each epoch of a dataset (one entry when it has no epoch index).
combineEpochs
function combineEpochs(list)Merge light curves of the same planet into one dataset. Each input (itself possibly made of several epochs) keeps its own epochs, so each keeps its own baseline in the fit. Times are put on the reference of the earliest input and sorted; epoch holds each point's epoch index and segments describes the epochs, ordered by start time. Points of epochs without an airmass column get airmass 0, which leaves their baseline flat.
removeEpoch
function removeEpoch(d, s)The dataset without one of its epochs.
splitByOrbit
function splitByOrbit(d, per, tmid, minPoints = 5)Give every orbit covered by a long light curve its own epoch (and so its own baseline): the epoch of a point is the whole number of periods between it and tmid. Returns the dataset unchanged when it covers a single orbit. Only orbits with at least minPoints are kept.
takeColumns
function takeColumns(d, take)The detrending columns (and their settings) of a subset of the points: { columns, detrend } or nothing.
foldTimes
function foldTimes(t, per, tmid)Times folded on the period: each is moved by whole periods to within half a period of tmid.
parseRV
function parseRV(text, name = 'RV')Read radial velocities from text: columns time, velocity, uncertainty and optionally an instrument name, in any order when there is a header ("BJD,Vel(m/s),ErrVel(m/s),Telescope"), otherwise in that order. Rows are grouped by instrument, because each has its own zero point. Velocities are returned in m/s (a header mentioning km/s converts). Times are absolute days. Returns { sets: [{ name, t, v, e }], notes }.