element_array#

class ElementArray(array_name, elements, use_aggregator=True)[source]#

Bases: list[Element]

Class that implements access to an element array

Parameters:
  • array_name (str) – Array name

  • elements (list[Element]) – Element list, all elements must be attached to the same instance of either a Simulator or a ControlSystem.

  • use_aggregator (bool) – Use aggregator to increase performance by using paralell access to underlying devices.

Example

An array can be retrieved from the configuration as in the following example:

>>> sr = Accelerator.load("acc.yaml")
>>> elements = sr.design.get_elements("QuadForTune")
__add__(other)[source]#

Alias for the union operator |.

Example

>>> all_corr = hcorr + vcorr
Returns:

Array – The result is automatically typed according to the most specific common base class of the remaining elements which can be: BPMArray or MagnetArray or CombinedFunctionMagnetArray or SerializedMagnetsArray or ElementArray.

__and__(other)[source]#

Intersection or boolean mask filtering.

This operator has two distinct behaviors depending on the type of other.

  1. Array intersection If other is an ElementArray, the result contains elements whose names are present in both arrays.

    Example

    >>> cell1 = sr.live.get_elements("C01")
    >>> sexts = sr.live.get_magnets("SEXT")
    >>> cell1_sext = cell1 & sexts
    
  2. Boolean mask filtering If other is a boolean mask (list[bool] or numpy.ndarray of bool), elements are kept where the mask is True.

    Example

    >>> mask = cell1.mask_by_type(Magnet)
    >>> magnets = cell1 & mask
    
Returns:

Array – The result is automatically typed according to the most specific common base class of the remaining elements which can be: BPMArray or MagnetArray or CombinedFunctionMagnetArray or SerializedMagnetsArray or ElementArray.

__or__(other)[source]#

Union between two ElementArray instances.

Elements are combined using their names as identity. Order is stable: elements from self first, followed by elements from other that are not already present.

Example

>>> hcorr = sr.live.get_magnets("HCORR")
>>> vcorr = sr.live.get_magnets("VCORR")
>>> all_corr = hcorr | vcorr
Returns:

Array – The result is automatically typed according to the most specific common base class of the remaining elements which can be: BPMArray or MagnetArray or CombinedFunctionMagnetArray or SerializedMagnetsArray or ElementArray.

__sub__(other)[source]#

Difference or boolean mask removal.

This operator has two behaviors depending on the type of other.

  1. Array difference If other is an ElementArray, the result contains elements whose names are present in self but not in other.

    Example

    >>> hvcorr = sr.live.get_magnets("HVCORR")
    >>> hcorr = sr.live.get_magnets("HCORR")
    >>> vcorr_only = hvcorr - hcorr
    
  2. Boolean mask removal If other is a boolean mask (list[bool] or numpy.ndarray of bool), elements are removed where the mask is True. This is the inverse of & mask.

    Example

    >>> mask = cell1.mask_by_type(Magnet)
    >>> non_magnets = cell1 - mask
    
Returns:

Array – The result is automatically typed according to the most specific common base class of the remaining elements which can be: BPMArray or MagnetArray or CombinedFunctionMagnetArray or SerializedMagnetsArray or ElementArray.

exclude_type(element_type)[source]#
get_name()[source]#

Returns the array name

get_peer()[source]#

Returns the peer (Simulator or ControlSystem) of an element list

mask_by_type(element_type)[source]#

Return a boolean mask indicating which elements are instances of the given type.

Parameters:

element_type (type) – The class to test against (e.g., Magnet).

Returns:

list[bool] – A list of booleans where True indicates the element is an instance of the given type (including subclasses).

names()[source]#

Returns the element names

of_type(element_type)[source]#

Return a new array containing only elements of the given type.

The resulting array is automatically typed according to the most specific common base class of the filtered elements.

Parameters:

element_type (type) – The class to filter by (e.g., Magnet).

Returns:

ElementArray or specialized array – An auto-typed array containing only matching elements. Returns [] if no elements match.