BaseContainer¶
- class marxs.simulator.BaseContainer(**kwargs)[source]¶
Bases:
SimulationSequenceElementBase class for containers that contain several
SimulationSequenceElementobjects.Define a new MARXS element.
Attributes Summary
Dictionary for display specifications, e.g. color.
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
clsin 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
- elements_of_class(cls, subclass_ok=False, stop_at_first=False)[source]¶
Walk a hirachy of simulation elements to all elements of a class.
This walks the hiracy of
marxs.simulator.Sequenceandmarxs.simulator.Parallelobjects. It descends depth-first. Typically, this function is used to find, e.g. all detectors of an instrument or all gratings.If
stop_at_firstis set it descends depth-first only until it find an object of typecls. 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 asmarxs.simulator.Parallelare searched for this becomes more complex. The search does not descend any deeper if a matching element is found. For example, if it finds aParallelobject, where the elements of this object contain otherParallelobjects it will only return the top level one.Parameters¶
- clsclass
The class searched for, e.g.
marxs.optics.FlatDetectorto find all detectors.- subclass_okbool
Controls if subclasses of
clscount 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]¶
Return the index of the first sub-element that has
clsin it.This walks the hiracy of
marxs.simulator.Sequenceandmarxs.simulator.Parallelobjects 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.FlatDetectorto find all detectors.- subclass_okbool
Controls if subclasses of
clscount as match.
Returns¶
- outint or None
index for the first element in
self.elementsthat is or contains an objects of classcls. If none is found, the method returnNone.