dipas.external module

class dipas.external.Paramodi

Bases: object

classmethod apply_units(paramodi: <MagicMock name='mock.DataFrame' id='139745936299280'>) List[Tuple]

Apply the specified units to the specified values.

If either the value is NaN or the unit is not available (---) the original value is used otherwise a corresponding quantity is computed. This uses the pint package for assigning the units.

Parameters

paramodi (pd.DataFrame) – Such as from parse().

Returns

quantities – A list containing the indices and quantities wherever applicable and the original values otherwise for each row of the paramodi data frame.

Return type

list of (index, pint.Quantity)

column_names = ['device', 'attribute', 'purpose', 'value', 'unit', 'parameter_name', 'original_value']
classmethod parse(f_name_or_text: str) <MagicMock name='mock.DataFrame' id='139745936299280'>

Parse the given paramodi file and return the data as a pandas data frame.

The resulting data frame has the following columns:

device, attribute, purpose, value, unit, parameter_name, original_value

where device and attribute are the original parameter name split at the first forward slash (/). parameter_name and original_value are the original representations of the parameter name and the parameter value. The first three columns serve as an index of the data frame.

Parameters

f_name_or_text (str) – File name pointing to the paramodi file or the content of such a file.

Return type

Data frame with the above described properties.

classmethod parse_line(line: str) Iterator[Tuple[str]]

Parse the given line into the required column values.

classmethod update_madx_device_data(devices: <MagicMock name='mock.DataFrame' id='139745936299280'>, paramodi: <MagicMock name='mock.DataFrame' id='139745936299280'>) DataFrame' id='139745936299280'>, dict]

Update the given MADX device data with values from the paramodi data.

This applies the following conversions:

  • [SBend] * angle is incremented by HKICK from the paramodi data.

  • [Quadrupole] * k1 is replaced by KL / q.L where KL is from the paramodi data.

  • [HKicker, VKicker] * kick is replaced by HKICK and VKICK respectively.

Parameters
  • devices (pd.DataFrame) – Data frame containing the MADX device data. Indices should be device labels and match those in the first index level of the paramodi data frame. Columns should be device attributes (NaN where no such attribute is applicable). There must be a "type" column which indicates the device type as MADX command keyword (e.g. “quadrupole” or “sbend”).

  • paramodi (pd.DataFrame) – Structure according to parse().

Returns

  • updated_devices (pd.DataFrame) – Data frame similar to devices with the relevant columns updated according to the above rules.

  • updates (dict) – A dict containing the applied updates. Keys are element labels and values are dicts that map parameter names to their new (updated) value.