Skip to main content

No project description provided

Project description

niess

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install niess

License

niess is distributed under the terms of the BSD-3-Clause license.

Motivation

This package is intended to hold information about the Neutron Insruments of the European Spallation Source for use in defining Monte Carlo ray-tracing simulations, file-layout information for use by the ESS file-writers, and other yet-undefined uses; in a use-agnostic approach.

The information required about an instrument for McStas and NeXusStructure is similar but not identical -- the latter attempts to hold all information needed to produce a valid NeXus file, which requires geometry information inspired by the McCode implementation used by McStas.

The two uses each have their own vocabulary, and the vocabulary used here is more closely in line with that of McCode. The basic building block of the two uses is the Comp in McCode and the NXclass in NeXus; here the term 'component' is used to refer to such a building block. Since there are sometimes slight differences between the 'same' Comp and NXclass in how equivalent information is stored, niess is intended to be component-aware as a single translation between the two is not possible globally.

Rather than attempting to store one implementation or the other, niess components are an independent low-level representation of the properties of a component. This representation can be written as a dictionary with pre-defined keys, and it is intended that serializing to and deserializing from such a representation can be used to provide calibrated instrument information to McStas and NeXusStructure.

Use

Thus far only as-designed information is provided for the BIFROST indirect geometry multiplexing spectrometer. You can load this information in a Python script, and use them to define a niess representation of the primary and secondary spectrometers

from niess.bifrost.parameters import primary_parameters, known_channel_params
from niess.bifrost import Primary, Tank
primary = Primary.from_calibration(primary_parameters())
secondary = Tank.from_calibration(known_channel_params())

The primary spectrometer begins at the source, here located at the nominal position of the viewed moderator in the Instrument Specific Coordinate System (ISCS), and ends with the position of the sample in the same coordinate system.

The secondary spectrometer is defined in a coordinate system relative to the sample position.

It is possible to convert the niess representations of these instrument parts to their McCode representation and insert them into a McStas instrument by leveraging an Assembler from the mccode_antlr package.

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


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

Optional CAD information

When a niess object is exported to mccode_antlr, the emitted component instances can also receive niess-specific METADATA describing their originating niess type. This can be used to build a more faithful CAD representation than the default MCDISPLAY fallback:

from scipp import vector, scalar
from scipp.spatial import rotations_from_rotvecs
from mccode_antlr import Flavor
from mccode_antlr.assembler import Assembler
from niess.components import Guide
from niess.mccode import add_niess_metadata
from niess.brep import instrument_to_assembly, save_step

assembler = Assembler('instrument', flavor=Flavor.MCSTAS)

width, height, substrate_thickness = 0.1, 0.2, 0.005  # m
guide = Guide(
    name="guide", 
    position=vector([0, 0, 0], unit='m'), 
    orientation=rotations_from_rotvecs(vector([0, 0, 0], unit='degree')),
    length=scalar(1., unit='m'),
    left=1.,  right=1., top=1., bottom=1. # m-values are unitless
)
instance = guide.to_mccode(assembler, insert_brep_metadata=True)
# Override the standard extra information to include the guide substrate thickness,
# which is not represented in McStas but can be drawn in CAD software
add_niess_metadata(instance, guide, extra={'substrate': substrate_thickness})

assembly = instrument_to_assembly(assembler.instrument)
save_step(assembly, 'bifrost.step')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niess-0.4.0.tar.gz (78.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niess-0.4.0-py3-none-any.whl (91.5 kB view details)

Uploaded Python 3

File details

Details for the file niess-0.4.0.tar.gz.

File metadata

  • Download URL: niess-0.4.0.tar.gz
  • Upload date:
  • Size: 78.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for niess-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2e53f8a8eb9a7bb63a3c47f09a449dfc60c176bdf7ac80c80c490ca517928511
MD5 1a4533edf15c3c0fa398f8050e54d42b
BLAKE2b-256 e0c3578e8ee698bafe14c12ce6f8d402306408da331a75c0587f0e2f20a73aea

See more details on using hashes here.

Provenance

The following attestation bundles were made for niess-0.4.0.tar.gz:

Publisher: build-and-publish.yml on g5t/niess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file niess-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: niess-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 91.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for niess-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b3ddcdb593408525b4ec9c81b7c03883b5f69910c5041c1b308e589ed8bd557
MD5 59496e4f4fe359fce5fd9f7197994202
BLAKE2b-256 d29bde5a5ff4b506ebfe3f843a902460dc4df0c0e8443174cfaa93cc7ae8ee59

See more details on using hashes here.

Provenance

The following attestation bundles were made for niess-0.4.0-py3-none-any.whl:

Publisher: build-and-publish.yml on g5t/niess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page