astronomix.analysis_helpers.energy_spectrum module#

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.

astronomix.analysis_helpers.energy_spectrum.get_cross_helicity_spectrum(vx, vy, vz, Bx, By, Bz, binning=2)[source]#

Cross-helicity spectrum H_c(k).

Cross helicity: H_c = integral(u . B) dV. Spectrum satisfies: sum(H_c(k)) == mean(u . B).

Parameters:
  • vx – Velocity components, each (Nx, Ny, Nz).

  • vy – Velocity components, each (Nx, Ny, Nz).

  • vz – Velocity components, each (Nx, Ny, Nz).

  • Bx – Magnetic field components, each (Nx, Ny, Nz).

  • By – Magnetic field components, each (Nx, Ny, Nz).

  • Bz – Magnetic field components, each (Nx, Ny, Nz).

  • binning – LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.

Returns:

Wavenumber bin centers and cross-helicity spectrum.

Return type:

wavenumber_centers, Hc

astronomix.analysis_helpers.energy_spectrum.get_kinetic_energy_spectrum(vx, vy, vz, rho, binning=2)[source]#

Kinetic energy spectrum with density weighting.

Uses w = sqrt(rho) * u so that sum(E_k) == mean(0.5 * rho * |u|^2).

Parameters:
  • vx – Velocity components, each (Nx, Ny, Nz).

  • vy – Velocity components, each (Nx, Ny, Nz).

  • vz – Velocity components, each (Nx, Ny, Nz).

  • rho – Density field, (Nx, Ny, Nz).

  • binning – LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.

Returns:

Wavenumber bin centers and kinetic energy spectrum.

Return type:

wavenumber_centers, Ek

astronomix.analysis_helpers.energy_spectrum.get_magnetic_energy_spectrum(Bx, By, Bz, mu0=1.0, binning=2)[source]#

Magnetic energy spectrum.

sum(E_m) == mean(|B|^2 / (2 * mu0)).

Parameters:
  • Bx – Magnetic field components, each (Nx, Ny, Nz).

  • By – Magnetic field components, each (Nx, Ny, Nz).

  • 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 bin centers and magnetic energy spectrum.

Return type:

wavenumber_centers, Em

astronomix.analysis_helpers.energy_spectrum.get_magnetic_helicity_spectrum(Bx, By, Bz, binning=2)[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).

Parameters:
  • Bx – Magnetic field components, each (Nx, Ny, Nz).

  • By – Magnetic field components, each (Nx, Ny, Nz).

  • Bz – Magnetic field components, each (Nx, Ny, Nz).

  • binning – LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.

Returns:

Wavenumber bin centers and magnetic helicity spectrum.

Return type:

wavenumber_centers, Hm

astronomix.analysis_helpers.energy_spectrum.vector_field_cross_spectrum(f1x, f1y, f1z, f2x, f2y, f2z, coeff=1.0, binning=2)[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.

Parameters:
  • f1x – First field components, each (Nx, Ny, Nz).

  • f1y – First field components, each (Nx, Ny, Nz).

  • f1z – First field components, each (Nx, Ny, Nz).

  • f2x – Second field components, each (Nx, Ny, Nz).

  • f2y – Second field components, each (Nx, Ny, Nz).

  • f2z – Second field components, each (Nx, Ny, Nz).

  • coeff – Scalar multiplier (default 1.0).

  • binning – LOG_BINNING, INTEGER_BINNING, or PHYSICAL_BINNING.

Returns:

Physical wavenumber bin centers. Ck: Cross spectrum per bin.

Return type:

wavenumber_centers

astronomix.analysis_helpers.energy_spectrum.vector_field_energy_spectrum(fx, fy, fz, energy_coeff=1.0, binning=2)[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).

Parameters:
  • fx – Field components, each shaped (Nx, Ny, Nz).

  • fy – Field components, each shaped (Nx, Ny, Nz).

  • 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:

Physical wavenumber bin centers. Ek: Energy spectrum per bin.

Return type:

wavenumber_centers

Based on: https://qiauil.github.io/blog/2026/tke_spectrum/