astrocook.core.model_grid module#

A model brought onto the grid of a spectrum (phase 7-ter, PR T2).

An external model (a telluric transmission, and in T3-T4 a continuum or an absorption model) is given on a grid of its own: the pixels of the model, with their edges. model_on_grid() gives its values on the pixels of the spectrum:

  • a copy where the model is on the grid of the spectrum: over the pixels where the two overlap, every centre of the model within SAME_GRID_TOLERANCE of a pixel of the spectrum (the axes written in a text file lose a few decimals); the model may cover a part of the spectrum or more than it;

  • otherwise an average over the pixels: for each pixel of the spectrum (xmin-xmax) the mean of the model over that interval, each pixel of the model weighted by its overlap. Where the model does not cover a pixel of the spectrum (beyond its ends, in a gap, over pixels of the model whose value is not finite) it takes the value of the role beyond the model (fill): with a finite one (1 for a transmission) a pixel covered in part is the mean of the model and of fill weighted by their widths; with NaN (a continuum) only the pixels covered in full (COVERED_FRACTION) have a value.

The model is a step function (one value per pixel of the model), so that the average conserves its integral: the equivalent width of a telluric line is the same on the two grids. Pure functions on arrays in one unit; the units are converted by the caller.

astrocook.core.model_grid.SAME_GRID_TOLERANCE = 0.1#

Two grids are the same when every centre of the model is within this fraction of the width of the pixel of the spectrum (T2: the axis of a model written in a text file with fewer decimals than the spectrum, e.g. four decimals in nm at 500 nm on a grid of 1 km/s, ~0.0017 nm, is off by up to 3% of a pixel; a model shifted by less than this is copied). Confirmed by Guido (20 November 2026)

astrocook.core.model_grid.COVERED_FRACTION = 0.999#

A pixel of the spectrum is covered by the model when the model covers this fraction of its width (the edges of a model written in a text file with six decimals in nm are off by up to 3e-4 of a pixel of 1 km/s at 500 nm; those converted between units differ in the last digits). Confirmed by Guido (20 November 2026)

class astrocook.core.model_grid.ModelOnGrid(values: ndarray, covered: ndarray, method: str)[source]#

Bases: object

The values of a model on the pixels of a spectrum.

values: ndarray#

One value per pixel of the spectrum (fill where not covered)

covered: ndarray#

True for the pixels of the spectrum the model covers

method: str#

'copy' or 'average'

__init__(values: ndarray, covered: ndarray, method: str) → None#
astrocook.core.model_grid.auto_edges(x: ndarray) → tuple[ndarray, ndarray][source]#

The edges of contiguous pixels from their centres: each pixel extends half the distance to the previous one on both sides (the first as the second), as the loaders do for a file without edges.

astrocook.core.model_grid.same_grid(x_model: ndarray, x: ndarray, xmin: ndarray, xmax: ndarray) → bool[source]#

Whether the centres of the model are those of the spectrum, within SAME_GRID_TOLERANCE of the width of each pixel.

astrocook.core.model_grid.average_over_pixels(m_xmin: ndarray, m_xmax: ndarray, values: ndarray, xmin: ndarray, xmax: ndarray, fill: float) → ModelOnGrid[source]#

The mean of the model (pixels m_xmin-m_xmax, values) over each pixel of the spectrum (xmin-xmax), with fill where the model does not cover it (module docstring). covered: the pixels covered in full.

astrocook.core.model_grid.model_on_grid(m_x: ndarray, m_xmin: ndarray, m_xmax: ndarray, values: ndarray, x: ndarray, xmin: ndarray, xmax: ndarray, fill: float) → ModelOnGrid[source]#

The model on the pixels of the spectrum: a copy where the model is on the grid of the spectrum (the same grid, or a part of it, or a wider one: same_grid() over their overlap; fill beyond), otherwise the average over the pixels (average_over_pixels()). In a copy, a value of the model that is not finite gets fill, as in the average.