Metadata-Version: 2.4
Name: pyzfn
Version: 1.0.6
Summary: micromagnetic post processing library
Author-email: Mathieu Moalic <matmoa@amu.edu.pl>, Mateusz Zelent <mateusz.zelent@amu.edu.pl>
License-Expression: GPL-3.0-or-later
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: matplotlib~=3.10
Requires-Dist: numpy~=2.2
Requires-Dist: zarr<3.2.0,>=3.0.8
Requires-Dist: typing_extensions<4.16.0,>=4.13.2
Requires-Dist: crc32c~=2.7.1
Requires-Dist: rich<14.2,>=14.0
Requires-Dist: psutil>=7.0.0
Dynamic: license-file

# pyzfn

**Pyzfn** is a Python library for post-processing micromagnetic simulation data generated by [amumax](https://github.com/MathieuMoalic/amumax), a fork of [mumax3](http://mumax.github.io/). It is designed for use with Zarr-backed datasets and supports spatially resolved frequency-domain analysis, visualization, and export of magnetization dynamics.

## Features

* 🧊 **Zarr-native API** for reading/writing simulation results
* ⚡ **FFT-based mode analysis** across 5D datasets (`(t, z, y, x, c)`)
* 📈 **Interactive spectrum visualization** with peak-picking
* 🌈 **Mode visualization** in amplitude and phase
* 🖼️ **Snapshot tools** for spatial magnetization structure
* 💾 **OVF (OOMMF Vector Field) export** for simulation interoperability
* 📚 Predefined theoretical **dispersion models** (Kittel, Kalinikos-Slavin, DMI-included...)

---

## Installation

```bash
pip install pyzfn
```

## Usage

### Loading a Zarr Dataset

```python
from pyzfn import Pyzfn

zfn = Pyzfn("my_simulation.zarr")
zfn.p  # Show tree structure
```

### Calculate Modes

```python
zfn.calc_modes(dset_in_str="m", dset_out_str="modes")
```

Performs time-FFT over magnetization and stores spatially resolved modes in `modes/...`.

### Visualize Frequency Spectrum + Modes

```python
zfn.ispec(dset_str="modes")
```

* Left: Spectral line plot
* Right: Mode amplitude, phase, and composite maps
* Click to explore frequency slices interactively

### Visualize a Snapshot

```python
zfn.snapshot(dset_str="m", t=-1, z=0)
```

Visualizes the magnetization vector field at a given time and layer.

---

## Dispersion Models

You can compute theoretical resonance frequencies for comparison:

```python
from pyzfn.equations import kittel_1948

f_res = kittel_1948(B=0.23, Ms=1.15e6, Ku=0.938e6)
print(f_res, "Hz")
```

Other supported models:

* `kalinikos_1986`, `kalinikos_1986_no_approx`
* `bottcher_2021`
* `kim_2016` (DMI included)
* `cortes_ortuno_2013`

---

## OVF Support

### Save to OVF

```python
from pyzfn.ovf import save_ovf

save_ovf("mode.ovf", array, dx=1e-9, dy=1e-9, dz=1e-9)
```

### Load from OVF

```python
from pyzfn.ovf import load_ovf

arr = load_ovf("mode.ovf")
```

---

## Development

### Run Tests

```bash
pytest
```

### Run Type Checks

```bash
mypy pyzfn
```

### Format & Lint

We use [`pre-commit`](https://pre-commit.com/) hooks:

```bash
pre-commit install
```
