External
External model Generate configuration table from MADX or ELEGANT output Insert locations into MADX or ELEGANT lattice files
Functions
load_tfs : Load TFS style table load_sdds : Load SDDS style table convert : Convert (sorted) columns to configuration table parse : Parse MADX or ELEGANT element or line load_lattice : Load MADX or ELEGANT lattice file text_lattice : Convert MADX or ELEGANT data to text rift_lattice : Rift MADX or ELEGANT lattice data (insert monitor or virtual locations) add_rc : Add RC from lattice to configuration table
External
rename (util) insert (util) select (util) cast (util)
- model.external.add_rc(table: Table, lattice: dict[str, dict[str, str | int | float | dict]], *, monitor: str = 'MONITOR', virtual: str = 'VIRTUAL') Table [source]
Add RC from lattice to configuration table
- Parameters:
table (Table) – configuration table
lattice (dict[str,dict[str,str|int|float|dict]]) – lattice data
monitor (str, default='MONITOR') – monitor kind
virtual (str, default='VIRTUAL')
- Return type:
Table
- model.external.convert(columns: dict[str, dict[str, str | int | float]], kind: Literal['TFS', 'SDDS'], kind_monitor: list[str], kind_virtual: list[str], *, dispersion: bool = False, rc: bool = False, name_monitor: list[str] | None = None, name_virtual: list[str] | None = None, monitor: str = 'MONITOR', virtual: str = 'VIRTUAL', rule: dict[str, str] | None = None) Table [source]
Convert (sorted) columns to configuration table
TFS parameters (MADX) can be used to setup CS model SDDS parameters (ELEGANT) can be used to setup CS and TM models
- Parameters:
columns (dict[str, dict[str, str|int|float]]) – columns to convert (sorted locations are assumed)
kind (Literal['TFS', 'SDDS']) – columns kind
kind_monitor (list[str]) – list of element types to identify with monitor locations
kind_virtual (list[str]) – list of element types to identify with virtual locations
dispersion (bool, default=False) – flag to insert zero dispersion values (original values are kept if present)
rc (bool, default=False) – flat to add RC key
name_monitor (Optional[list[str]]) – list of element names to set as monitor locations
name_virtual (Optional[list[str]]) – list of element names to set as virtual locations
monitor (str, default='MONITOR') – monitor kind
virtual (str, default='VIRTUAL') – virtual kind
rule (Optional[dict[str, str]]) – keys rename rule (appended to default rules)
- Return type:
Table
- model.external.load_lattice(path: Path, *, rc: bool = False) dict[str, dict[str, str | int | float | dict]] [source]
Load MADX or ELEGANT lattice file
- Parameters:
path (Path) – input path
rc (bool, default=False) – flag to parse comment as element
- Return type:
dict[str,dict[str,str|int|float|dict]]
- model.external.load_sdds(path: Path, *, postfix: str = '_') tuple[dict[str, str | int | float], dict[str, dict[str, str | int | float]]] [source]
Load SDDS style table
- Parameters:
path (Path) – input path
postfix (str, default='') – rename duplicate locations postfix
- Returns:
{key: value} (parameters) {location: {key: value}} (columns)
- Return type:
tuple[dict[str, str|int|float], dict[str, dict[str, str|int|float]]]
- model.external.load_tfs(path: Path, *, postfix: str = '_') tuple[dict[str, str | int | float], dict[str, dict[str, str | int | float]]] [source]
Load TFS style table
- Parameters:
path (Path) – input path
postfix (str, default='') – rename duplicate locations postfix
- Returns:
{key: value} (parameters) {location: {key: value}} (columns)
- Return type:
tuple[dict[str, str|int|float], dict[str, dict[str, str|int|float]]]
- model.external.parse(line: str, *, rc: bool = False) list[str, dict[str, str | int | float]] [source]
Parse MADX or ELEGANT element or line
Note, full definition is assumed to be on a singe line Element or line name should not contain ‘!’, ‘:’ or ‘”’ All elements should contain
name : line=(element, element, …) [;] [! comment] name : kind, [key=value, key=value, …] [;] [! comment]
Note, comma after element kind in mandatory If comment to be parsed as element it is assumed to match
name : kind, [key=value, key=value, …]
- Parameters:
line (str) – input line
rc (bool, default=False) – flag to parse comment as element
- Return type:
list[str, dict[str, str|int|float]]
- model.external.rift_lattice(lattice: dict[str, dict[str, str | int | float | dict]], monitor: str, virtual: str, kind_monitor: list[str], kind_virtual: list[str], *, include_monitor: list[str] | None = None, include_virtual: list[str] | None = None, exclude_monitor: list[str] | None = None, exclude_virtual: list[str] | None = None, prefix_monitor: str = 'M', prefix_virtual: str = 'V') dict[str, dict[str, str | int | float | dict]] [source]
Rift MADX or ELEGANT lattice data (insert monitor or virtual locations)
Elements with matching kinds or names are splitted in half (angle and length are halved) Observaton (monitor or virtual) location is inserted between parts Elements with zero length are also splitted Original parameters are added to location RC Old element is replaced by a line
- Parameters:
monitor (str) – monitor type to use (e.g. MONITOR or MONI)
virtual (str) – virtual type to use (e.g. MARKER or MARK)
kind_monitor (list[str]) – list of element types to insert monitor locations
kind_virtual (list[str]) – list of element types to insert virtual locations
include_monitor (Optional[list[str]]) – list of element names to insert monitor locations
include_virtual (Optional[list[str]]) – list of element names to insert virtual locations
exclude_monitor (Optional[list[str]]) – list of element names to exclude from monitor locations
exclude_virtual (Optional[list[str]]) – list of element names to exclude form virtual locations
prefix_monitor (str, default='M') – monitor rename prefix
prefix_virtual (str, default='V') – virtual rename prefix
- Return type:
dict[str,dict[str,str|int|float|dict]]
- model.external.text_lattice(kind: Literal['MADX', 'LTE'], lattice: dict[str, dict[str, str | int | float | dict]], *, rc: bool = False) str [source]
Convert MADX or ELEGANT data to text
- Parameters:
kind (Literal['MADX', 'LTE']) – lattice lind
lattice (dict[str,dict[str,str|int|float|dict]]) – lattice data
rc (bool, default=False) – flag to parse RC as comment
- Return type:
str