Spectra

NTECARS.SpectrumType
Spectrum(x::Vector{N}, I::Vector{T}, unit::Symbol) where {N,T} -> Spectrum

Constructs a Spectrum from spectral positions x and intensities I.

Constructor Arguments

  • x::Vector{N}: Spectral positions at which the intensities are given. Units are specified by unit.
  • I::Vector{T}: Intensities at spectral positions x.
  • unit::Symbol: Units of x. Must be :wavelength (meters) or :wavenumber (cm⁻¹).

Fields of returned type

  • ν::Vector{Float64}: Spectral positions in wavenumbers (cm⁻¹), sorted from lowest to highest. Converted automatically if constructed with :wavelength.
  • I::Vector{T}: Intensities corresponding to ν.

Notes

  • Spectral positions are always stored in wavenumbers internally, sorted from lowest to highest. If x is not sorted, the order is corrected automatically.
  • Use wavenumbers(spectrum) and intensities(spectrum) to access the fields rather than accessing ν and I directly.

Examples

s = Spectrum([404e-9, 405e-9, 406e-9], [0.0, 1.0, 0.0], :wavelength)
s = Spectrum([20000.0, 21000.0], [0.5, 1.0], :wavenumber)
ν = wavenumbers(s)
λ = wavelengths(s)
I = intensities(s)
I = intensities(s, normalization = :maximum)
I = intensities(s, normalization = :sum)
source
NTECARS.save_spectrumFunction
save_spectrum(file_path, spec::Spectrum, sim::CARSSimulator)

Saves a spectrum to a CSV file with anti-Stokes wavelength, Raman shifts relative to both lasers, and intensity columns.

Arguments

  • file_path: Path to the output CSV file, e.g. "results/spectrum.csv".
  • spec::Spectrum: The spectrum to save.
  • sim::CARSSimulator: Simulator providing the laser configuration used to compute the Raman shifts.

Output columns

  • anti-Stokes wavelength (nm): Anti-Stokes wavelength axis in nm.
  • Raman shift (cm⁻¹) [ω₁ - ωₛ]: Raman shift relative to the first laser in cm⁻¹.
  • Raman shift (cm⁻¹) [ω₂ - ωₛ]: Raman shift relative to the second laser in cm⁻¹.
  • intensity (a.u.): Normalised CARS intensity.
  • sqrt(intensity) (a.u.): Square root of the normalised CARS intensity.

Notes

  • The spectrum is normalised to its maximum value before saving, so intensities are in the range [0, 1].
  • Prints the output path to the console upon successful completion.

Examples

save_spectrum("results/spectrum.csv", spec, sim)
source
NTECARS.GaussianFunction
Gaussian(σ, μ=0.0) -> Spectrum

Convenience constructor for a normalised Gaussian spectral profile.

Arguments

  • σ::Float64: Gaussian width (standard deviation, FWHM=2.355*σ) in cm⁻¹.
  • μ::Float64: Centre offset in cm⁻¹. Defaults to 0.0.

Returns

  • Spectrum: Sampled Gaussian profile centred at μ.

Examples

profile = Gaussian(0.2)          # σ = 0.2 cm⁻¹, centred at 0
profile = Gaussian(0.2, 1.0)     # σ = 0.2 cm⁻¹, centred at 1.0 cm⁻¹
source
NTECARS.VoigtFunction
Voigt(σ, γ, μ=0.0) -> Spectrum

Convenience constructor for a normalised Voigt spectral profile.

Arguments

  • σ::Float64: Gaussian width (standard deviation, FWHM=2.355*σ) in cm⁻¹.
  • γ::Float64: Lorentzian half-width in cm⁻¹.
  • μ::Float64: Centre offset in cm⁻¹. Defaults to 0.0.

Returns

  • Spectrum: Sampled Voigt profile centred at μ.

Examples

profile = Voigt(0.1, 0.05)        # σ = 0.1 cm⁻¹, γ = 0.05 cm⁻¹
profile = Voigt(0.1, 0.05, 1.0)   # same but centred at 1.0 cm⁻¹
source
NTECARS.PowerVoigtFunction
PowerVoigt(σ, γ, n, μ=0.0) -> Spectrum

Convenience constructor for a normalised power-Voigt spectral profile, i.e. a Voigt profile raised to the power n. Setting n = 1 recovers a standard Voigt. Setting γ = 0, n = 1 recovers a Gaussian.

Arguments

  • σ::Float64: Gaussian width (standard deviation, FWHM=2.355*σ) in cm⁻¹.
  • γ::Float64: Lorentzian half-width in cm⁻¹.
  • n::Float64: Exponent applied to the normalised Voigt profile.
  • μ::Float64: Centre offset in cm⁻¹. Defaults to 0.0.

Returns

  • Spectrum: Sampled power-Voigt profile centred at μ.

Examples

profile = PowerVoigt(0.1, 0.05, 2.0)       # squared Voigt profile
profile = PowerVoigt(0.1, 0.05, 2.0, 1.0)  # same but centred at 1.0 cm⁻¹
source
NTECARS.cut_spectral_rangeFunction
cut_spectral_range(spectrum::Spectrum, range::Tuple{Float64, Float64}, unit::Symbol)

Extracts a sub-range of a spectrum by finding the closest grid points to the specified range limits.

Arguments

  • spectrum::Spectrum: The spectrum to cut.
  • range::Tuple{Float64, Float64}: The desired spectral range as (min, max). For :wavelength, order does not matter as the tuple is sorted after conversion.
  • unit::Symbol: Unit of range. Must be :wavenumber or :wavelength (in meters).

Returns

  • Spectrum: A new spectrum on a wavenumber grid, containing only the points within the specified range.

Notes

  • The cut is performed by nearest-neighbour lookup, so the returned range may differ slightly from the requested one if the grid spacing is coarse.
  • The returned Spectrum is always in :wavenumber units, regardless of the input unit.

Examples

cut = cut_spectral_range(spectrum, (2200.0, 2400.0), :wavenumber)
cut = cut_spectral_range(spectrum, (4.0e-6, 4.5e-6), :wavelength)
source
NTECARS.raman_shiftsFunction
raman_shifts(; chi2, lasers) -> (ramanshift_ν1_νS, ramanshift_ν2_νS)

Computes the Raman shifts for the CARS-spectrum chi2 relative to each of the two laser wavenumbers.

Arguments

  • chi2::Spectrum: The CARS spectrum..
  • lasers::LaserConfiguration: Laser configuration providing ν_1 and ν_2 in cm⁻¹.

Returns

  • ramanshift_ν1_νS: Raman shifts relative to the first laser, ν_1 - ν_S, in cm⁻¹.
  • ramanshift_ν2_νS: Raman shifts relative to the second laser, ν_2 - ν_S, in cm⁻¹.
source