Pyzfn is a micromagnetic post-processing library designed for analyzing and visualizing data generated by amumax, a fork of mumax3. It provides a convenient interface for working with simulation data stored in Zarr format, offering optimized functions for data manipulation, spectral analysis, and visualization.
- Easy Data Access: Load and navigate large simulation datasets efficiently.
- Spectral Analysis: Calculate dispersion relations and extract spin wave modes.
- Visualization Tools: Generate snapshots and interactive spectral plots.
- Integration with Zarr: Leverage Zarr's capabilities for handling big data.
Install Pyzfn using pip:
pip install pyzfn
Pyzfn builds upon the functionalities provided by Zarr. Familiarity with Zarr is recommended for advanced usage.
from pyzfn import Pyzfn
# Replace 'path/to/job.zarr' with your simulation data path
job = Pyzfn('path/to/job.zarr')
# Interactive tree (requires IPython)
job.pp
# Non-interactive print
job.p
Simulation metadata is stored in the .attrs
attribute:
# Access metadata as a dictionary
dx = job.attrs['dx']
# Or as a class attribute (if no dataset shares the same name)
dx = job.dx
Access datasets saved during the simulation:
# Access magnetization data
# For example, get the x-component of magnetization for time steps 10 <= t < 20
# Dimensions are (time, z, y, x, component)
mag = job.m[10:20, :, :, :, 0] # mag is a NumPy array
To handle large datasets without loading them into memory immediately:
# Get a reference to the dataset
mag_dset = job.m
# Load data when needed
arr = mag_dset[:]
Display detailed information about a dataset:
mag_dset.info
Use Python's built-in help
and dir
functions for assistance:
help(mag_dset)
Pyzfn provides optimized functions for common post-processing tasks.
# Calculate the dispersion relation for the magnetization dataset
job.calc_disp(dset_in_str='m', dset_out_str='m')
# Extract spin wave modes from the data
job.calc_modes(dset_in_str='m', dset_out_str='m')
Generate a snapshot of the magnetization at a specific time step:
# Visualize the magnetization at time index t=50 and layer z=0
job.snapshot(t=50, z=0)
Launch an interactive FFT spectrum plot:
# Interactive spectrum analysis
job.ispec(dset='m', c=0)
Optimize memory usage and performance with custom slicing:
# Define custom slices for processing
slices = (
slice(None), # Time dimension
slice(None), # z dimension
slice(None), # y dimension
slice(None), # x dimension
slice(None) # Component dimension
)
# Calculate modes with custom slices
job.calc_modes(dset_in_str='m', dset_out_str='m', slices=slices)
Pyzfn includes utilities for working with OOMMF's OVF file format:
from pyzfn.utils import save_ovf, load_ovf
# Save data to an OVF file
save_ovf('output.ovf', mag)
# Load data from an OVF file
data = load_ovf('output.ovf')
Trim modes based on peak detection to reduce data size:
# Trim modes with specified parameters
job.trim_modes(dset_in_str='m', dset_out_str='trimmed_m', peak_xcut_min=0)
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request on the GitHub repository.