Architecture

NEREIDS is organized as a Rust workspace with seven library crates, a GUI application, and Python bindings.

Crate Dependency Graph

                    endf-mat (standalone lookup tables)
                        |
                   nereids-core (types, constants)
                   /    |    \
          nereids-endf  |  nereids-io
            (ENDF)      |    (TIFF, NeXus)
               \        |
           nereids-physics
            (cross-sections)
                 \
              nereids-fitting
               (LM, Poisson)
                      |
              nereids-pipeline ── nereids-io
              (orchestration)
                /         \
       nereids-python    nereids-gui
        (PyO3 bindings)  (egui desktop)

Crate Overview

CratePurpose
endf-matZero-dependency lookup tables: element symbols, MAT numbers, natural abundances, ZA encoding
nereids-coreCore types (Isotope, Resonance), physical constants, element data, error types
nereids-endfENDF file retrieval from IAEA, local caching, File 2 resonance parameter parsing
nereids-physicsCross-section calculation (Reich-Moore, SLBW, RML, URR), Doppler/resolution broadening, Beer-Lambert transmission
nereids-ioTIFF stack and NeXus/HDF5 loading, TOF-to-energy conversion, normalization, export
nereids-fittingLevenberg-Marquardt and Poisson KL divergence optimizers, transmission fit model
nereids-pipelineSingle-spectrum fitting, per-pixel spatial mapping (rayon), trace detectability
nereids-pythonPyO3 Python bindings (not published to crates.io)
nereids-guiegui desktop application (not published to crates.io)

Data Flow

The standard analysis pipeline processes data through these stages:

Raw TOF data (TIFF/NeXus)
    │
    ▼
Normalization (sample / open_beam → transmission)     [nereids-io]
    │
    ▼
Energy conversion (TOF bin edges → energy centers)    [nereids-io]
    │
    ▼
ENDF data (fetch resonance parameters from IAEA)      [nereids-endf]
    │
    ▼
Forward model (cross-sections → broadening → T(E))    [nereids-physics]
    │
    ▼
Fitting (minimize |T_measured - T_model|)              [nereids-fitting]
    │
    ▼
Spatial mapping (fit each pixel in parallel)           [nereids-pipeline]
    │
    ▼
Density maps, chi² maps, convergence maps              [output]

Key Design Decisions

Exact SAMMY Physics

All physics modules implement the exact formalisms from the SAMMY Fortran code, with no ad-hoc approximations. Every module references specific SAMMY source files and equation numbers. See the Physics Reference for details.

Workspace Architecture

The workspace is structured so that each crate has a single responsibility and minimal dependencies. nereids-core is the foundation with zero internal dependencies. Higher-level crates compose lower-level ones.

See ADR 0001 for the full rationale.

Parallel Spatial Mapping

Per-pixel fitting uses rayon for data parallelism. The outer pixel loop runs on a dedicated thread pool to avoid deadlocking with inner parallel operations (cross-section calculation, broadening).

Python Bindings via PyO3

The Python bindings expose a high-level API (load_endf, forward_model, fit_spectrum, spatial_map) that maps directly to the Rust pipeline. NumPy arrays are zero-copy where possible via numpy crate integration.