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: Instruction

Generic 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_idx will 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 as DIAGNOSTIC.

  • line (DatLine)

  • dat_idx (int | None, default: None)

  • 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
is_implemented: bool = 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 the DAT file. If the element was given a name, it must not appear in line but rather in name. First element of the list must be in PARAMETERS_1D.

  • dat_idx (int | None, default: None) – Position in the DAT file.

  • name – Non-default name of the element, as given in the DAT file. 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

property name: str

Give personalized name of element if exists, default otherwise.

has(key)[source]

Check if the given key exists in this element or its nested members.

Parameters:

key (str) – Name of the attribute to check.

Return type:

bool

Returns:

True if the key exists, False otherwise.

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:

Any

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:

None

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.

update_status(new_status)[source]

Change the status of the element.

To override.

Parameters:

new_status (Literal['compensate (in progress)', 'compensate (not ok)', 'compensate (ok)', 'failed', 'nominal', 'rephased (in progress)', 'rephased (ok)'])

Return type:

None

_abc_impl = <_abc._abc_data object at 0x7318fb36e000>
class ELEMENT_TO_INDEX_T(*args, **kwargs)[source]

Bases: Protocol

Type for function linking an Element or its name to its index.

In particular, it is used for the get methods.

__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']) – Element for which you want position. Can be the Element.name attribute or the Element instance itself. Actually unused in this default function.

  • pos (Literal['in', 'out'] | None, default: None) – Position within the Element. If not provided, all indexes of Element will be returned. Actually unused in this default function.

  • return_elt_idx (bool, default: False) – Return a position in a ListOfElements instance. Used for arguments such as phi_s, which holds one value per Element. Actually unused in this default function.

  • handle_missing_elt (bool, default: False) – Look for an equivalent element when elt is not in _elts.

Return type:

int | slice

Returns:

Index(es) of given elt, at given pos. Returns all indexes in this default function.