BaseContainer

class marxs.simulator.BaseContainer(**kwargs)[source] [edit on github]

Bases: SimulationSequenceElement

Base class for containers that contain several SimulationSequenceElement objects.

Define a new MARXS element.

Attributes Summary

display

Dictionary for display specifications, e.g. color.

elements

List of elements that are contained in this container.

Methods Summary

__call__(photons)

Call self as a function.

elements_of_class(cls[, subclass_ok, ...])

Walk a hirachy of simulation elements to all elements of a class.

first_of_class_top_level(cls[, subclass_ok])

Return the index of the first sub-element that has cls in it.

Attributes Documentation

display = {'shape': 'container'}

Dictionary for display specifications, e.g. color

elements = []

List of elements that are contained in this container.

Methods Documentation

__call__(photons)[source] [edit on github]

Call self as a function.

elements_of_class(cls, subclass_ok=False, stop_at_first=False)[source] [edit on github]

Walk a hirachy of simulation elements to all elements of a class.

This walks the hiracy of marxs.simulator.Sequence and marxs.simulator.Parallel objects. It descends depth-first. Typically, this function is used to find, e.g. all detectors of an instrument or all gratings.

If stop_at_first is set it descends depth-first only until it find an object of type cls. When it does, it adds that object to the output list and returns to the next higher level, continuing the search for the remaining elements of that list. This sounds more complicated than it is in practice. Only if container types such as marxs.simulator.Parallel are searched for this becomes more complex. The search does not descend any deeper if a matching element is found. For example, if it finds a Parallel object, where the elements of this object contain other Parallel objects it will only return the top level one.

Parameters:
clsclass

The class searched for, e.g. marxs.optics.FlatDetector to find all detectors.

subclass_okbool

Controls if subclasses of cls count as match.

stop_at_firstbool

Controls if the search continues along a branch after a match is found.

Returns:
outlist

Python list of all objects found.

first_of_class_top_level(cls, subclass_ok=False)[source] [edit on github]

Return the index of the first sub-element that has cls in it.

This walks the hiracy of marxs.simulator.Sequence and marxs.simulator.Parallel objects and returns the index of the first sub-element that contains a certain class.

Typically, this function is used to study and instrument with small modifications. If e.g. only the detector are changed, we might want to run a simulation up to the detectors, save te rays and then try out different detector combinations without rerunning the simulations for all earlier steps. This methid can help to identify the step that contains the detectors.

Parameters:
clsclass

The class searched for, e.g. marxs.optics.FlatDetector to find all detectors.

subclass_okbool

Controls if subclasses of cls count as match.

Returns:
outint or None

index for the first element in self.elements that is or contains an objects of class cls. If none is found, the method return None.