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.

__init__(source=None, components=None, choppers=None, detectors=None)[source]#

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

choppers

A dictionary of the choppers in the instrument.

components

A dictionary of the components in the instrument.

detectors

A dictionary of the detectors in the instrument.

samples

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.

Parameters:

component (Component) – A chopper or detector.

Return type:

None

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:

dict

property choppers: MappingProxyType#

A dictionary of the choppers in the instrument.

property components: dict[str, Component]#

A dictionary of the components 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.

Parameters:

filename (str) – The path to the JSON file.

Return type:

Model

remove(name)[source]#

Remove a component.

Parameters:

name (str) – The name of the component to remove.

run()[source]#

Run the simulation.

Return type:

Result

property samples: MappingProxyType#

A dictionary of the samples in the instrument.

to_json(filename)[source]#

Save the model to a JSON file. If the source is not from a facility, it is not included in the output.

Added in version 25.11.0.

Parameters:

filename (str) – The path to the JSON file.

Return type:

None