astrocook.fitting.lsf module#

Exact convolution of a model with the line spread function (#526).

The model flux F is computed on a fine grid, uniform in velocity, and each pixel i of the spectrum gets the mean over its own edges [v_lo_i, v_hi_i] of F convolved with a Gaussian of the resolution of that pixel:

model_i = (1 / (v_hi_i - v_lo_i)) * integral over [v_lo_i, v_hi_i] of (F * G_i)(v) dv
        = integral of F(v) K_i(v) dv / integral of K_i(v) dv,
K_i(v) = Phi((v_hi_i - v) / sigma_i) - Phi((v_lo_i - v) / sigma_i),

with Phi the Gaussian cumulative distribution and sigma_i = c / R_i / (2 sqrt(2 ln 2)). On the fine samples F_j (step 2h) the integral is a sum with weights w_ij, normalised over j:

  • when the kernel is resolved (sigma_i at least one step), w_ij = K_i(v_j): sampling a smooth kernel converges very fast (1e-8 of the continuum against the analytic result for Gaussian lines);

  • without a resolution, or with sigma_i below one step, the kernel has sharp edges and its samples would shift each pixel by up to h, depending on how they fall within it (3e-3 of the continuum on a line with b = 12 km/s). The flux is then taken constant over each cell [v_j - h, v_j + h] and the weight is the exact integral of K_i over it,

    w_ij = r(v_hi_i - v_j + h) - r(v_hi_i - v_j - h)
    • r(v_lo_i - v_j + h) + r(v_lo_i - v_j - h),

    with r(t) = sigma_i G(t / sigma_i), G(u) = u Phi(u) + phi(u); without a resolution, the overlap of the cell with the pixel. The error is then that of a midpoint rule, ~h^2/24 F’’ (up to 3e-3 on a line with b = 1 km/s).

This replaces the convolution on the pixel grid with one kernel width for the whole window (taken at its median wavelength) and no integration over the pixel (findings register F10, F9).

astrocook.fitting.lsf.SIGMA_SAMPLES = 2.0#

half the instrumental sigma, so that the kernel is resolved, and a third of the b of the narrowest line in the pixels (within 1e-5 of the continuum against a mock with 60 sub-pixels, also on saturated lines; with b / 2, up to 4e-4), never below half the smallest b the fitter allows (1 km/s, voigt_model; 2e-4 there) nor above the smallest pixel. Without a resolution, also OVERSAMPLE samples per pixel. Sampling at the pixels alone (before #526) was off by up to 6e-3 at R 45000 and 6e-2 at R 8900

Type:

Fine step (#526, F9)

astrocook.fitting.lsf.CHUNK = 2000#

the weights take n x K values, with K up to a few hundred samples per pixel (low resolution, narrow lines), ~10 MB per array with 2000 pixels

Type:

Pixels per block when the weights are not cached (whole spectra)

astrocook.fitting.lsf.KERNEL_SIGMAS = 5.0#

The kernel is cut at this many sigma

class astrocook.fitting.lsf.PixelLSF(xmin_ang: ndarray, xmax_ang: ndarray, r_min: float | None = None, r_max: float | None = None, b_min: float | None = None, cache: bool = True)[source]#

Bases: object

Fine grid and exact LSF convolution for a set of pixels.

Parameters:
  • xmin_ang (np.ndarray) – Edges of the pixels (Angstrom), increasing.

  • xmax_ang (np.ndarray) – Edges of the pixels (Angstrom), increasing.

  • r_min (float, optional) – Smallest and largest resolving power to be used: the fine grid extends beyond the outer pixels by KERNEL_SIGMAS sigma of r_min, and its step follows the sigma of r_max.

  • r_max (float, optional) – Smallest and largest resolving power to be used: the fine grid extends beyond the outer pixels by KERNEL_SIGMAS sigma of r_min, and its step follows the sigma of r_max.

  • b_min (float, optional) – Doppler parameter (km/s) of the narrowest line in the pixels.

  • cache (bool) – Keep the weights of each resolution, for the many calls of a fit. Without, the weights are computed at each call only for the pixels that have absorption within the reach of their kernel (the others are 1), for a model of the whole spectrum computed once.

__init__(xmin_ang: ndarray, xmax_ang: ndarray, r_min: float | None = None, r_max: float | None = None, b_min: float | None = None, cache: bool = True)[source]#
x_fine#

Fine grid in Angstrom, on which the optical depth is computed

apply(flux_fine: ndarray, resol: None | float | ndarray, key=None) → ndarray[source]#

Flux of each pixel: the fine flux convolved with the LSF of the pixel (resolving power resol, scalar or one per pixel; None or NaN for no LSF) and averaged over the pixel. The weights are cached under key (the resolution itself if scalar or None), unless the pixels are more than CHUNK.