src/core/ldspec.js
Limb darkening for ANY bandpass from the wavelength-resolved table (src/data/ld_spectral.js, built from
PHOENIX specific intensities by tools/build_ld_spectral.py; accuracy measured in test/ldspec.test.mjs).
The table holds, for each stellar model node (Teff, log g, [Fe/H]) and each of 357 wavelength bins from 200
to 5500 nm (about lambda / 120 wide: 5 nm below 900 nm, 45 nm at 5.4 micron), the four Claret coefficients of
the bin's intensity profile and the bin's photon-weighted centre intensity F, compressed as a mean plus 40
principal components.
A band is a set of weights w_b over the bins: the fraction of each bin inside a wavelength range, or a
response curve averaged over each bin. Its profile is the photon-weighted mean of the bins' profiles,
I_band(mu) = sum_b w_b F_b I_b(mu) / sum_b w_b F_b,
and because every I_b is 1 at the centre and the Claret law is linear in its coefficients, the band's
four coefficients are the same weighted mean of the bins' coefficients. Nothing is fitted to combine bins.
The stellar dependence is handled exactly as for the bundled 37-band table, by the same code: bandTable()
evaluates the band at every model node and returns a table in that format, so gridFromTable(),
interpLDGrid() and makeLDTie() of ldest.js give the other laws, the trilinear interpolation with its
`clamped` flag, and the function a fit calls. A custom band therefore behaves like a listed one.
No DOM, no three.js. The table module is data only; load it lazily:
const { LD_SPECTRAL_COMPACT } = await import('../data/ld_spectral.js');
const spectral = expandSpectral(LD_SPECTRAL_COMPACT);Import: import { … } from './src/core/ldspec.js' — no DOM, runs in Node and the browser.
expandSpectral
function expandSpectral(t)Decode the compact table (format 'esl-ld-spectral-1') into typed arrays. The result is what every other function here takes as table; treat it as read-only. About 1 ms.
bandWeights
function bandWeights(table, band)Weights of a band over the table's bins.
band = [wlMinNm, wlMaxNm] a boxcar (equal limits: the bin holding that wavelength)
band = { wl: [nm...], response: [...] } a response curve (per photon), linear between its points, 0 outside
Returns { w, b0, b1, coverage, key }: w[b] for b0 <= b < b1 is the mean response over bin b; `coverage` is the
fraction of the band's integrated response that lies inside the table's wavelength range (1 when all of it).
Throws if none of the band is inside.keepPhysical
function keepPhysical(a, margin = 1)Make the Claret coefficients a (array of 4, modified in place) physical in the sense above. Returns true if they had to be changed. margin scales the room kept from the boundary (1: as the builder).
bandTable
function bandTable(table, band, name = 'band')The band evaluated at every stellar model node, as a table in the format of the bundled 37-band table (what expandLDTable() returns: rows with teff, logg, feh, filter, linear, quadratic, nonlinear; one filter, named name). Pass it to gridFromTable() / interpLDGrid() / makeLDTie() of ldest.js, or keep it where the app keeps a loaded table. Profiles are kept physical (keepPhysical); constrained counts the nodes where that changed something, and coverage is the fraction of the band inside the table's wavelength range. Results are cached per table and band (the name is not part of the key: the first name given is kept). Cost: a few ms for a filter, about 40 ms for a band spanning the whole table (plus the constraint, where needed).
bandCoefficients
function bandCoefficients(table, star, band, law = 'nonlinear')Coefficients of `law` ('linear', 'quadratic', 'kipping', 'sqrt', 'nonlinear', 'uniform') for a star in a band.
star = { teff, logg, feh }; band = [wlMinNm, wlMaxNm] or { wl: [...], response: [...] }
Returns { coeffs, clamped, method, coverage, nBins, law }. `clamped` is true when the star is outside the
table (Teff 2300-8000 K, log g 4.0-5.0 or 5.5 below 4000 K, [Fe/H] -0.5 to 0.5; the nearest edge is used)
or when part of the band is outside 200-5500 nm (`coverage` < 1; only the part inside is used).bandProfile
function bandProfile(table, star, band, { nmu = 60, muMin = 0.02 } = {})I(mu)/I(1) of the band for a star, for plotting: { mu, I, coeffs (four Claret coefficients), clamped, coverage }.
mu runs evenly from muMin to 1, the same shape greyProfile() returns. Below mu = 0.1 the law is an
extrapolation of the fit (the model atmospheres have almost no points there).spectralTieSpec
function spectralTieSpec(table, { law, band, logg, teffRange, fehRange })The `ldTie` entry of a fit specification for a custom band: a plain object that survives structured cloning
to the fit worker, in the form makeLDTie() of ldest.js (and so buildProblem) already understands.
opts = { law, band, logg, teffRange: [lo, hi], fehRange: [lo, hi] }makeSpectralTie
function makeSpectralTie(table, opts)(teff, feh, out) -> out for a custom band: what makeLDTie() returns. Allocation-free, about 10 ns a call.binCentres
function binCentres(table)Wavelength (nm) at the middle of each bin and the bins' edges, for plotting coefficients against wavelength.