Public Functions
The public functions exported by FormationTemps.jl are documented on this page. The high-level convenience functions should meet the needs of most users. However, some potentially useful, slightly lower-level methods are exposed by FormationTemps.jl and documented below. A full index of all methods defined by FormationTemps.jl is available in the Full Index.
High-level Convenience Functions
FormationTemps.jl provides a few high-level convenience wrappers to produce flux spectra and formation temperatures.
FormationTemps.calc_formation_temp — Function
calc_formation_temp(star, linelist; use_gpu=GPU_DEFAULT, Δλ=0.01,
gpu_precision=Float64, convolve=false,
minλ=NaN, maxλ=NaN, u1=NaN, u2=NaN, Nϕ=128,
showprogress=true, kwargs...)Compute flux formation temperatures, normalized flux, and flux contribution function for a given star and linelist.
The wavelength grid is built from the line list (vacuum cm → Å) with padding and step Δλ. Use minλ/maxλ (Angstrom) to override the default bounds (first/last line ± 2 A).
Returns a FormTempResult with fields:
wavs: wavelength grid (Angstrom).flux: normalized flux (sum(cfunc_dt_flux) / sum(cfunc_dt_flux_cont)).form_temps: formation temperature defined at 50% of the cumulative flux contribution.cont_func: contribution function, shape(Natm - 1, Nλ).atmosphere: atmosphere structure used for the calculation.
If convolve=true, applies Hirano rotation + macroturbulent convolution using limb-darkening coefficients u1 and u2. Otherwise, performs numerical disk integration using Nϕ latitude bins. Set use_gpu=true to use the GPU implementation when available. Set showprogress=false to suppress the progress bar during disk integration.
Pass gpu_precision=Float32 to run GPU computations at single precision. Absorption coefficients are always computed at Float64 (a Korg requirement) and converted to the target precision before GPU upload. This roughly halves GPU memory usage and can improve throughput on consumer GPUs. The default is Float64.
The CPU disk integration path (use_gpu=false, convolve=false) is parallelized across tiles using Threads.@threads. Launch Julia with multiple threads (e.g. julia -t auto) to benefit. FFTW internal threading is disabled during the tile loop to avoid contention. See Parallelization for details.
Examples
star = StellarProps(Teff=5777.0, logg=4.44, Fe_H=0.0, vsini=2100.0)
linelist = Korg.read_linelist(joinpath(FT.datdir, "Sun_VALD.lin"))[1:500]
result = calc_formation_temp(star, linelist; Δλ=0.01, convolve=true, u1=0.43, u2=0.31)
# Float32 GPU:
result32 = calc_formation_temp(star, linelist; Δλ=0.01, gpu_precision=Float32)FormationTemps.calc_formation_temp_chunked — Function
calc_formation_temp_chunked(star, linelist; chunk_width=50.0, wing_padding=30.0,
overlap=5.0, Δλ=0.001, buffer=2.0,
callback=nothing, kwargs...)Compute formation temperatures over an arbitrarily large wavelength range by processing fixed-width wavelength chunks.
Each chunk selects lines within [λ_start - wing_padding, λ_stop + wing_padding], ensuring that broad line wings contribute correctly at chunk boundaries.
Arguments
chunk_width: width of each wavelength chunk in Å.wing_padding: extra range (Å) beyond each chunk edge for linelist selection. 30 Å is conservative enough for the strongest lines (H-alpha, Ca II).overlap: overlap width (Å) between adjacent chunks for smooth stitching.callback: optional(chunk_idx, result::FormTempResult, ll_chunk) -> nothingcalled after each chunk, wherell_chunkis the padded linelist view used for that chunk. When provided, results are not accumulated and the function returnsnothing. Use this for streaming to disk when the full result is too large for RAM.- All other keyword arguments are forwarded to
calc_formation_temp.
When callback=nothing, returns a Vector{FormTempResult} with one entry per chunk. Stitching is the caller's responsibility.
FormationTemps.StellarProps — Type
StellarProps(; Teff=NaN, logg=NaN, Fe_H=NaN, vsini=0.0, v_macro=NaN, v_micro=NaN,
ρstar=1.0, istar=90.0)Container for stellar parameters and broadening properties used by calc_formation_temp.
Keyword arguments:
Teff: effective temperature (K).logg: log10 surface gravity (cgs).Fe_H: metallicity [Fe/H] (dex); used to build the abundance vectorA_X.vsini: projected rotational velocity (m/s).v_macro: macroturbulent velocity scale ζ (m/s); ifNaN, usesvmac_fit(Teff, logg).v_micro: microturbulent velocity ξ (m/s). Scalar for uniform broadening; vector of lengthNatmfor per-layer broadening. If scalarNaN, usesvmic_fit(Teff).ρstar: stellar radius scale factor for disk integration (dimensionless; default 1).istar: stellar inclination (degrees; 90 = equator-on).
Struct fields:
Teff,logg,Fe_H,A_X: atmosphere parameters (A_X is the full abundance vector).vsini,ζ,ξ: rotational, macroturbulent, and microturbulent velocities (m/s).ξisT(scalar) orAbstractVector{T}(per-layer).ρstar,istar: disk integration parameters.
See also: vmac_fit, vmic_fit, calc_formation_temp
FormationTemps.FormTempResult — Type
FormTempResult(wavs, flux, form_temps, cont_func, atmosphere)Container for calc_formation_temp outputs.
Fields:
wavs: wavelength grid (Angstrom).flux: normalized flux across the grid.form_temps: formation temperature (K) at cumulative flux contribution of 0.5.cont_func: differential contribution function (C × Δτ), size(Natm - 1, Nλ).atmosphere: atmosphere structure used for the calculation.
Atmosphere Types
FormTempResult includes an atmosphere field which contains the model atmosphere used in the spectrum modeling.
FormationTemps.Atmosphere — Type
Atmosphere{T}Abstract atmosphere type used by formation temperature calculations.
FormationTemps.get_τs — Function
get_τs(atm)Return the optical depth reference grid as a standard Array. Returns an empty vector when the atmosphere was constructed from a model that does not supply tau_ref (in that case the Bézier τ integrator is used and atm.τs is empty).
FormationTemps.get_zs — Function
get_zs(atm)Return the height grid as a standard Array.
FormationTemps.get_Ts — Function
get_Ts(atm)Return the temperature grid as a standard Array.
Empirical Relations
A few works have reported empirical relationships between fundamental stellar parameters and the measured micro- and macroturbulent velocities. FormationTemps.jl implements these for cases where micro- and macroturbulence are not available.
FormationTemps.vmac_fit — Function
vmac_fit(teff, logg)
vmac_fit(teff)Empirical macroturbulent velocity fits.
vmac_fit(teff, logg) uses the Doyle et al. (2014) relation with teff in K and logg in cgs. vmac_fit(teff) uses the Bruntt et al. (2010) relation with teff in K. Both return the macroturbulent velocity in m/s.
FormationTemps.vmic_fit — Function
vmic_fit(teff)Empirical microturbulent velocity fit from Bruntt et al. (2010).
Input teff is in K; returns microturbulent velocity in m/s.
Resolution Degradation + LSF Modeling
Spectra are synthesized at infinite spectral resolving power (but finite sampling). Since instruments imprint some LSF on spectra, model spectra are generally convolved with model LSFs. Functions for performing these operations are documented here.
FormationTemps.convolve_instrument_gauss — Function
convolve_instrument_gauss(xs, ys; new_res=1.17e5, oversampling=2.0)Convolve a spectrum with a Gaussian LSF at resolving power new_res. The output spectrum is resampled onto a new wavelength grid (evenly spaced in log-wavelength, i.e., velocity) at the specified oversampling factor.
Arguments:
xs::AbstractVector{<:Real}: Input wavelength grid.ys::AbstractVector{<:Real}: Input spectrum sampled onxs.new_res::Real=1.17e5: Target resolving power (λ/Δλ) for the Gaussian LSF.oversampling::Real=2.0: Oversampling factor for the output log-wavelength grid.
Returns:
xs_out::Vector{<:Real}: Output wavelength grid at the requested resolution.ys_out::Vector{<:Real}: Spectrum convolved with the Gaussian LSF and rebinned toxs_out.
See also: rebin_spectrum
FormationTemps.rebin_spectrum — Function
rebin_spectrum(xs_old, ys_old, xs_new)
rebin_spectrum(xs_old, ys_old, σs_old, xs_new)Rebin a spectrum (and optional uncertainties) from xs_old to xs_new.
Based on the SpectRes spectral resampling implementation: https://github.com/ACCarnall/SpectRes/blob/master/spectres/spectral_resampling.py
Note: the algorithm may introduce small shifts if the wavelength grids are misaligned.
Convolutions & Kernels
Convolution operations are often used in the modeling of spectra, even when explicit disk integration is performed (e.g., for microturbulent broadening). FormationTemps.jl exposes these convolution methods.
FormationTemps.convolve_gray_rotation — Function
convolve_gray_rotation(xs, ys, vsini, u1)Convolve a spectrum with the Gray (2008) rotation kernel using linear limb darkening.
Arguments:
xs::AbstractVector{<:Real}: Wavelength grid (Å).ys::AbstractArray{<:Real}: Spectrum onxs(vector or matrix with rows as spectra).vsini::Real: Projected rotational velocity (m/s).u1::Real: Linear limb-darkening coefficient.
Returns:
ys_out::AbstractArray{<:Real}: Convolved spectrum with the same shape asys.
See also: gray_rot_kernel, convolve_gray_rotation_gpu
FormationTemps.convolve_hirano_rotmacro — Function
convolve_hirano_rotmacro(xs, ys, vsini, ζ_rt, u1, u2; intres=HIRANO_QUADRATURE_NPTS)Convolve a spectrum with the Hirano et al. (2011) combined rotation+macroturbulence kernel. The kernel is computed analytically in the Fourier domain and applied via FFT.
Arguments:
xs::AbstractVector{<:Real}: Wavelength grid (Å).ys::AbstractArray{<:Real}: Spectrum onxs(vector or matrix with rows as spectra).vsini::Real: Projected rotational velocity (m/s).ζ_rt::Real: Radial-tangential macroturbulence velocity scale (m/s).u1::Real: Linear limb-darkening coefficient.u2::Real: Quadratic limb-darkening coefficient.intres::Int=HIRANO_QUADRATURE_NPTS: Number of quadrature points for the disk integral.
Returns:
ys_out::AbstractArray{<:Real}: Convolved spectrum with the same shape asys.
See also: hirano_rotmacro_ft_kernel, convolve_hirano_rotmacro_gpu
FormationTemps.convolve_iso_rt_macro — Function
convolve_iso_rt_macro(xs, ys, ζ_rt)Convolve a spectrum with the isotropic radial-tangential macroturbulence kernel from Gray (2008) (Eq. 17.8). This is the disk-integrated (μ-averaged) form appropriate for stellar flux spectra.
Arguments:
xs::AbstractVector{<:Real}: Wavelength grid (Å).ys::AbstractArray{<:Real}: Spectrum onxs(vector or matrix with rows as spectra).ζ_rt::Real: Isotropic macroturbulence velocity scale (m/s).
Returns:
ys_out::AbstractArray{<:Real}: Convolved spectrum (orysifζ_rt == 0).
See also: gray_iso_rt_macro_kernel, convolve_iso_rt_macro_gpu, convolve_rt_macro
FormationTemps.convolve_rt_macro — Function
convolve_rt_macro(xs, ys, ζ_rt, μ)Convolve a spectrum with the anisotropic radial-tangential macroturbulence kernel from Gray (2008) (Eq. 17.6), assuming equal radial and tangential velocity scales (ζ_R = ζ_T).
Arguments:
xs::AbstractVector{<:Real}: Wavelength grid (Å).ys::AbstractArray{<:Real}: Spectrum onxs(vector or matrix with rows as spectra).ζ_rt::Real: Radial-tangential macroturbulence velocity scale (m/s).μ::Real: Cosine of the angle between the local normal and the line of sight.
Returns:
ys_out::AbstractArray{<:Real}: Convolved spectrum (orysifζ_rt == 0).
See also: rt_macro_kernel, convolve_iso_rt_macro
The broadening kernels (which are evaluated internally in the above convolution functions) can also be directly calculated.
FormationTemps.gray_rot_kernel — Function
gray_rot_kernel(vs, vsini, u1)Compute the Gray (2008) rotation broadening kernel (Eq. 18.14) with linear limb darkening.
Arguments:
vs::AbstractVector{<:Real}: Velocity grid centered on the line core (m/s).vsini::Real: Projected rotational velocity (m/s).u1::Real: Linear limb-darkening coefficient.
Returns:
kernel::Vector{<:Real}: Normalized rotation kernel evaluated onvs.
See also: convolve_gray_rotation
FormationTemps.hirano_rotmacro_ft_kernel — Function
hirano_rotmacro_ft_kernel(σs, vsini, ζ_rt; u1=0.43, u2=0.31, intres=HIRANO_QUADRATURE_NPTS)Compute the Fourier transform of the Hirano et al. (2011) rotation+macroturbulence kernel (Eq. B12) by quadrature integration over the visible stellar disk.
Arguments:
σs::AbstractVector{<:Real}: Frequency grid (s/m; inverse of velocity units).vsini::Real: Projected rotational velocity (m/s).ζ_rt::Real: Radial-tangential macroturbulence velocity scale (m/s).u1::Real=0.43: Linear limb-darkening coefficient.u2::Real=0.31: Quadratic limb-darkening coefficient.intres::Int=HIRANO_QUADRATURE_NPTS: Number of quadrature points for the disk integral.
Returns:
Kσ::Vector{<:Real}: Fourier transform of the combined kernel, same length asσs.
See also: convolve_hirano_rotmacro
FormationTemps.gray_iso_rt_macro_kernel — Function
gray_iso_rt_macro_kernel(vs, ζ_rt)Compute the isotropic radial-tangential macroturbulence kernel from Gray (2008) (Eq. 17.8), assuming equal amplitudes (AR = AT) and equal velocity scales (ζR = ζT). The kernel is the disk-integrated (μ-averaged) form.
Arguments:
vs::AbstractVector{<:Real}: Velocity grid centered on the line core (m/s).ζ_rt::Real: Isotropic macroturbulence velocity scale (m/s).
Returns:
kernel::Vector{<:Real}: Normalized macroturbulence kernel evaluated onvs.
See also: convolve_iso_rt_macro, rt_macro_kernel
FormationTemps.rt_macro_kernel — Function
rt_macro_kernel(vs, ζ_rt, μ)Compute the anisotropic radial-tangential macroturbulence kernel from Gray (2008) (Eq. 17.6), assuming equal amplitudes (AR = AT) and equal velocity scales (ζR = ζT).
Arguments:
vs::AbstractVector{<:Real}: Velocity grid centered on the line core (m/s).ζ_rt::Real: Radial-tangential macroturbulence velocity scale (m/s).μ::Real: Cosine of the angle between the local normal and the line of sight.
Returns:
kernel::Vector{<:Real}: Normalized macroturbulence kernel evaluated onvs.
See also: convolve_rt_macro, gray_iso_rt_macro_kernel
rt_macro_kernel(vs, ζ_r, ζ_t, μ)Compute the anisotropic radial-tangential macroturbulence kernel from Gray (2008) (Eq. 17.6) with independent radial and tangential velocity scales, assuming equal amplitudes (AR = AT).
Arguments:
vs::AbstractVector{<:Real}: Velocity grid centered on the line core (m/s).ζ_r::Real: Radial macroturbulence velocity scale (m/s).ζ_t::Real: Tangential macroturbulence velocity scale (m/s).μ::Real: Cosine of the angle between the local normal and the line of sight.
Returns:
kernel::Vector{<:Real}: Normalized macroturbulence kernel evaluated onvs.
See also: convolve_rt_macro
Absorption Cache
AlphaCache provides a reusable cache that accelerates repeated compute_alpha! calls by warm-starting the electron density solver and reusing continuum buffers across calls.
FormationTemps.AlphaCache — Type
AlphaCache(wls, A_X, Nlayers; cntm_step=ANGSTROM_TO_CM, line_buffer=10*ANGSTROM_TO_CM)
AlphaCache(wls, A_X, atm; cntm_step=ANGSTROM_TO_CM, line_buffer=10*ANGSTROM_TO_CM)Reusable cache for accelerated compute_alpha! calls.
This cache implements:
- warm-started electron density guesses across columns,
- precomputed abundance normalization and continuum wavelength grid,
- reusable buffers for chemistry and line-absorption assembly.
Arguments:
wls::Korg.Wavelengths: Wavelength grid for line and continuum absorption.A_X::AbstractVector{<:Real}: Elemental abundances on the usual astronomical scale.Nlayers::Intoratm::Atmosphere: Number of atmosphere layers, or an atmosphere struct.cntm_step: Continuum wavelength step (cm; defaultANGSTROM_TO_CM, i.e. 1 Å).line_buffer: Buffer around the wavelength range for line wings (cm; default 10 Å).
See also: compute_alpha!, set_abundances!, reset_alpha_cache!
Miscellaneous Utilities
FormationTemps.round_to_power — Function
round_to_power(x::Real)Round x to one significant digit based on its order of magnitude.
FormationTemps.elav — Function
elav(a::AbstractVector)
elav(a; dims)Compute midpoints between adjacent elements along dims.
FormationTemps.searchsortednearest — Function
searchsortednearest(a, x)
searchsortednearest(x, a)Return the index of the element in sorted vector a that is closest to x.