element_array#
- class ElementArray(array_name, elements, use_aggregator=True)[source]#
-
Class that implements access to an element array
- Parameters:
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:
BPMArrayorMagnetArrayorCombinedFunctionMagnetArrayorSerializedMagnetsArrayorElementArray.
- __and__(other)[source]#
Intersection or boolean mask filtering.
This operator has two distinct behaviors depending on the type of
other.Array intersection If
otheris 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
Boolean mask filtering If
otheris 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:
BPMArrayorMagnetArrayorCombinedFunctionMagnetArrayorSerializedMagnetsArrayorElementArray.
- __or__(other)[source]#
Union between two ElementArray instances.
Elements are combined using their names as identity. Order is stable: elements from
selffirst, followed by elements fromotherthat 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:
BPMArrayorMagnetArrayorCombinedFunctionMagnetArrayorSerializedMagnetsArrayorElementArray.
- __sub__(other)[source]#
Difference or boolean mask removal.
This operator has two behaviors depending on the type of
other.Array difference If
otheris an ElementArray, the result contains elements whose names are present inselfbut not inother.Example
>>> hvcorr = sr.live.get_magnets("HVCORR") >>> hcorr = sr.live.get_magnets("HCORR") >>> vcorr_only = hvcorr - hcorr
Boolean mask removal If
otheris 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:
BPMArrayorMagnetArrayorCombinedFunctionMagnetArrayorSerializedMagnetsArrayorElementArray.
- get_peer()[source]#
Returns the peer (
SimulatororControlSystem) 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).
- 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.