astronomix.analysis_helpers.energy_spectrum#
Shell-averaged energy, cross and helicity spectra of 3D vector fields.
Provides the FFT-based spectral diagnostics used by the snapshot machinery: generic vector-field energy and cross spectra, plus the MHD physics wrappers (density-weighted kinetic energy, magnetic energy, cross helicity, magnetic helicity). All spectra share a single shell-binning of the wavenumber grid so their bins line up.
Module Contents#
Functions#
Energy spectrum E(k) of a vector field (fx, fy, fz). |
|
Cross spectrum C(k) between two vector fields f1 and f2. |
|
Kinetic energy spectrum with density weighting. |
|
Magnetic energy spectrum. |
|
Cross-helicity spectrum H_c(k). |
|
Magnetic helicity spectrum H_m(k). |
Data#
API#
- astronomix.analysis_helpers.energy_spectrum.LOG_BINNING = 0#
- astronomix.analysis_helpers.energy_spectrum.INTEGER_BINNING = 1#
- astronomix.analysis_helpers.energy_spectrum.PHYSICAL_BINNING = 2#
- astronomix.analysis_helpers.energy_spectrum.vector_field_energy_spectrum(fx, fy, fz, energy_coeff=1.0, binning=PHYSICAL_BINNING)[source]#
Energy spectrum E(k) of a vector field (fx, fy, fz).
Satisfies: sum(E(k)) == mean(c * |f|^2) over the domain (shell-summed convention).
- Args:
fx, fy, fz: Field components, each shaped (Nx, Ny, Nz). energy_coeff: Scalar multiplier c (default 1.0). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers: Physical wavenumber bin centers. Ek: Energy spectrum per bin.
- astronomix.analysis_helpers.energy_spectrum.vector_field_cross_spectrum(f1x, f1y, f1z, f2x, f2y, f2z, coeff=1.0, binning=PHYSICAL_BINNING)[source]#
Cross spectrum C(k) between two vector fields f1 and f2.
Satisfies: sum(C(k)) == mean(c * f1 . f2) over the domain.
The spectrum is the shell-summed co-spectrum (real part of the conjugate dot product in Fourier space). Unlike energy spectra, cross spectra are not positive-definite.
- Args:
f1x, f1y, f1z: First field components, each (Nx, Ny, Nz). f2x, f2y, f2z: Second field components, each (Nx, Ny, Nz). coeff: Scalar multiplier (default 1.0). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers: Physical wavenumber bin centers. Ck: Cross spectrum per bin.
- astronomix.analysis_helpers.energy_spectrum.get_kinetic_energy_spectrum(vx, vy, vz, rho, binning=PHYSICAL_BINNING)[source]#
Kinetic energy spectrum with density weighting.
Uses w = sqrt(rho) * u so that sum(E_k) == mean(0.5 * rho * |u|^2).
- Args:
vx, vy, vz: Velocity components, each (Nx, Ny, Nz). rho: Density field, (Nx, Ny, Nz). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers, Ek: Wavenumber bin centers and kinetic energy spectrum.
- astronomix.analysis_helpers.energy_spectrum.get_magnetic_energy_spectrum(Bx, By, Bz, mu0=1.0, binning=PHYSICAL_BINNING)[source]#
Magnetic energy spectrum.
sum(E_m) == mean(|B|^2 / (2 * mu0)).
- Args:
Bx, By, Bz: Magnetic field components, each (Nx, Ny, Nz). mu0: Magnetic permeability (default 1.0 for Alfvénic units). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers, Em: Wavenumber bin centers and magnetic energy spectrum.
- astronomix.analysis_helpers.energy_spectrum.get_cross_helicity_spectrum(vx, vy, vz, Bx, By, Bz, binning=PHYSICAL_BINNING)[source]#
Cross-helicity spectrum H_c(k).
Cross helicity: H_c = integral(u . B) dV. Spectrum satisfies: sum(H_c(k)) == mean(u . B).
- Args:
vx, vy, vz: Velocity components, each (Nx, Ny, Nz). Bx, By, Bz: Magnetic field components, each (Nx, Ny, Nz). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers, Hc: Wavenumber bin centers and cross-helicity spectrum.
- astronomix.analysis_helpers.energy_spectrum.get_magnetic_helicity_spectrum(Bx, By, Bz, binning=PHYSICAL_BINNING)[source]#
Magnetic helicity spectrum H_m(k).
Magnetic helicity: H_m = integral(A . B) dV, where B = curl(A). In a periodic domain with Coulomb gauge, the vector potential is recovered in Fourier space as: A_hat(k) = +i k x B_hat(k) / |k|^2.
Spectrum satisfies: sum(H_m(k)) == mean(A . B).
- Args:
Bx, By, Bz: Magnetic field components, each (Nx, Ny, Nz). binning: LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.
- Returns:
wavenumber_centers, Hm: Wavenumber bin centers and magnetic helicity spectrum.