Full Index
FormationTemps.AbstractConvolutionMemory — Type
AbstractConvolutionMemory{T<:AbstractFloat}Abstract supertype for GPU convolution memory structs. Concrete subtypes:
ConvolutionMemory: micro-turbulence path (Doppler filter + batched FFT).MacroConvolutionMemory: macro-turbulence / rotation path (adds 1D kernel FFT plans, padded kernel buffers, and an output extraction buffer).
FormationTemps.AtmosphereCPU — Type
AtmosphereCPU{T<:AbstractFloat} <: Atmosphere{T}CPU-backed atmosphere wrapping a Korg MARCS model.
Fields:
Natm: Number of atmosphere layers.τs: Reference optical depth grid (lengthNatm); empty iftau_refis 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)
FormationTemps.AtmosphereCPU — Method
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.
FormationTemps.AtmosphereGPU — Type
AtmosphereGPU{T<:AbstractFloat} <: Atmosphere{T}GPU-backed atmosphere wrapping a Korg MARCS model.
Fields:
Natm: Number of atmosphere layers.τs: Reference optical depth grid (lengthNatm); empty iftau_refis 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)
FormationTemps.AtmosphereGPU — Method
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.
FormationTemps.BatchedMicroConvMem — Type
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)
FormationTemps.BatchedMicroConvMem — Method
BatchedMicroConvMem(Nλ, Natm, B, Npad; T=Float64)Allocate GPU buffers for batched Doppler convolution of B tiles, each with Natm atmosphere rows and Nλ wavelength points.
FormationTemps.CPUTileWorkspace — Type
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.
FormationTemps.ConvolutionMemory — Type
ConvolutionMemory{T<:AbstractFloat}Pre-allocated GPU buffers and CUFFT plans for batched FFT-based Doppler convolution (micro-turbulence path).
See also: MacroConvolutionMemory, ConvolutionMemory(Nλ, Natm, Npad)
FormationTemps.ConvolutionMemory — Method
ConvolutionMemory(Nλ, Natm, Npad; T=Float64)Allocate GPU buffers and CUFFT plans for micro-turbulence convolution of Natm × Nλ matrices.
FormationTemps.GPUMemory — Type
GPUMemory{T<:AbstractFloat}Pre-allocated GPU working arrays for the radiative transfer computation.
Fields:
λs: Wavelength grid on the device (Å), lengthNλ.α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 whenuse_anchored=false.log_τ_ref,ifactor_base: Anchored τ-integration constants (log τ_refandτ_ref / α_ref); populated and used whenuse_anchored=true.use_anchored:truefor the anchored d(log τ) integrator;falsefor the Bézier integrator.v_los_zeros: Pre-allocated zero vector (lengthNatm) for stationary-frame flux calculations. Used instead of destructively zeroingatm.v_los.
See also: GPUMemory(λs, atm), GPUMemory(λs, atm, α_ref)
FormationTemps.GPUMemory — Method
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.
FormationTemps.GPUMemory — Method
GPUMemory(λs_cpu, atm)Allocate GPU working memory using the Bezier τ integrator (backward-compatible default).
FormationTemps.MacroConvolutionMemory — Type
MacroConvolutionMemory{T<:AbstractFloat}Pre-allocated GPU buffers and CUFFT plans for macro-turbulence / rotation convolution. Extends the base convolution buffers with 1D kernel FFT infrastructure, padded kernel work vectors, and an output extraction buffer.
See also: ConvolutionMemory, MacroConvolutionMemory(Nλ, Natm, Npad)
FormationTemps.MacroConvolutionMemory — Method
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.
FormationTemps.StellarProps — Method
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._allequal — Method
_allequal(v)Check whether all elements of v are equal (short-circuits on first mismatch).
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).
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.
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.
FormationTemps._extract_korg_fields — Method
_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.
FormationTemps._ifftshift_complex! — Method
_ifftshift_complex!(dst, src)Copy real vector src into complex vector dst with ifftshift permutation (zero allocation).
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).
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λ].
FormationTemps._padded_convolve — Method
_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.
FormationTemps._resample_log_tau — Method
_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.
FormationTemps._select_lines_for_window — Method
_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.
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).
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.
FormationTemps.calc_flux_quantities — Method
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:
FluxContFuncwith fields:cfunc: Flux contribution functionC_F, shape(Natm-1, Nλ).cfunc_dt:cfunc .* Δτ, the differential contribution.
See also: calc_intensity_quantities
FormationTemps.calc_formation_temp — Method
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 — Method
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.calc_intensity_quantities — Method
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:
IntensityContFuncwith fields:cfunc: Intensity contribution functionC_I, shape(Natm-1, Nλ).cfunc_dt:cfunc .* Δτ, the differential contribution.
See also: calc_flux_quantities
FormationTemps.calc_stellar_grid — Method
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.
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.
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].
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.
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 toKorg.line_absorption!.atm::Atmosphereor(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:αsis filled in-place.
Notes:
- Adapted from
Korg.line_absorption!.
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.
FormationTemps.convolve_gray_rotation — Method
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_gray_rotation_gpu — Method
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 asys.
Notes:
- CPU and GPU both use padded linear convolution with edge replication.
See also: convolve_gray_rotation, gray_rot_kernel
FormationTemps.convolve_hirano_rotmacro — Method
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_hirano_rotmacro_gpu — Method
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 asys.
Notes:
- Short-circuits (returns
CuArray(ys)) when bothvsiniandζ_rtare 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!
FormationTemps.convolve_instrument_gauss — Method
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.convolve_iso_rt_macro — Method
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_iso_rt_macro_gpu — Method
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 asys.
Notes:
- Short-circuits (returns
CuArray(ys)) whenζ_rtis zero. - CPU and GPU both use padded linear convolution with edge replication.
See also: convolve_iso_rt_macro, gray_iso_rt_macro_kernel
FormationTemps.convolve_rt_macro — Method
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
FormationTemps.convolve_rt_macro_gpu — Method
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 asys.
Notes:
- Short-circuits (returns
CuArray(ys)) when bothζ_randζ_tare zero. - CPU and GPU both use padded linear convolution with edge replication.
See also: convolve_rt_macro, rt_macro_kernel
FormationTemps.convolve_rt_macro_gpu — Method
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 asys.
Notes:
- Short-circuits (returns
CuArray(ys)) whenζ_rtis zero. - CPU and GPU both use padded linear convolution with edge replication.
See also: convolve_rt_macro, rt_macro_kernel
FormationTemps.convolve_rt_macro_gpu_cached — Method
convolve_rt_macro_gpu_cached(cmem, ys, kernel_ft)Convolve ys with a precomputed RT macroturbulence kernel FFT. Skips kernel computation entirely. Use with precompute_rt_macro_kernel_ft.
FormationTemps.convolve_wavelength_axis — Method
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.
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λ)`.
FormationTemps.elav — Method
elav(a::AbstractVector)
elav(a; dims)Compute midpoints between adjacent elements along dims.
FormationTemps.get_Ts — Method
get_Ts(atm)Return the temperature grid as a standard Array.
FormationTemps.get_nd — Method
get_nd(atm)Return the number density grid as a standard Array.
FormationTemps.get_zs — Method
get_zs(atm)Return the height grid as a standard Array.
FormationTemps.get_τs — Method
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.gray_iso_rt_macro_kernel — Method
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.gray_rot_kernel — Method
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 — Method
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.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.
FormationTemps.precompute_rt_macro_kernel_ft — Method
precompute_rt_macro_kernel_ft(cmem, xs, ζ_rt, μ)Precompute the Fourier transform of the RT macroturbulence kernel for a given μ. Returns a CuVector{Complex{T}} that can be passed to convolve_rt_macro_gpu_cached.
FormationTemps.rebin_spectrum — Method
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.
FormationTemps.reset_alpha_cache! — Method
reset_alpha_cache!(cache)Drop warm-start state while keeping allocated buffers.
FormationTemps.round_to_power — Method
round_to_power(x::Real)Round x to one significant digit based on its order of magnitude.
FormationTemps.rt_macro_kernel — Method
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
FormationTemps.rt_macro_kernel — Method
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
FormationTemps.searchsortednearest — Method
searchsortednearest(a, x)
searchsortednearest(x, a)Return the index of the element in sorted vector a that is closest to x.
FormationTemps.set_abundances! — Method
set_abundances!(cache, A_X)Refresh cached absolute abundances after changing A_X.
FormationTemps.vmac_fit — Method
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 — Method
vmic_fit(teff)Empirical microturbulent velocity fit from Bruntt et al. (2010).
Input teff is in K; returns microturbulent velocity in m/s.