tof.Model#
- class tof.Model(source=None, components=None, choppers=None, detectors=None)[source]#
A class that represents a neutron instrument. It is defined by a source and a list of components (choppers, detectors, etc.).
- Parameters:
source (
Source|None, default:None) – A source of neutrons.components (
list[Component] |tuple[Component,...] |None, default:None) – A list of components.choppers (
list[Chopper] |tuple[Chopper,...] |None, default:None) – A list of choppers. This is kept for backwards-compatibility; new code should use the components parameter instead.detectors (
list[Detector] |tuple[Detector,...] |None, default:None) – A list of detectors. This is kept for backwards-compatibility; new code should use the components parameter instead.
Methods
__init__([source, components, choppers, ...])add(component)Add a component to the instrument.
as_json()Return the model as a JSON-serializable dictionary.
from_json(filename)Create a model from a JSON file.
remove(name)Remove a component.
run()Run the simulation.
to_json(filename)Save the model to a JSON file.
Attributes
A dictionary of the choppers in the instrument.
A dictionary of the components in the instrument.
A dictionary of the detectors in the instrument.
A dictionary of the samples in the instrument.
- add(component)[source]#
Add a component to the instrument. Component names must be unique across choppers and detectors. The name “source” is reserved for the source, and can thus not be used for other components.
- as_json()[source]#
Return the model as a JSON-serializable dictionary. If the source is not from a facility, it is not included in the output.
Added in version 25.11.0.
- Return type:
- property choppers: MappingProxyType#
A dictionary of the choppers in the instrument.
- property detectors: MappingProxyType#
A dictionary of the detectors in the instrument.
- classmethod from_json(filename)[source]#
Create a model from a JSON file.
Currently, only sources from facilities are supported when loading from JSON.
Added in version 25.10.1.
- remove(name)[source]#
Remove a component.
- Parameters:
name (
str) – The name of the component to remove.
- property samples: MappingProxyType#
A dictionary of the samples in the instrument.