Metadata-Version: 2.4
Name: maggie
Version: 0.2.0
Summary: Mesh-Agnostic Graphics for Group-wise Iteration and Evolution
Author: Ben Whewell
License-Expression: MIT
Project-URL: Homepage, https://github.com/bwhewe-13/maggie
Project-URL: Issues, https://github.com/bwhewe-13/maggie/issues
Project-URL: Releases, https://github.com/bwhewe-13/maggie/releases
Keywords: neutron transport,neutron diffusion,multigroup,scalar flux,reaction rates,visualization,nuclear engineering
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PySide6>=6.5
Requires-Dist: matplotlib>=3.7
Requires-Dist: numpy>=1.24
Requires-Dist: h5py>=3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-qt>=4.2; extra == "dev"
Dynamic: license-file

# MAGGIE
Mesh-Agnostic Graphics for Group-wise Iteration and Evolution

Load and plot multigroup neutron flux, and the scattering and fission rate
densities computed from it, from transport and diffusion codes. MAGGIE
currently reads output from ants, discrete1 and NeutronDiffusion, plus any
code that saves plain arrays.

## Install

```bash
pip install maggie
```

MAGGIE needs Python 3.11-3.14. Standalone executables that need no Python
are attached to each [GitHub Release](https://github.com/bwhewe-13/maggie/releases)
(see Download below).

Start the viewer with `maggie` (or `python -m maggie`).

## Roadmap

1. **ants, discrete1, NeutronDiffusion - static.** Load screen, viewer tabs
   for flux and scattering/fission rate densities. *(done)*
2. **ants, discrete1, NeutronDiffusion - live.** Watch a running solver and
   update the plots as time steps / iterations arrive.
3. **Other transport codes.** MC/DC, OpenMC, OpenMOC and OpenSN readers will
   be added once steps 1-2 are settled.

## Using the app

`maggie` opens the **load screen**:

- **Problem** - 1D, 2D or 3D.
- **Flux files** - one or more; several files are separate runs, overlaid on
  1-D plots. Bare arrays (ants, discrete1, NeutronDiffusion `np.save`) need an
  axis order, e.g. `time, x, group`; the list suggests each code's layouts.
- **Cross sections** (optional) - scattering, fission and a material map
  (ants' `medium_map`). Picking an ants-style `.npz` for one fills the others
  from the same file. Matrices are `sigma[to, from]` unless set otherwise.
- **Discretizations** - energy, x/y/z and time grids: from the flux file,
  uniform (space and time), or loaded from a file (edges or centres).

**Load** opens the **viewer**, with tabs for flux, scattering rate density
and fission rate density (`R_g = Sigma_g phi_g`, a `[to, from]` matrix summed
over `to`). Each tab picks the dataset, group (or the sum), time step, a
spatial or energy-spectrum view, and for 3-D the plane and slice. File > Load
new data goes back to the load screen with the same choices.

Everything on the load screen can be given on the command line:

```bash
maggie flux.npy --dim 1 --axes "time,x,group" \
       --scatter xs.npz:xs_scatter --fission xs.npz:xs_fission --map xs.npz:medium_map \
       --x-grid edges_x.npy --energy-grid edges_g.npy --view   # --view skips the load screen
maggie info result.npz           # what MAGGIE finds in a file
```

## Supported files

| Source | Files | What MAGGIE gets |
|---|---|---|
| ants, discrete1 | bare `.npy`/`.npz` (`np.save(flux)`, `np.savez(flux=..., keff=...)`) | axes from a per-code `preset=` or `dims=`; scalars become attributes, `edges_*` arrays become coords |
| NeutronDiffusion | `.npz` from `ndiffusion.save_result`, or a bare `np.save(flux)` | `(x\|cell, group)`; 2-D split to `(x, y, group)` given edges |
| MAGGIE schema | `.npz`, `.h5` written by `maggie.io.write_flux` / `save` | named dims, edges, std, mesh, attrs |
| any other code | bare `.npy`/`.npz`/`.csv`/`.txt`/`.h5` | axes from `dims=` |

The reader is picked from the file contents, not only the extension.

```python
import maggie.io as mio

flux = mio.load("flux.npy", preset="ants", layout="1D time-dependent")  # -> Field
flux.dims                                    # ('time', 'x', 'group')
flux.isel(time=-1).sum("group")              # reductions keep coords

mio.load("flux.npy", dims="T x I x G")       # same, naming the axes directly
mio.entries("result.npz")                    # what is in a file (no data read)
mio.load("result.npz", "flux", edges_x=ex, edges_y=ey)  # NeutronDiffusion 2-D
```

From the command line, `maggie info FILE [KEY]` shows which readers
recognise a file, what it holds, and a summary of the loaded field.

### Writing MAGGIE files from a solver

```python
from maggie.io import write_flux

write_flux("slab.h5", flux, dims=("time", "x", "group"),
           x=edges_x, group=edges_g, time=times,
           attrs={"code": "ants", "keff": keff})
```

Coords are bin edges (length n+1) or centres (length n). Dim names:
`x y z r theta phi cell region group group_out time angle moment mu azi polar`
(`I`, `G`, `T` and other short forms are accepted).

### Plotting from scripts and notebooks

`maggie.plot` draws the viewer's plots with matplotlib alone (no Qt window),
for notebooks or saving figures:

```python
import maggie
from maggie.plot import plot

flux = maggie.load("flux.npy", preset="ants", layout="1D time-dependent")
ax = plot(flux)                                  # last step, summed over groups
plot(flux, group=3, step=0, log=True)            # one group, first step
plot(flux, kind="spectrum", at={"x": 500})       # energy spectrum at cell 500
plot({"ants": flux, "discrete1": other})         # overlay runs
ax.figure.savefig("flux.png")
```

Two spatial axes give a colour map; for 3-D pick the plane and slice with
`plane=("x", "z"), at={"y": 10}`.

## Download

Prebuilt executables for Windows, macOS, and Linux are attached to each
[GitHub Release](https://github.com/bwhewe-13/maggie/releases) (no Python
install needed).

- **Windows**: unzip and run `maggie.exe`. SmartScreen may warn because the
  exe is unsigned — click "More info" → "Run anyway".
- **macOS**: unzip and open `maggie.app`. The app is unsigned, so Gatekeeper
  blocks the first launch — right-click → Open, or run
  `xattr -dr com.apple.quarantine maggie.app`. Pick the `arm64` zip for
  Apple Silicon or `x64` for Intel.
- **Linux**: untar and run `./maggie`.

The single-file executables self-extract on launch, so the first start takes a
few seconds.

## Development

```bash
git clone https://github.com/bwhewe-13/maggie.git && cd maggie
pip install -e ".[dev]"     # plus pytest, pytest-qt
pytest                      # headless; GUI tests run offscreen
```

### Releasing

1. Set `version` in `pyproject.toml` (e.g. `0.2.1`) and merge to `main`.
2. Optional dry run: run the **Release** workflow by hand (Actions > Release
   > Run workflow). It builds the package and tests the installed wheel but
   publishes nothing.
3. Tag and push: `git tag v0.2.1 && git push origin v0.2.1`. The workflow
   checks the tag matches the version, runs the tests, tests the built wheel,
   publishes to PyPI and attaches executables to a GitHub Release.

Publishing uses PyPI trusted publishing: on pypi.org the project has a
publisher for this repository, workflow `release.yml`, environment `pypi`.

## Layout

```
src/maggie/
  core/dims.py        canonical dimension names + aliases
  core/field.py       Field - named-dim array + coords, std, mesh, attrs (no Qt)
  core/mesh.py        UnstructuredMesh (CSR cells)
  core/xs.py          cross sections -> reaction rate densities
  core/session.py     LoadSpec (load-screen choices) -> Session (datasets + rates)
  core/views.py       field -> what one plot shows (group/time/slice selection)
  io/base.py          Reader interface, registry, detect/entries/load
  io/schema.py        MAGGIE file schema: reader + save/write_flux
  io/presets.py       axis layouts for bare arrays from ants/discrete1/ndiffusion
  io/readers/         arrays (bare files + presets), ndiffusion
  gui/load_window.py  screen 1: files, cross sections, discretizations
  gui/viewer_window.py screen 2: one tab per quantity
  gui/field_view.py   controls + matplotlib plot used by each tab
  plot.py             matplotlib plots without Qt (used by the viewer tabs)
  app.py              command line, window controller (main())
```

## Extending

- **New file format**: subclass `maggie.io.Reader` in `io/readers/`, decorate
  it with `@register`, and import it in `io/readers/__init__.py`. Implement
  `sniff` (0-100 confidence), `entries` (metadata only), and `read` (-> `Field`).
- **New bare-array code**: add its layouts to `PRESETS` in `io/presets.py`.
