Full Index

FormationTemps.AtmosphereCPUType
AtmosphereCPU{T<:AbstractFloat} <: Atmosphere{T}

CPU-backed atmosphere wrapping a Korg MARCS model.

Fields:

  • Natm: Number of atmosphere layers.
  • τs: Reference optical depth grid (length Natm); empty if tau_ref is unavailable.
  • zs, Ts: Height (cm) and temperature (K) grids.
  • nₑ, nd: Electron and total number density grids.
  • reference_wavelength: MARCS reference wavelength for τ_ref (cm; typically 5000 Å).
  • vx, vy, vz: Per-layer velocity components (m/s).
  • v_mic, v_los: Per-layer microturbulent speed and mean line-of-sight velocity (m/s).

See also: AtmosphereCPU(atm_korg)

source
FormationTemps.AtmosphereCPUMethod
AtmosphereCPU(atm_korg)

Construct an AtmosphereCPU with thermodynamic and velocity fields on the CPU.

The input atmosphere is first resampled onto a uniform log-τ grid to remove non-uniform layer spacing introduced by Korg.interpolate_marcs. If the model does not supply tau_ref (e.g., some non-MARCS grids), resampling is skipped and atm.τs is set to an empty vector — the Bézier τ integrator is used automatically downstream in that case.

source
FormationTemps.AtmosphereGPUType
AtmosphereGPU{T<:AbstractFloat} <: Atmosphere{T}

GPU-backed atmosphere wrapping a Korg MARCS model.

Fields:

  • Natm: Number of atmosphere layers.
  • τs: Reference optical depth grid (length Natm); empty if tau_ref is unavailable.
  • zs, Ts: Height (cm) and temperature (K) grids on the CPU.
  • nₑ, nd: Electron and total number density grids on the CPU.
  • reference_wavelength: MARCS reference wavelength for τ_ref (cm; typically 5000 Å).
  • zs_gpu, Ts_gpu, nd_gpu: Height, temperature, and number density on the device.
  • vx, vy, vz: Per-layer velocity components on the device (m/s). Initialized to zero by the convenience constructor; populated by downstream packages from MHD simulation data.
  • v_mic, v_los: Per-layer microturbulent speed and mean line-of-sight velocity on the device (m/s).

See also: AtmosphereGPU(atm_korg)

source
FormationTemps.AtmosphereGPUMethod
AtmosphereGPU(atm_korg; T=Float64)

Construct an AtmosphereGPU{T} with thermodynamic fields from Korg and velocity fields allocated on the GPU. Pass T=Float32 for single-precision GPU arrays.

Korg always returns Float64 data; the constructor converts all fields (CPU and GPU) to type T.

The input atmosphere is first resampled onto a uniform log-τ grid to remove non-uniform layer spacing introduced by Korg.interpolate_marcs. If the model does not supply tau_ref (e.g., some non-MARCS grids), resampling is skipped and atm.τs is set to an empty vector — the Bézier τ integrator is used automatically downstream in that case.

source
FormationTemps.BatchedMicroConvMemType
BatchedMicroConvMem{T<:AbstractFloat}

Pre-allocated GPU buffers and cuFFT plans for batched Doppler convolution of B tiles simultaneously. The signal FFT is shared across tiles (absorption is tile-independent); only the Doppler filter and convolution product scale with B.

Layout: first dimension is B*Natm for per-tile buffers, Natm for shared buffers. Tile b occupies rows (b-1)*Natm+1 : b*Natm.

See also: ConvolutionMemory, BatchedMicroConvMem(Nλ, Natm, B, Npad)

source
FormationTemps.BatchedMicroConvMemMethod
BatchedMicroConvMem(Nλ, Natm, B, Npad; T=Float64)

Allocate GPU buffers for batched Doppler convolution of B tiles, each with Natm atmosphere rows and wavelength points.

source
FormationTemps.CPUTileWorkspaceType

Pre-allocated per-thread working arrays and FFT infrastructure for the CPU disk integration tile loop. Eliminates per-tile heap allocations so the threaded loop scales without GC contention. Uses padded linear convolution with edge replication and R2C FFT plans, matching the GPU path.

source
FormationTemps.GPUMemoryType
GPUMemory{T<:AbstractFloat}

Pre-allocated GPU working arrays for the radiative transfer computation.

Fields:

  • λs: Wavelength grid on the device (Å), length .
  • αs, τs: Absorption coefficient and optical depth arrays, shape (Natm, Nλ).
  • cfunc, cfunc_dt: Contribution function and dτ-weighted variant, shape (Natm-1, Nλ).
  • tau_ds, tau_alphaC: Bézier τ-integration geometry work arrays; used when use_anchored=false.
  • log_τ_ref, ifactor_base: Anchored τ-integration constants (log τ_ref and τ_ref / α_ref); populated and used when use_anchored=true.
  • use_anchored: true for the anchored d(log τ) integrator; false for the Bézier integrator.
  • v_los_zeros: Pre-allocated zero vector (length Natm) for stationary-frame flux calculations. Used instead of destructively zeroing atm.v_los.

See also: GPUMemory(λs, atm), GPUMemory(λs, atm, α_ref)

source
FormationTemps.GPUMemoryMethod
GPUMemory(λs_cpu, atm, α_ref_cpu)

Allocate GPU working memory using the anchored τ integrator. α_ref_cpu is the continuum absorption coefficient at the MARCS reference wavelength for each layer — αs_cont[:, end] from a prior compute_alpha! call.

source
FormationTemps.GPUMemoryMethod
GPUMemory(λs_cpu, atm)

Allocate GPU working memory using the Bezier τ integrator (backward-compatible default).

source
FormationTemps.MacroConvolutionMemoryMethod
MacroConvolutionMemory(Nλ, Natm, Npad; T=Float64)

Allocate GPU buffers and CUFFT plans for macro-turbulence / rotation convolution of Natm × Nλ matrices. Includes 1D kernel FFT infrastructure.

source
FormationTemps.StellarPropsMethod
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 vector A_X.
  • vsini: projected rotational velocity (m/s).
  • v_macro: macroturbulent velocity scale ζ (m/s); if NaN, uses vmac_fit(Teff, logg).
  • v_micro: microturbulent velocity ξ (m/s). Scalar for uniform broadening; vector of length Natm for per-layer broadening. If scalar NaN, uses vmic_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). ξ is T (scalar) or AbstractVector{T} (per-layer).
  • ρstar, istar: disk integration parameters.

See also: vmac_fit, vmic_fit, calc_formation_temp

source
FormationTemps._apply_fft_kernel!Method
_apply_fft_kernel!(out, ys, kernel_ft, ws, Nrows)

Convolve the first Nrows rows of ys with a pre-computed kernel FFT, writing results into out. Uses padded linear convolution with edge replication and R2C FFT plans from ws (zero heap allocation per row).

source
FormationTemps._convolve_macro_inplace!Method
_convolve_macro_inplace!(out, xs, ys, ζ_rt, μ, ws)

In-place radial-tangential macroturbulence convolution using pre-allocated CPUTileWorkspace buffers. Uses padded linear convolution with edge replication and R2C FFTs, matching the GPU path. When ζ_rt == 0, copies ys into out directly.

source
FormationTemps._convolve_micro_inplace!Method
_convolve_micro_inplace!(out, xs, ys, v_los, v_mic, ws)

In-place microturbulent broadening using pre-allocated CPUTileWorkspace buffers.

Scalar v_los and v_mic build one kernel and apply it to all atmosphere layers (the common case in disk integration). Vector arguments build per-row kernels.

source
FormationTemps._extract_korg_fieldsMethod
_extract_korg_fields(atm_korg)

Resample a Korg model atmosphere onto a uniform log-τ grid, then extract thermodynamic fields into a NamedTuple. Shared by both AtmosphereCPU and AtmosphereGPU constructors.

source
FormationTemps._kernel_to_dft_layout!Method
_kernel_to_dft_layout!(kbuf, kernel, i0)

Place a length-Nλ kernel (with zero-lag at index i0) into a length-L DFT-ordered buffer kbuf (zero-lag at index 1, positive lags next, negative lags at end).

source
FormationTemps._pad_edges!Method
_pad_edges!(dst, src, pad_left, Nλ)

Fill length-L vector dst with edge-replicated padding of src: left pad = src[1], right pad = src[Nλ].

source
FormationTemps._padded_convolveMethod
_padded_convolve(ys::Vector, kernel::Vector; Npad=512)
_padded_convolve(ys::Matrix, kernel::Vector; Npad=512)

CPU padded linear convolution with edge replication using R2C FFT. Matches the GPU convolution strategy (padded signal, zero-padded kernel, extract valid region). Returns an array the same size as ys.

source
FormationTemps._resample_log_tauMethod
_resample_log_tau(atm_korg; n_layers=-1)

Resample a Korg model atmosphere onto a uniform grid in log(τref), returning a new atmosphere of the same type. Returns `atmkorg` unchanged if tau_ref is unavailable.

interpolate_marcs drops layers where the interpolated grid has NaN values (via nanmask), which produces a non-uniform log-τ spacing that contaminates the anchored τ integration scheme. This function detects and removes that discontinuity by re-interpolating all thermodynamic quantities onto a uniform log-τ grid.

By default n_layers matches the input layer count, so the function is a pure spacing fix. Pass an explicit value to upsample or downsample.

source
FormationTemps._select_lines_for_windowMethod
_select_lines_for_window(linelist, λ_start, λ_stop, wing_padding)

Return a view of linelist containing lines whose centers (in Å) fall within [λ_start - wing_padding, λ_stop + wing_padding]. Uses binary search on the sorted linelist for O(log N) per chunk.

source
FormationTemps.batched_macro_multiply_accumulate!Method
batched_macro_multiply_accumulate!(acc_ft, signal_ft, kernel_cache_flat,
                                   μ_idx, dA_tiles, Natm1, Bcur; tile_offset=0)

Launch the batched macro multiply-accumulate kernel. signal_ft is (Bcur*Natm1, nfreq) from a batched forward FFT of padded cfdt. kernel_cache_flat is (N_unique_μ, nfreq). μ_idx maps tile index → row in kernelcacheflat. Result accumulates into acc_ft (Natm1, nfreq).

source
FormationTemps.batched_macro_multiply_accumulate_kernel!Method
batched_macro_multiply_accumulate_kernel!(acc_ft, signal_ft, kernel_cache_flat,
                                          μ_idx, dA_tiles, tile_offset, Natm1, Bcur)

CUDA kernel: for each (layer k, frequency f), loop over B tiles in the batch, multiply the tile's forward-FFT'd signal by its cached macro kernel FFT, weight by dA, and accumulate into the Fourier-space accumulator.

source
FormationTemps.calc_flux_quantitiesMethod
calc_flux_quantities(αs_init, atm, mem, cmem, v_mic)

Compute the disk-center (μ=1, zero rotation) flux contribution function and its optical-depth-weighted differential.

Applies microturbulent broadening (zero Doppler shift), integrates the optical depth using either the anchored or Bézier scheme (as configured in mem), and evaluates the Planck-weighted E₂(τ) contribution function at each layer boundary.

Arguments:

  • αs_init::AbstractMatrix{<:Real}: Absorption coefficients, shape (Natm, Nλ).
  • atm::AtmosphereGPU: GPU atmosphere.
  • mem::GPUMemory: Pre-allocated GPU working arrays.
  • cmem::AbstractConvolutionMemory: Pre-allocated GPU convolution memory.
  • v_mic::Union{T, CuArray{T,1}}: Microturbulent broadening width (m/s). Scalar for uniform broadening; CuVector for per-layer broadening.

Returns:

  • FluxContFunc with fields:
    • cfunc: Flux contribution function C_F, shape (Natm-1, Nλ).
    • cfunc_dt: cfunc .* Δτ, the differential contribution.

See also: calc_intensity_quantities

source
FormationTemps.calc_formation_tempMethod
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 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)
source
FormationTemps.calc_formation_temp_chunkedMethod
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) -> nothing called after each chunk, where ll_chunk is the padded linelist view used for that chunk. When provided, results are not accumulated and the function returns nothing. 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.

source
FormationTemps.calc_intensity_quantitiesMethod
calc_intensity_quantities(αs_init, atm, mem, cmem, μ_tile, v_los, v_mic)

Compute the specific intensity contribution function and its optical-depth-weighted differential for a single disk tile.

Applies microturbulent broadening (with per-layer Doppler shift v_los), integrates the optical depth using either the anchored or Bézier scheme (as configured in mem), and evaluates the Planck-weighted contribution function at each layer boundary.

Arguments:

  • αs_init::AbstractMatrix{<:Real}: Absorption coefficients, shape (Natm, Nλ).
  • atm::AtmosphereGPU: GPU atmosphere.
  • mem::GPUMemory: Pre-allocated GPU working arrays.
  • cmem::AbstractConvolutionMemory: Pre-allocated GPU convolution memory.
  • μ_tile::Real: Cosine of the local zenith angle for this disk tile.
  • v_los::CuArray{<:Real,1}: Per-layer line-of-sight velocity from rotation (m/s).
  • v_mic::Union{T, CuArray{T,1}}: Microturbulent broadening width (m/s). Scalar for uniform broadening; CuVector for per-layer broadening.

Returns:

  • IntensityContFunc with fields:
    • cfunc: Intensity contribution function C_I, shape (Natm-1, Nλ).
    • cfunc_dt: cfunc .* Δτ, the differential contribution.

See also: calc_flux_quantities

source
FormationTemps.calc_stellar_gridMethod
calc_stellar_grid(ρs, i, vsini, Nϕ)

Compute a stellar surface grid on the GPU for disk integration. Geometry follows that from S. S. Vogt et al. (1987) and N. Piskunov & O. Kochukhov (2002).

Arguments:

  • ρs::Real: Stellar radius (in solar radii)
  • i::Real: Inclination in degrees, in the range [-90, 90].
  • vsini::Real: Projected rotational velocity.
  • Nϕ::Int: Number of latitude bins; longitude bins vary with latitude.

Returns:

  • μs::CuArray: Cosine of the angle between the surface normal and the line of sight per tile.
  • dA::CuArray: Projected surface area per tile.
  • z_rot::CuArray: Line-of-sight rotational velocity per tile.
  • z_cbs::CuArray: Additional per-tile velocity term. Disused in this implementation.
source
FormationTemps.calc_tau_anchored_cpu!Method
calc_tau_anchored_cpu!(μ_i, τ_ref, α_ref, αs, τs)

Compute optical depth by integrating in d(log τ_ref) rather than ds, following the "anchored" scheme of Korg (Wheeler et al. 2022, Appendix A.1).

The change of variables τ = ∫ α ds = ∫ (α/αref) dτref eliminates the sensitivity to non-uniform geometric layer spacing in the model atmosphere.

α_ref must be the physical continuum absorption coefficient at the MARCS reference wavelength for each layer, computed from chemistry (not estimated from layer geometry). This is what makes the integration independent of Δz.

source
FormationTemps.calc_tau_anchored_kernel!Method
calc_tau_anchored_kernel!(αs, τs, log_τ_ref, ifactor_base, inv_μ, Nλ)

GPU kernel for anchored τ integration. One thread per wavelength; serial loop over N layers.

Integrates τ[i] = τ[i-1] + 0.5*(f[i-1]+f[i]) * Δ(log τref)[i] where f[k] = αs[k,j] * ifactorbase[k] * invμ and ifactorbase[k] = τref[k] / αref[k].

source
FormationTemps.compute_alpha!Method
compute_alpha!(αs, wls, linelist, atm, A_X, cache; kwargs...)
compute_alpha!(αs, wls, linelist, zs, Ts, nds, nes, A_X, cache; kwargs...)

Cache-accelerated overloads of FormationTemps.compute_alpha!.

These overloads are additive: existing FormationTemps methods remain unchanged.

source
FormationTemps.compute_alpha!Method
compute_alpha!(αs, wls, linelist, atm, A_X; partition_funcs=Korg.default_partition_funcs, ne_warn_thresh=0.1)
compute_alpha!(αs, wls, linelist, zs, Ts, nds, nes, A_X; partition_funcs=Korg.default_partition_funcs, ne_warn_thresh=0.1)

Compute total (continuum + line) absorption coefficients in-place.

Arguments:

  • αs::AbstractArray{<:Real}: Output array for absorption coefficients, sized (Nlayers, Nλ).
  • wls::Korg.Wavelengths: Wavelength grid for the absorption calculation.
  • linelist: Line list passed to Korg.line_absorption!.
  • atm::Atmosphere or (zs, Ts, nds, nes): Atmospheric structure (heights, temperatures, number densities, electron densities).
  • A_X::AbstractVector{<:Real}: Elemental abundances on the usual astronomical scale.
  • partition_funcs=Korg.default_partition_funcs: Partition function table for chemical equilibrium.
  • ne_warn_thresh=0.1: Relative warning threshold for electron density updates.

Returns:

  • nothing: αs is filled in-place.

Notes:

  • Adapted from Korg.line_absorption!.
source
FormationTemps.compute_rt_macro_dft_layout_2d!Method
compute_rt_macro_dft_layout_2d!(kbuf, xs, v_losals, i0, ζ_rt, Nλ, L)

CUDA kernel: evaluate the RT macroturbulence kernel for multiple μ values in parallel, writing directly in DFT layout (zero-lag at index 1). Each row of kbuf (N_unique, L) corresponds to one unique μ value. Skips the roll + ifftshift needed by the serial path.

source
FormationTemps.convolve_gray_rotationMethod
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 on xs (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 as ys.

See also: gray_rot_kernel, convolve_gray_rotation_gpu

source
FormationTemps.convolve_gray_rotation_gpuMethod
convolve_gray_rotation_gpu(cmem, xs, ys, vsini, u1)

GPU implementation of convolve_gray_rotation. Convolves each row of ys with the Gray (2008) rotation kernel using padded FFT convolution on the device.

Arguments:

  • cmem::MacroConvolutionMemory: Pre-allocated GPU working memory.
  • xs::AbstractVector{<:Real}: Wavelength grid (Å).
  • ys::AbstractMatrix{<:Real}: Input matrix with shape (Natm, Nλ).
  • vsini::Real: Projected rotational velocity (m/s).
  • u1::Real: Linear limb-darkening coefficient.

Returns:

  • out::CuArray{<:Real,2}: Convolved matrix on the GPU, same shape as ys.

Notes:

  • CPU and GPU both use padded linear convolution with edge replication.

See also: convolve_gray_rotation, gray_rot_kernel

source
FormationTemps.convolve_hirano_rotmacroMethod
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 on xs (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 as ys.

See also: hirano_rotmacro_ft_kernel, convolve_hirano_rotmacro_gpu

source
FormationTemps.convolve_hirano_rotmacro_gpuMethod
convolve_hirano_rotmacro_gpu(cmem, xs, ys, vsini, ζ_rt, u1, u2; intres=HIRANO_QUADRATURE_NPTS)

GPU implementation of convolve_hirano_rotmacro. Convolves each row of ys with the Hirano et al. (2011) combined rotation+macroturbulence kernel using padded FFT convolution on the device.

Arguments:

  • cmem::MacroConvolutionMemory: Pre-allocated GPU working memory.
  • xs::AbstractVector{<:Real}: Wavelength grid (Å).
  • ys::AbstractMatrix{<:Real}: Input matrix with shape (Natm, Nλ).
  • 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: Quadrature resolution for the kernel integral.

Returns:

  • out::CuArray{<:Real,2}: Convolved matrix on the GPU, same shape as ys.

Notes:

  • Short-circuits (returns CuArray(ys)) when both vsini and ζ_rt are zero.
  • The Hirano FT kernel is computed entirely on the GPU via hirano_rotmacro_ft_kernel_gpu!, then converted to the spatial domain and applied via padded FFT convolution on the device.
  • CPU and GPU both use padded linear convolution with edge replication.

See also: convolve_hirano_rotmacro, hirano_rotmacro_ft_kernel_gpu!

source
FormationTemps.convolve_instrument_gaussMethod
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 on xs.
  • 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 to xs_out.

See also: rebin_spectrum

source
FormationTemps.convolve_iso_rt_macroMethod
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 on xs (vector or matrix with rows as spectra).
  • ζ_rt::Real: Isotropic macroturbulence velocity scale (m/s).

Returns:

  • ys_out::AbstractArray{<:Real}: Convolved spectrum (or ys if ζ_rt == 0).

See also: gray_iso_rt_macro_kernel, convolve_iso_rt_macro_gpu, convolve_rt_macro

source
FormationTemps.convolve_iso_rt_macro_gpuMethod
convolve_iso_rt_macro_gpu(cmem, xs, ys, ζ_rt)

GPU implementation of convolve_iso_rt_macro. Convolves each row of ys with the isotropic radial-tangential macroturbulence kernel using padded FFT convolution on the device.

Arguments:

  • cmem::MacroConvolutionMemory: Pre-allocated GPU working memory.
  • xs::AbstractVector{<:Real}: Wavelength grid (Å).
  • ys::AbstractMatrix{<:Real}: Input matrix with shape (Natm, Nλ).
  • ζ_rt::Real: Isotropic macroturbulence velocity scale (m/s).

Returns:

  • out::CuArray{<:Real,2}: Convolved matrix on the GPU, same shape as ys.

Notes:

  • Short-circuits (returns CuArray(ys)) when ζ_rt is zero.
  • CPU and GPU both use padded linear convolution with edge replication.

See also: convolve_iso_rt_macro, gray_iso_rt_macro_kernel

source
FormationTemps.convolve_rt_macroMethod
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 on xs (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 (or ys if ζ_rt == 0).

See also: rt_macro_kernel, convolve_iso_rt_macro

source
FormationTemps.convolve_rt_macro_gpuMethod
convolve_rt_macro_gpu(cmem, xs, ys, ζ_r, ζ_t, μ)

GPU implementation of convolve_rt_macro(xs, ys, ζ_r, ζ_t, μ). Convolves each row of ys with the anisotropic radial-tangential macroturbulence kernel using padded FFT convolution on the device, allowing independent radial and tangential velocity scales.

Arguments:

  • cmem::MacroConvolutionMemory: Pre-allocated GPU working memory.
  • xs::AbstractVector{<:Real}: Wavelength grid (Å).
  • ys::AbstractMatrix{<:Real}: Input matrix with shape (Natm, Nλ).
  • ζ_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:

  • out::CuArray{<:Real,2}: Convolved matrix on the GPU, same shape as ys.

Notes:

  • Short-circuits (returns CuArray(ys)) when both ζ_r and ζ_t are zero.
  • CPU and GPU both use padded linear convolution with edge replication.

See also: convolve_rt_macro, rt_macro_kernel

source
FormationTemps.convolve_rt_macro_gpuMethod
convolve_rt_macro_gpu(cmem, xs, ys, ζ_rt, μ)

GPU implementation of convolve_rt_macro. Convolves each row of ys with the anisotropic radial-tangential macroturbulence kernel using padded FFT convolution on the device.

Arguments:

  • cmem::MacroConvolutionMemory: Pre-allocated GPU working memory.
  • xs::AbstractVector{<:Real}: Wavelength grid (Å).
  • ys::AbstractMatrix{<:Real}: Input matrix with shape (Natm, Nλ).
  • ζ_rt::Real: Radial-tangential macroturbulence velocity scale (m/s).
  • μ::Real: Cosine of the angle between the local normal and the line of sight.

Returns:

  • out::CuArray{<:Real,2}: Convolved matrix on the GPU, same shape as ys.

Notes:

  • Short-circuits (returns CuArray(ys)) when ζ_rt is zero.
  • CPU and GPU both use padded linear convolution with edge replication.

See also: convolve_rt_macro, rt_macro_kernel

source
FormationTemps.convolve_wavelength_axisMethod
convolve_wavelength_axis(xs, ys, v_los, v_mic)

Convolve each row of ys with a Gaussian kernel that models microturbulent broadening and a Doppler shift, using FFT convolution. The kernel width is wavelength-dependent (constant in velocity units): σ(x) = x·v_mic/c.

Scalar v_los and v_mic apply the same kernel to every row; vectors specify per-row values. The GPU implementation (convolve_wavelength_axis_gpu) builds the same kernel on device, so CPU and GPU agree to floating-point precision.

source
FormationTemps.convolve_wavelength_axis_batched!Method
convolve_wavelength_axis_batched!(bcmem, xs, ys, v_los_batch, v_mic, Bcur)

Batched Doppler convolution for Bcur tiles simultaneously. The absorption signal ys (Natm × Nλ) is shared across tiles; v_los_batch (BcurNatm) provides per-tile velocities. Scalar v_mic avoids tiling allocations; vector v_mic is tiled across tiles. Returns a view of the valid region `(BcurNatm, Nλ)`.

source
FormationTemps.elavMethod
elav(a::AbstractVector)
elav(a; dims)

Compute midpoints between adjacent elements along dims.

source
FormationTemps.get_τsMethod
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).

source
FormationTemps.gray_iso_rt_macro_kernelMethod
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 on vs.

See also: convolve_iso_rt_macro, rt_macro_kernel

source
FormationTemps.gray_rot_kernelMethod
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 on vs.

See also: convolve_gray_rotation

source
FormationTemps.hirano_rotmacro_ft_kernelMethod
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

source
FormationTemps.hirano_rotmacro_ft_kernel_gpu!Method
hirano_rotmacro_ft_kernel_gpu!(Kσ, σs, vsini, ζ_rt, u1, u2, intres, Nσ)

CUDA kernel that computes the Fourier transform of the Hirano et al. (2011) rotation+macroturbulence kernel directly on the GPU. One block per frequency bin; threads within each block split the intres quadrature points and reduce via shared memory.

This is the GPU equivalent of hirano_rotmacro_ft_kernel.

source
FormationTemps.rebin_spectrumMethod
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.

source
FormationTemps.rt_macro_kernelMethod
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 on vs.

See also: convolve_rt_macro

source
FormationTemps.rt_macro_kernelMethod
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 on vs.

See also: convolve_rt_macro, gray_iso_rt_macro_kernel

source
FormationTemps.vmac_fitMethod
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.

source
FormationTemps.vmic_fitMethod
vmic_fit(teff)

Empirical microturbulent velocity fit from Bruntt et al. (2010).

Input teff is in K; returns microturbulent velocity in m/s.

source