Skip to main content

inspy-conv

inspy-conv (install name: inspy-conv, import name: inspy) is a Python toolkit for inelastic neutron scattering data analysis. It provides triple-axis spectrometer resolution calculation (Cooper–Nathans / Popovici), resolution-convolution fitting of S(Q,ω) models, crystal lattice and space-group tools, and a Qt-based interactive GUI.

The resolution algorithms are the same as ResLib, with known issues tracked and fixed incrementally.


Features

  • Resolution calculation — Cooper–Nathans (method=0) and Popovici (method=1, default) formalisms in Q–E and HKL–E frames: R0 prefactor, RMS/RM matrices.
  • Resolution convolution fitting — fit S(Q,ω) parameters to measured scans by numerically convolving the model with the instrument resolution (FitConv, UltraFastFitConv).
  • Crystallography — lattices, UB orientation matrices, the 230 space groups, nuclear/magnetic structure factors, built-in scattering and form-factor databases.
  • Interactive GUI — unified E/Q-scan resolution-convolution fitting.
  • CLI — launches the unified fit GUI by default.

Installation

pip install inspy-conv

Editable development install:

git clone https://github.com/gcdengansto/inspy-conv
cd inspy-conv
pip install -e .

Dependencies: numpy, scipy, matplotlib, pandas, lmfit, h5py, plotly, QtPy, PySide6 (Python ≥ 3.8).

Because GUI modules are imported lazily, import inspy itself only needs the core scientific stack — Qt/lmfit are required when a fitting GUI is actually launched. See docs/installation.md.


Command-line usage

Installing the package provides the inspy-conv console command:

inspy-conv            # unified energy/Q-scan fit GUI (default)
inspy-conv -fit       # unified energy/Q-scan convolution-fit GUI
inspy-conv -h         # help

The unified fitting GUI starts with or without -fit. python -m inspy [flag] is equivalent. Full reference: docs/cli.md.


Quick start

import inspy

# Neutron beam: 14.7 meV
en = inspy.Energy(energy=14.7)
print(en.wavelength)      # Angstrom
print(en.wavevector)      # 1/Angstrom

# Cubic sample, 30' mosaic
sample = inspy.Sample(a=3.0, b=4.0, c=5.0,
                      alpha=90, beta=90, gamma=90,
                      u=[1, 0, 0], v=[0, 1, 0],
                      mosaic=30, vmosaic=30)

# Triple-axis spectrometer, fixed Ef = 14.7 meV (Popovici by default)
tas = inspy.TripleAxisSpectr(efixed=14.7, method=1)
tas.sample = sample
tas.hcol = [40, 40, 40, 120]     # collimation in arcmin
tas.arms = [200, 100, 100, 200]  # distances in cm

# Resolution at (H, K, L, E) = (2, 0, 0, 0)
tas.CalcResMatHKL([2, 0, 0, 0])
print(tas.R0)    # prefactor, shape (N,)
print(tas.RMS)   # 4x4 resolution matrix, shape (N, 4, 4)
print(tas.RM)    # resolution matrix in the Q frame

CalcResMatHKL stores its results on the instrument object (R0, RMS, RM) and returns None.

More in docs/quickstart.md.


Package structure

src/inspy/
├── __main__.py            # CLI dispatch (unified fit GUI)
├── constants.py           # Physical constants + database loaders
├── energy.py              # Energy / wavelength / wavevector conversion
├── crystal/               # Crystallography
│   ├── lattice.py         #   Lattice: metric tensors, d-spacing, volume
│   ├── sample.py          #   Sample: UB orientation matrix, mosaic
│   ├── atom.py            #   Atom / MagneticAtom
│   ├── symmetry.py        #   SpaceGroup: 230 groups, symmetry operations
│   ├── structure_factors.py  # Nuclear / magnetic structure factors
│   └── material.py        #   Material = Sample + structure factors
├── instrument/            # Instrument models
│   ├── mono.py            #   Monochromator (+ built-in crystal tau table)
│   ├── ana.py             #   Analyzer
│   ├── components.py      #   Chopper, Detector, Guide (Time-of-Flight)
│   ├── tas_spectr.py      #   TripleAxisSpectr — core resolution engine
│   ├── tof_spectr.py      #   TimeOfFlightSpectr (stub)
│   └── tools.py           #   Projection utilities, get_tau, Bragg/phonon widths
├── insfit/                # Resolution-convolution fitting
│   ├── fitconv.py         #   FitConv (scipy.optimize.least_squares, method='trf')
│   └── uffitconv.py       #   UltraFastFitConv (caching, precompute, adaptive steps)
├── gui/                   # Qt graphical interfaces (imported lazily)
│   ├── gui_convfit_uf.py  #   Unified E/Q-scan convolution-fit GUI
│   ├── tools.py           #   Shared widgets + demo S(Q,w)/prefactor models
│   └── ui/                #   Qt Designer .ui files
└── database/              # JSON data files (packaged via pyproject.toml)
    ├── magnetic_form_factors.json
    ├── periodic_table.json
    ├── scattering_lengths.json
    └── symmetry.json

Documentation

Detailed documentation lives in docs/ and is written to be publishable as a static site with MkDocs (config provided in mkdocs.yml):

pip install mkdocs
mkdocs serve     # http://127.0.0.1:8000
mkdocs build     # static site in site/
Document Contents
Installation Install, dependencies, verification, troubleshooting
Quick start End-to-end first calculation
CLI reference inspy-conv flags and behaviour
Energy Neutron energy conversions
Crystallography Lattice, Sample, Atom, Material, SpaceGroup, structure factors
Resolution TripleAxisSpectr, theory notes, plotting, utilities
Convolution fitting FitConv, UltraFastFitConv, S(Q,ω) models
GUIs The three graphical interfaces
Architecture Package layout, lazy imports, packaging
Development Setup, tests, conventions, review history

Testing

pip install -e ".[dev]"
pytest tests/

References

  • A. Zheludev, ResLib 3.4c — MATLAB resolution library the TAS engine.
  • neutronpy conventions — several modules are adapted from neutronpy.

Author

Guochu Deng — gc.deng.ansto@gmail.com

License

MIT — see LICENSE.

Metadata

Release files for inspy-conv 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inspy-conv 0.5.0
File Size Uploaded Provenance Actions
inspy_conv-0.5.0.tar.gz 137.1 kB Without provenance Details for inspy_conv-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for inspy-conv 0.5.0
File Interpreter ABI Platform Actions
inspy_conv-0.5.0-py3-none-any.whl Python 3 none any Details for inspy_conv-0.5.0-py3-none-any.whl

Total release size: 263.6 kB

Release files / inspy_conv-0.5.0.tar.gz

Download URL inspy_conv-0.5.0.tar.gz
Size 137.1 kB
Tags Source
SHA-256 checksum
How to use checksums
27de73808ef7d834a16bdd5e16ab1aa61d726e91bbf40992bda8856805d0db7c
BLAKE2b-256 checksum
How to use checksums
2606d44fda6b0ab47579a4df9ad0b968285a4da5ad16216c7c88f18c927c247d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / inspy_conv-0.5.0-py3-none-any.whl

Download URL inspy_conv-0.5.0-py3-none-any.whl
Size 126.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5ae88f13f8bc34c3f5a18f0fe6b6c79fa7f20403cca4872373fc8a5cc2c6a6c
BLAKE2b-256 checksum
How to use checksums
b893295c1ef469345ae24cfe36cfc1339d6c994f7a4dfd7b042e16fb904ce0d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for inspy-conv 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page