element module
Define base Element, declined in Drift, FieldMap, etc.
Todo
clean the patch for the ‘name’. my has and get methods do not work with @property
- class Element(line, dat_idx=None, idx_in_lattice=-1, lattice=-1, section=-1, **kwargs)[source]
Bases:
InstructionGeneric element.
- Parameters:
base_name – Short name for the element according to TraceWin. Should be overriden.
increment_elt_idx – If the element should be considered when counting the elements. If False,
elt_idxwill keep its default value of-1. As for now, there is no element with this attribute set to False.increment_lattice_idx – If the element should be considered when determining the lattice. Should be True for physical elements, such as
DRIFT, and False for other elements such asDIAGNOSTIC.line (
DatLine)idx_in_lattice (
int, default:-1)lattice (
int, default:-1)section (
int, default:-1)
- base_name = 'ELT'
- increment_elt_idx = True
- increment_lattice_idx = True
- __init__(line, dat_idx=None, idx_in_lattice=-1, lattice=-1, section=-1, **kwargs)[source]
Init parameters common to all elements.
- Parameters:
line (
DatLine) – A line of theDATfile. If the element was given a name, it must not appear inlinebut rather inname. First element of the list must be inPARAMETERS_1D.dat_idx (
int|None, default:None) – Position in theDATfile.name – Non-default name of the element, as given in the
DATfile. The default is None, in which case an automatic name will be given later.idx_in_lattice (
int, default:-1)lattice (
int, default:-1)section (
int, default:-1)
- Return type:
None
- get(*keys, to_numpy=True, **kwargs)[source]
Get attributes from this class or its nested members.
- Parameters:
*keys (
Literal['dat_idx','elt_idx','idx','idx_in_lattice','lattice','length_m','name','nature','section'] |Literal['abs_mesh','d_z','n_steps','rel_mesh','s_in','s_out','transf_mat_function']) – Names of the desired attributes.to_numpy (
bool, default:True) – If True, convert lists to NumPy arrays. If False, convert NumPy arrays to lists.**kwargs (
Any) – Other arguments passed to the recursive getter.
- Return type:
- Returns:
A single attribute value if one key is provided, otherwise a tuple of values.
- keep_cavity_settings(cavity_settings)[source]
Save data calculated by
BeamCalculator.run_with_this().- Parameters:
cavity_settings (
CavitySettings)- Return type:
- property is_accelerating: bool
Say if this element is accelerating or not.
Will return False by default.
- property can_be_retuned: bool
Tell if we can modify the element’s tuning.
Will return False by default.
- _abc_impl = <_abc._abc_data object at 0x7318fb36e000>
- class ELEMENT_TO_INDEX_T(*args, **kwargs)[source]
Bases:
ProtocolType for function linking an
Elementor its name to its index.In particular, it is used for the
getmethods.- __init__(*args, **kwargs)
- _abc_impl = <_abc._abc_data object at 0x7318fb6ae780>
- _is_protocol = True
- default_element_to_index(*, elt, pos=None, return_elt_idx=False, handle_missing_elt=False)[source]
Return all indexes whatever the inputs are.
- Parameters:
elt (
str|Element|Literal['first','last']) –Elementfor which you want position. Can be theElement.nameattribute or theElementinstance itself. Actually unused in this default function.pos (
Literal['in','out'] |None, default:None) – Position within theElement. If not provided, all indexes ofElementwill be returned. Actually unused in this default function.return_elt_idx (
bool, default:False) – Return a position in aListOfElementsinstance. Used for arguments such asphi_s, which holds one value perElement. Actually unused in this default function.handle_missing_elt (
bool, default:False) – Look for an equivalent element wheneltis not in_elts.
- Return type:
- Returns:
Index(es) of given
elt, at givenpos. Returns all indexes in this default function.