Skip to main content

A Python package for post-processing MHD turbulence simulations

Project description

PyMHD

DOI License: MIT

A Python package for post-processing magnetohydrodynamic (MHD) turbulence simulations.

Features

  • High-fidelity a posteriori estimation and visualization of numerical dissipation in MHD turbulence simulations
  • Computation and visualization of turbulent energy spectra
  • Visualization of 2D slices of MHD variables
  • Built-in support for simulations from the Athena family, including Athena++, AthenaK, and AthenaPK
  • Support for driven MHD turbulence (e.g., Alfvénic turbulence and small-scale dynamos), driven hydrodynamic turbulence, and MRI-driven turbulence (from shearing-box simulations) with triply periodic boundary conditions
  • Support for adiabatic and isothermal equations of state (EoS); TODO: add support for incompressible EoS
  • TODO: Computation and visualization of correlation functions
  • TODO: Spectral energy transfer analysis following Grete, Philipp, et al. Physics of Plasmas 24.9 (2017)
  • TODO: JAX acceleration on GPUs and multi-node CPUs (currently, certain algorithms support parallelism on single-node, multi-core CPUs)

Quick Start

Installation

Install PyMHD from PyPI with:

pip install pymhd

This command installs PyMHD and its required dependencies, including:

  • NumPy for core computations
  • JAX for parallel acceleration on single-node, multi-core CPUs; therefore, the CPU version of JAX is required
  • yt and h5py for extracting data from HDF5 output files, specifically Athena++ .athdf files, AthenaK .bin files, and AthenaPK .phdf files
  • Matplotlib for plotting functionality in the pymhd.plot modules
  • KDEpy for plotting smoothed histograms of numerical dissipation data in the pymhd.plot.nd module

Built-in Examples

For a quick start, clone the source repository:

git clone https://github.com/PlasmaHua/PyMHD.git

Alternatively, download the source code from the GitHub releases page. Then navigate to the ./examples subdirectory with cd PyMHD/examples, where two AthenaK simulation examples are provided.

Each directory in PyMHD/examples contains a Python script, quick.py, that demonstrates basic usage of PyMHD, including:

  • Extracting a PyMHD Turbulence object from output files with the pymhd.output2turbulence function
  • Calculating turbulent energy spectra with the PyMHD EnergySpectra class
  • Estimating numerical dissipation a posteriori with the PyMHD NumericalDissipation class
  • Visualizing turbulent spectra and numerical dissipation with the pymhd.plot module

Analyze Your Own Athena Simulations

PyMHD natively supports simulations from Athena++, AthenaK, and AthenaPK. Following the examples in PyMHD/examples, use the pymhd.output2turbulence function to extract output data and input-file metadata, then construct a PyMHD Turbulence object for further analysis.

API Documentation

Under construction.

Citation

If PyMHD contributes to your work, please consider citing the package using the following BibTeX entry:

@misc{Hua2026,
  doi = {10.5281/zenodo.20749062},
  url = {https://zenodo.org/doi/10.5281/zenodo.20749062},
  author = {Hua, Yuyang},
  title = {PyMHD: Python package for post-processing MHD turbulence simulations},
  publisher = {Zenodo},
  year = {2026},
  copyright = {MIT License}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymhd-0.1.2.tar.gz (69.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymhd-0.1.2-py3-none-any.whl (75.9 kB view details)

Uploaded Python 3

File details

Details for the file pymhd-0.1.2.tar.gz.

File metadata

  • Download URL: pymhd-0.1.2.tar.gz
  • Upload date:
  • Size: 69.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pymhd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2ec9649931a2d3c7424b97b6122f59423bfff75da7ecf1d169c8791c497afbd5
MD5 e55b68b398a4b1524823b50a50e071f9
BLAKE2b-256 8f6d95f8eb983fa8418eadaf3ee5843488d46eadbc379675f6b72c4997e698c8

See more details on using hashes here.

File details

Details for the file pymhd-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pymhd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 75.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for pymhd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6137d92dd76f0b92ac71a1d429cff1e85872200b7b1a63e02b2c9cec8197fc4d
MD5 4334436c945156a32fd2eb71531daa01
BLAKE2b-256 e85c1314e4876c9cd85121ab7f82686941181c07b80c8f752ede5a586b763f70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page