Skip to content

niess

Neutron instruments of the European Spallation Source, described once as calibrated Python objects, and emitted as whatever a downstream tool needs.

A McStas .instr file is a flat list of numbers. It says a guide is 2 metres long and sits 1.5 metres from the moderator, but not that the 1.5 came from a survey, nor how to move the guide without editing three other lines. It also says nothing a NeXus file needs. niess keeps the calibration — measured quantities with units, positions chained rather than repeated — and derives the rest:

flowchart LR
    C[calibration<br/>scipp Variables] --> N[niess objects]
    N --> M[McStas .instr]
    N --> X[ESS NeXus<br/>Structure JSON]
    N --> S[CAD / STEP]

Install

pip install niess

Two ways in

In sixty seconds

from mccode_antlr import Flavor
from mccode_antlr.assembler import Assembler
from niess.bifrost import Primary, Tank
from niess.bifrost.parameters import primary_parameters, tank_parameters
from niess.nexus import to_nexus_structure
from niess.nexus.bifrost import BIFROST_REGISTRY

assembler = Assembler('bifrost', flavor=Flavor.MCSTAS)
Primary.from_calibration(primary_parameters()).to_mccode(assembler)
Tank.from_calibration(tank_parameters()).to_mccode(assembler, 'sample_origin')

structure = to_nexus_structure(
    assembler.instrument, origin='sample_origin', registry=BIFROST_REGISTRY,
)

BIFROST is the instrument that exists today; niess.teaching is a small worked example written to be read, and is the subject of the guides.

Where to go next