tof.Model#

class tof.Model(source=None, choppers=None, detectors=None)[source]#

A class that represents a neutron instrument. It is defined by a list of choppers, a list of detectors, and a source.

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

Methods

__init__([source, choppers, detectors])

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.

add(component)[source]#

Add a component to the instrument. Component names must be unique across choppers and detectors.

Parameters:

component – A chopper or detector.

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.

Return type:

dict

classmethod from_json(filename)[source]#

Create a model from a JSON file.

Currently, only sources from facilities are supported when loading from JSON.

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.

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.

Parameters:

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