Skip to main content

A library for MMPP (Micro Magnetic Post Processing) simulation and analysis

Project description

๐Ÿงฒ MMPP - Micro Magnetic Post Processing

Python License Documentation GitHub Issues GitHub Stars

A powerful Python library for micromagnetic simulation analysis and visualization

๐Ÿ“– Documentation โ€ข ๐Ÿš€ Getting Started โ€ข ๐ŸŽฏ Features โ€ข ๐Ÿ’ก Examples


๐ŸŽฏ Features

๐Ÿ”ฌ Advanced Analysis

  • ๐ŸŒŠ Fast Fourier Transform (FFT) computation
  • ๐Ÿ“Š Frequency spectrum analysis
  • ๐ŸŽญ FMR mode identification
  • ๐Ÿ“ˆ Statistical data processing

โšก High Performance

  • ๐Ÿš€ Parallel batch processing
  • ๐Ÿ’พ Efficient data handling with Zarr
  • ๐Ÿ”„ Concurrent operations
  • ๐Ÿ“ฆ Memory-optimized workflows

๐ŸŽจ Rich Visualization

  • ๐Ÿ“Š Publication-ready plots
  • ๐ŸŽฌ Interactive animations
  • ๐ŸŽจ Custom styling themes
  • ๐Ÿ–ผ๏ธ Multiple export formats

๐Ÿ› ๏ธ Developer Friendly

  • ๐Ÿ Pythonic API design
  • ๐Ÿ“š Comprehensive documentation
  • ๐Ÿงช Well-tested codebase
  • ๐Ÿ”Œ Extensible architecture

๐Ÿค– Smart Auto-Selection โœจ NEW!

  • ๐ŸŽฏ Automatic dataset detection and selection
  • ๐Ÿ“Š Intelligently chooses the largest magnetization dataset
  • ๐Ÿš€ Simplified API - no need to specify dataset names
  • ๐Ÿ”„ Backwards compatible with manual dataset selection

๐Ÿš€ Quick Start

Installation

# Install from PyPI (recommended)
pip install mmpp

# Or install latest development version
pip install git+https://github.com/MateuszZelent/mmpp.git

Basic Usage

import mmpp

# ๐Ÿ“‚ Load simulation data
op = mmpp.MMPP('path/to/simulation.zarr')

# ๐Ÿ” Single file analysis with auto-selection
result = op[0]
fft_analyzer = result.fft

# ๐Ÿค– Auto-dataset selection (NEW!) - automatically chooses largest m_z dataset
spectrum = fft_analyzer.spectrum()  # Uses auto-selection
power_spectrum = fft_analyzer.power()  # Uses auto-selection

# ๐ŸŽฏ Or specify dataset explicitly
spectrum = fft_analyzer.spectrum(dset='m_z5-8')

# โšก Batch processing
batch = op[:]  # Get all results
modes = batch.fft.modes.compute_modes(parallel=True)  # Auto-selection in batch too

๐Ÿค– Smart Auto-Selection Feature

MMPP now includes intelligent dataset auto-selection that automatically chooses the best magnetization dataset for analysis:

# โœจ NEW: Auto-selection API (recommended)
result = op[0]
fft_analyzer = result.fft

# No need to specify dataset - MMPP chooses the largest m_z dataset automatically
spectrum = fft_analyzer.spectrum()
power_spectrum = fft_analyzer.power()
modes = fft_analyzer.modes.compute_modes()

# ๐Ÿ” Check which dataset was auto-selected
selected_dataset = result.get_largest_m_dataset()
print(f"Auto-selected dataset: {selected_dataset}")  # e.g., "m_z5-8"

# ๐Ÿ”„ Traditional API still works for manual control
spectrum = fft_analyzer.spectrum(dset='m_z5-8')

Benefits:

  • ๐ŸŽฏ Simplified API: No need to remember dataset names
  • ๐Ÿš€ Intelligent Selection: Automatically finds the best dataset
  • ๐Ÿ”„ Backward Compatible: Existing code continues to work
  • ๐Ÿ“Š Consistent Results: Always uses the dataset with most data points

๐Ÿ’ก Examples

๐Ÿ”„ Batch Processing

Process multiple simulation files efficiently:

# ๐Ÿ“ Process all files in a directory
op = mmpp.MMPP('simulation_results/')
batch = op[:]

# โšก Parallel FFT analysis with auto-selection (NEW!)
modes = batch.fft.modes.compute_modes(parallel=True)  # Auto-selects best dataset

# ๏ฟฝ Or specify dataset explicitly for batch operations
modes = batch.fft.modes.compute_modes(dset='m_z5-8', parallel=True)

# ๐Ÿš€ Complete analysis in one call (NEW!)
results = batch.process(parallel=True, max_workers=4)  # FFT + mode analysis
print(f"Processed {results['successful']}/{results['total']} files successfully")

๐ŸŒŠ Advanced FFT Analysis

Comprehensive frequency domain analysis:

# ๐Ÿค– Auto-selection (NEW!) - Let MMPP choose the best dataset
spectrum = fft_analyzer.spectrum()  # Automatically selects largest m_z dataset
power_spectrum = fft_analyzer.power()
frequencies = fft_analyzer.frequencies()
modes = fft_analyzer.modes.compute_modes()

# ๐ŸŽฏ Manual dataset selection (traditional approach)
spectrum = fft_analyzer.spectrum(dset='m_z5-8')
power_spectrum = fft_analyzer.power(dset='m_z5-8')
frequencies = fft_analyzer.frequencies(dset='m_z5-8')
modes = fft_analyzer.modes.compute_modes(dset='m_z5-8')

# ๐ŸŽฌ Plot mode visualizations at specific frequency
plot_result = fft_analyzer.plot_modes(frequency=10.5)  # Auto-selection
plot_result = fft_analyzer.plot_modes(frequency=10.5, dset='m_z5-8')  # Manual

๐ŸŽจ Publication-Ready Visualizations

Create stunning plots with built-in themes:

# ๐Ÿ“ˆ Custom styled plots
import mmpp.plotting as mplt
mplt.plot_spectrum(spectrum, style='publication')

# ๐ŸŽจ Interactive visualizations
mplt.interactive_plot(data, colormap='viridis')

# ๐Ÿ’พ Export in multiple formats
mplt.save_figure('spectrum.png', dpi=300, format='png')

โšก Performance Tips

๐Ÿš€ Optimize Your Workflow

Use Parallel Processing

# Enable parallel processing for batch operations
modes = batch.fft.modes.compute_modes(parallel=True)

# Control number of workers
modes = batch.fft.modes.compute_modes(parallel=True, max_workers=4)

Leverage Auto-Selection

# Let MMPP choose the optimal dataset automatically
spectrum = fft_analyzer.spectrum()  # Faster than manual selection

Memory Management

# Process large datasets in chunks to manage memory usage
op = mmpp.MMPP('large_simulation_directory/')
batch_size = 50  # Process 50 results at a time

print(f"Total files: {len(op)}")
for i in range(0, len(op), batch_size):
    chunk = op[i:i+batch_size]
    results = chunk.process(parallel=True, max_workers=4)
    
    chunk_num = i//batch_size + 1
    total_chunks = (len(op) + batch_size - 1) // batch_size
    print(f"Chunk {chunk_num}/{total_chunks}: {results['successful']}/{results['total']} successful "
          f"({results['computation_time']:.1f}s)")
    
    # Optional: Clear memory or save intermediate results
    if results['failed'] > 0:
        print(f"โš ๏ธ  {results['failed']} files failed in chunk {chunk_num}")

Efficient Data Loading

# Load only what you need
result = op[0]  # Single result
specific_results = op.find(solver=3, amp_values=0.0022)  # Filtered results

๐Ÿ“Š Benchmarks

Typical performance on a modern system (16GB RAM, 8-core CPU):

Operation Single File Batch (10 files) Parallel Batch
Load Data ~0.1s ~1.0s ~0.3s
FFT Analysis ~2.0s ~20s ~5s
Mode Computation ~5.0s ~50s ~12s

Performance varies significantly based on dataset size and system specifications.

๐Ÿ“š Documentation & Resources

Resource Description Link
๐Ÿ“– Documentation Complete API reference and tutorials GitHub Pages
๐ŸŽ“ Tutorials Step-by-step guides and examples Tutorials
๐Ÿ”ฌ API Reference Detailed function documentation API Docs
๐Ÿš€ Getting Started Quick start guide Getting Started
๐Ÿ—‚๏ธ PyZFN Library ZFN file format handling (dependency) PyZFN by Mathieu Moalic

๐Ÿ—๏ธ Build Documentation Locally

# Quick build and serve
./build_docs.sh --serve

# Manual build
cd docs
pip install sphinx sphinx-rtd-theme myst-parser sphinx-autodoc-typehints
sphinx-build -b html . _build

๐Ÿ”ง Installation Options

๐Ÿ“ฆ Standard Installation

pip install mmpp

๐Ÿ› ๏ธ Development Installation

git clone https://github.com/MateuszZelent/mmpp.git
cd mmpp
pip install -e ".[dev]"

๐ŸŽฏ Optional Features

# Interactive Jupyter support
pip install mmpp[interactive]

# Enhanced plotting capabilities
pip install mmpp[plotting]

# Full development environment
pip install mmpp[dev]

๐Ÿ“‹ Requirements

Core Dependencies

  • ๐Ÿ Python โ‰ฅ3.9
  • ๐Ÿ”ข NumPy โ‰ฅ1.20.0
  • ๐Ÿผ Pandas โ‰ฅ1.3.0
  • ๐Ÿ“Š Matplotlib โ‰ฅ3.5.0
  • ๐Ÿ—‚๏ธ PyZFN - ZFN file format handling (Mathieu Moalic)
  • โšก Zarr - High-performance data storage
  • ๐ŸŽจ Rich - Beautiful terminal output
  • ๐Ÿ“ˆ TQDM - Progress bars

Optional Dependencies

  • ๐Ÿช Jupyter Ecosystem (itables, IPython, jupyter)
  • ๐ŸŒŠ Enhanced Plotting (cmocean, seaborn)
  • ๐Ÿงช Development Tools (pytest, ruff, mypy)

๐Ÿ’ป System Requirements

Supported Platforms

  • ๐Ÿง Linux (Ubuntu 18.04+, CentOS 7+, etc.)
  • ๐ŸŽ macOS (10.14+)
  • ๐ŸชŸ Windows (10+)

Hardware Recommendations

  • RAM: 8GB minimum, 16GB+ recommended for large datasets
  • Storage: SSD recommended for better I/O performance
  • CPU: Multi-core processor recommended for parallel operations

Python Compatibility

  • โœ… Python 3.9 - Minimum supported version
  • โœ… Python 3.10 - Fully supported
  • โœ… Python 3.11 - Fully supported
  • โš ๏ธ Python 3.12 - Beta support (some dependencies may vary)

๐Ÿ“š Additional Documentation

For developers and advanced users, additional documentation is available:

๐Ÿ”ฌ FFT Analysis Documentation

๐Ÿ› ๏ธ Development Documentation

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

Type Description Action
๐Ÿ› Bug Reports Found an issue? Open Issue
๐Ÿ’ก Feature Requests Have an idea? Discussion
๐Ÿ”ง Pull Requests Want to contribute code? Contributing Guide
๐Ÿ“– Documentation Improve the docs Edit on GitHub

๐Ÿš€ Quick Contribution Setup

# Fork and clone the repository
git clone https://github.com/MateuszZelent/mmpp.git
cd mmpp

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Check code style
ruff check mmpp/
ruff format --check mmpp/

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with โค๏ธ by MateuszZelent
  • Powered by the amazing Python scientific computing ecosystem
  • PyZFN integration: Utilizes components from PyZFN by Mathieu Moalic for efficient ZFN file handling
  • Special thanks to all contributors and users

โญ Star this repo if you find it useful! โญ

Report Bug โ€ข Request Feature โ€ข Documentation

โ“ Frequently Asked Questions

๐Ÿ” Q: How does auto-selection work?

A: MMPP automatically identifies and selects the largest magnetization dataset (m_z*) in your simulation files. This ensures you're always working with the most comprehensive data available.

๐Ÿ“Š Q: Can I still use manual dataset selection?

A: Yes! The auto-selection feature is backward compatible. You can still specify datasets manually using the dset parameter in any method.

โšก Q: How do I speed up batch processing?

A: Use the parallel=True parameter in batch operations:

batch.fft.modes.compute_modes(parallel=True)

๐Ÿ› Q: I'm getting import errors. What should I do?

A: Make sure you have all dependencies installed:

pip install mmpp[dev]  # For full functionality

๐Ÿ“ Q: What file formats does MMPP support?

A: MMPP primarily works with Zarr archives (.zarr) from micromagnetic simulations. The library is optimized for this format's high-performance capabilities.

๐Ÿ”ง Troubleshooting

Common Issues

Import Errors

# Problem: ModuleNotFoundError
# Solution: Install missing dependencies
pip install mmpp[dev]

Memory Issues with Large Datasets

# Problem: Out of memory errors
# Solution: Process data in chunks or use batch operations
batch_size = 10
for chunk in op.chunks(batch_size):
    results = chunk.fft.modes.compute_modes()

Performance Issues

# Problem: Slow FFT computation
# Solution: Use parallel processing
modes = batch.fft.modes.compute_modes(parallel=True, max_workers=4)

Getting Help

If you encounter issues:

  1. Check the Documentation: GitHub Pages
  2. Search Issues: GitHub Issues
  3. Ask Questions: GitHub Discussions
  4. Contact: mateusz.zelent@amu.edu.pl

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

mmpp-0.5.3.tar.gz (9.1 MB view details)

Uploaded Source

Built Distribution

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

mmpp-0.5.3-py3-none-any.whl (3.6 MB view details)

Uploaded Python 3

File details

Details for the file mmpp-0.5.3.tar.gz.

File metadata

  • Download URL: mmpp-0.5.3.tar.gz
  • Upload date:
  • Size: 9.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mmpp-0.5.3.tar.gz
Algorithm Hash digest
SHA256 0e1d609bb951faf261e0e71d160ec2a11c984d45204e468048081521b6b478f5
MD5 5f189fc0d39f41df8d5558f407d50a89
BLAKE2b-256 1251e192deff22cd2ae28a011462e1f3fcb1497f38f5f83c5622532335e62195

See more details on using hashes here.

File details

Details for the file mmpp-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: mmpp-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mmpp-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 434917d95f722db6392a5aead7b2d55db0d7e16960b2e7428b80fff6acf1c2bb
MD5 f9dd7131a838bc7081fad5e369f22773
BLAKE2b-256 bc27bbc47dfc97113f69637b29763216467856b5bd0af15367dbc3b245508c00

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