Other

TbT Converter

Top-level script to convert turn-by-turn files from various formats to LHC binary SDDS files. Optionally, it can replicate files with added noise.

omc3.tbt_converter.converter_entrypoint(opt)[source]

Converts turn-by-turn files from various formats to LHC binary SDDS files. Optionally can replicate files with added noise.

Converter Kwargs:
  • files: TbT files to convert

    Flags: --files Required: True

  • outputdir: Output directory.

    Flags: --outputdir Required: True

  • tbt_datatype (str): Choose datatype from which to import (e.g LHC binary SDDS).

    Flags: --tbt_datatype Default: lhc

  • output_datatype (str): Choose the datatype to export.

    Flags: --output_datatype Default: lhc

  • realizations (int): Number of copies with added noise.

    Flags: --realizations Default: 1

  • noise_levels (float): Sigma of added Gaussian noise.

    Flags: --noise_levels Default: None

  • use_average (bool): If set, returned sdds only contains the average over all particle/bunches.

    Flags: --use_average Default: False

  • drop_elements: Names of elements to drop from the input file during conversion.

    Flags: --drop_elements Default: None

Model Creator

Entrypoint to run the model creator for LHC, PSBooster and PS models.

omc3.model_creator.create_instance_and_model(opt, accel_opt) Accelerator[source]
Manager Keyword Args:

--Required--

  • accel:

    Choose the accelerator to use.Can be the class already.

    choices: ['lhc', 'ps', 'esrf', 'psbooster', 'skekb', 'JPARC', 'petra', 'iota']

Creator Keyword Args:

--Required--

  • outputdir (str):

    Output path for model, twiss files will be writen here.

--Optional--

  • logfile (str):

    Path to the file where to write the MAD-X script output.If not provided it will be written to sys.stdout.

  • type:

    Type of model to create.

    choices: ('nominal', 'best_knowledge', 'coupling_correction')

Accelerator Keyword Args:

lhc: omc3.model.accelerators.lhc

ps: omc3.model.accelerators.ps

esrf: omc3.model.accelerators.esrf

psbooster: omc3.model.accelerators.psbooster

skekb: omc3.model.accelerators.skekb

iota: omc3.model.accelerators.iota

petra: omc3.model.accelerators.petra (not implemented)

JPARC: Not implemented

Knob Extractor

Entrypoint to extract knobs from NXCALS at a given time, and eventually write them out to a file. This script can also be used to display information about the StateTracker State. The data is fetched from NXCALS through pytimber using the StateTracker fields.

Note

Please note that access to the GPN is required to use this functionality.

Arguments:

--Optional--

  • knob_definitions (PathOrStrOrDataFrame):

    User defined path to the knob-definitions, or (via python) a dataframe containing the knob definitions with the columns ‘madx’, ‘lsa’ and ‘scaling’.

  • knobs (str):

    A list of knob names or categories to extract. Available categories are: sep, xing, chroma, ip_offset, disp, mo.

    default: ['sep', 'xing', 'chroma', 'ip_offset', 'disp', 'mo']

  • output (PathOrStr):

    Specify user-defined output path. This should probably be model_dir/knobs.madx

  • state:

    Prints the state of the StateTracker. Does not extract anything else.

    action: store_true

  • time (str):

    At what time to extract the knobs. Accepts ISO-format (YYYY-MM- DDThh:mm:ss), timestamp or ‘now’. The default timezone for the ISO- format is local time, but you can force e.g. UTC by adding +00:00.

    default: now

  • timedelta (str):

    Add this timedelta to the given time. The format of timedelta is ‘((d+)(w))+’ with the second token being one of s(seconds), m(minutes), h(hours), d(days), w(weeks), M(months) e.g 7m = 7 minutes, 1d = 1day, 7m30s = 7 min 30 secs. A prefix ‘_’ specifies a negative timedelta. This allows for easily getting the setting e.g. 2h ago: ‘_2h’ while setting the time argument to ‘now’ (default).

class omc3.knob_extractor.Col[source]

DataFrame Columns used in this script.

class omc3.knob_extractor.Head[source]

TFS Headers used in this script.

omc3.knob_extractor.check_for_undefined_knobs(knobs_definitions: pd.DataFrame, knob_categories: Sequence[str])[source]

Check that all knobs are actually defined in the knobs-definitions.

Parameters:
  • knobs_definitions (pd.DataFrame) -- A mapping of all knob-names to KnobEntries.

  • knob_categories (Sequence[str]) -- Knob Categories or Knob-Names to extract.

Raises:

KeyError -- If one or more of the knobs don’t have a definition.

omc3.knob_extractor.extract(ldb, knobs: Sequence[str], time: datetime) dict[str, float][source]

Standalone function to gather data from the StateTracker. Extracts data via pytimber’s LoggingDB for the knobs given (either by name or by category) in knobs.

Parameters:
  • ldb (pytimber.LoggingDB) -- The pytimber database.

  • knobs (Sequence[str]) -- Knob Categories or Knob-Names to extract.

  • time (datetime) -- The time, when to extract.

Returns:

Contains all the extracted knobs. When extraction was not possible, the value is None.

Return type:

Dict[str, float]

omc3.knob_extractor.get_state(ldb, time: datetime) dict[str, str][source]

Standalone function to gather and log state data from the StateTracker.

Parameters:
  • ldb (pytimber.LoggingDB) -- The pytimber database.

  • time (datetime) -- The time, when to get the state.

Returns:

Dictionary of state-variable and the extracted state value.

Return type:

Dict[str, str]

omc3.knob_extractor.load_knobs_definitions(file_path: Path | str) DataFrame[source]

Load the knobs-definition file and convert into a DataFrame. Each line in this file should consist of at least three comma separated entries in the following order: madx-name, lsa-name, scaling factor. Other columns are ignored. Alternatively, a TFS-file is also allowed, but needs to have the suffix .tfs.

Parameters:

file_path (Path) -- Path to the knobs definition file.

Returns:

Dataframe with LSA names (but with colon instead of /) as keys and KnobEntries (without values) as value.

omc3.knob_extractor.lsa2name(lsa_name: str) str[source]

LSA name -> Variable in Timber/StateTracker conversion.

omc3.knob_extractor.main(opt) TfsDataFrame[source]

Main knob extracting function.

omc3.knob_extractor.name2lsa(name: str) str[source]

Variable in Timber/StateTracker -> LSA name conversion.

MAD-X Wrapper

madx_wrapper is high-level wrapper for running MAD-X codes within omc3.

Usage: python madx_wrapper.py --file your_madx_file.madx

exception omc3.madx_wrapper.MadxError[source]
omc3.madx_wrapper.run_file(input_file: Path, output_file: Path = None, log_file: Path = None, madx_path: Path = PosixPath('/home/runner/work/omc3/omc3/omc3/bin/madx-linux64-gnu'), cwd: Path = None)[source]

Runs MAD-X on a given script in a subprocess.

Parameters:
  • input_file -- MAD-X input file.

  • output_file -- If given writes MAD-X script.

  • log_file -- If given writes MAD-X logging output.

  • madx_path -- Path to the MAD-X executable.

omc3.madx_wrapper.run_string(input_string: str, output_file: Path = None, log_file: Path = None, madx_path: Path = PosixPath('/home/runner/work/omc3/omc3/omc3/bin/madx-linux64-gnu'), cwd: Path = None)[source]

Runs MAD-X on a given string in a subprocess.

Parameters:
  • input_string -- MAD-X input string.

  • output_file -- If given writes MAD-X script.

  • log_file -- If given writes MAD-X logging output.

  • madx_path -- Path to the MAD-X executable.