Install and first instrument¶
niess needs Python 3.11 or newer. It pulls in scipp for units and geometry and
mccode-antlr for the McStas side.
Build an instrument¶
niess.teaching is a small instrument that ships with niess. Building it means turning
its calibration into a McStas instrument:
from niess.instrument import Instrument, Mount
from niess.mccode import to_mccode
from niess.teaching import Primary
teaching = Instrument(name='teaching', origin='sample_origin', parts=(
Mount(name='primary', content=Primary.from_calibration()),
))
instrument = to_mccode(teaching)
instrument is an mccode_antlr object. str(instrument) is the .instr text, and
it can be compiled and run by McStas like any other.
Seven components come out of that: the moderator, two guide units, a chopper, a jaw, a
monitor and the sample position. So do eight run-time parameters —
source_lambda_min, source_lambda_max, chopper_rotation_speed,
chopper_experiment_delay, chopper_mechanical_delay, pulse_delay, jaw_left and
jaw_right — which nothing had to declare by hand. Each is named for the log ESS
publishes it as, and declared in that log's unit: the delays in nanoseconds and degrees,
the jaw edges in millimetres. The chopper and the jaw generate their
own, and the source wavelengths were given in the calibration as parameter
specifications rather than values.
Convert it to NeXus¶
The same object converts to the JSON the ESS filewriter consumes:
and its contents can be inspected without walking dictionaries by hand:
from niess.nexus import find_child, get_attribute
instrument = structure['children'][0]['children'][0]
classes = {
get_attribute(child, 'NX_class')
for child in instrument['children'] if child.get('type') == 'group'
}
That yields NXmoderator, NXguide, NXdisk_chopper, NXaperture, NXmonitor and
NXcomponent groups — the last of those being the things that are only a place, which
say so in a description. The chopper's rotation_speed is not a number but a link
to an NXlog, because chopper_rotation_speed is settable at run time — see
constants become values, run-time knobs become links.
Next¶
- Core concepts — what a component, a section and a calibration actually are.
- Build a new instrument submodule — the teaching instrument, explained line by line.
- Translate an existing
.instr— if you already have a McStas model.