pytac.element#

Module containing the element class.

Members

Element

Class representing one physical element in an accelerator lattice.

EpicsElement

EPICS-aware element.

class pytac.element.Element(length, element_type, name=None, lattice=None)[source]#

Class representing one physical element in an accelerator lattice.

An element has zero or more devices (e.g. quadrupole magnet) associated with each of its fields (e.g. ‘b1’ for a quadrupole).

Attributes:

name#

The name identifying the element. The user is free to define this for their own purposes.

Type:

str

type_#

The type of the element. The user is free to define this for their own purposes.

Type:

str

length#

The length of the element in metres.

Type:

float

Parameters:
  • length (float) – The length of the element.

  • element_type (str) – The type of the element.

  • name (str) – The unique identifier for the element in the ring.

  • lattice (Lattice) – The lattice to which the element belongs.

Methods:

property index#

The element’s index within the ring, starting at 1.

Type:

int

property s#

The element’s start position within the lattice in metres.

Type:

float

property cell#

The lattice cell this element is within.

N.B. If the element spans multiple cells then the cell it begins in is returned (lowest cell number).

Type:

int

property families#

All families that this element is in.

Type:

set(str)

set_default_data_source(data_source_type: str) None[source]#

Set the default data source for this element.

Parameters:

data_source_type – the type of the data source being set: pytac.LIVE or pytac.SIM.

set_default_units(units: str) None[source]#

Set the default units type for this element.

Parameters:

units – pytac.PHYS or pytac.ENG

set_data_source(data_source: DataSource, data_source_type: str) None[source]#

Add a data source to the element.

Parameters:
  • data_source – the data source to be set.

  • data_source – the type of the data source being set: pytac.LIVE or pytac.SIM.

get_fields()[source]#

Get the all fields defined on an element.

Includes all fields defined by all data sources.

Returns:

A dictionary of all the fields defined on an element,

separated by data source(key).

Return type:

dict

add_device(field, device, uc)[source]#

Add device and unit conversion objects to a given field.

A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices.

Parameters:
  • field (str) – The key to store the unit conversion and device objects.

  • device (Device) – The device object used for this field.

  • uc (UnitConv) – The unit conversion object used for this field.

Raises:

DataSourceException – if no DeviceDataSource is set.

get_device(field)[source]#

Get the device for the given field.

A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices.

Parameters:

field (str) – The lookup key to find the device on an element.

Returns:

The device on the given field.

Return type:

Device

Raises:

DataSourceException – if no DeviceDataSource is set.

get_unitconv(field)[source]#

Get the unit conversion option for the specified field.

Parameters:

field (str) – The field associated with this conversion.

Returns:

The object associated with the specified field.

Return type:

UnitConv

Raises:

FieldException – if no unit conversion object is present.

set_unitconv(field, uc)[source]#

Set the unit conversion option for the specified field.

Parameters:
  • field (str) – The field associated with this conversion.

  • uc (UnitConv) – The unit conversion object to be set.

add_to_family(family)[source]#

Add the element to the specified family.

Parameters:

family (str) – Represents the name of the family.

is_in_family(family)[source]#

Return true if the element is in the specified family.

Parameters:

family (str) – Family to check.

Returns:

true if element is in the specified family.

get_value(field, handle='readback', units='default', data_source='default', throw=True)[source]#

Get the value for a field.

Returns the value of a field on the element. This value is uniquely identified by a field and a handle. The returned value is either in engineering or physics units. The data_source flag returns either real or simulated values.

Parameters:
  • field (str) – The requested field.

  • handle (str) – pytac.SP or pytac.RB.

  • units (str) – pytac.ENG or pytac.PHYS returned.

  • data_source (str) – pytac.LIVE or pytac.SIM.

  • throw (bool) – On failure: if True, raise ControlSystemException; if False, return None and log a warning.

Returns:

The value of the requested field

Return type:

float

Raises:
set_value(field, value, units='default', data_source='default', throw=True)[source]#

Set the value for a field.

This value can be set on the machine or the simulation.

Parameters:
  • field (str) – The requested field.

  • value (float) – The value to set.

  • units (str) – pytac.ENG or pytac.PHYS.

  • data_source (str) – pytac.LIVE or pytac.SIM.

  • throw (bool) – On failure: if True, raise ControlSystemException: if False, log a warning.

Raises:
set_lattice(lattice)[source]#

Set the stored lattice reference for this element to the passed lattice object.

Parameters:

lattice (Lattice) – lattice object to store a reference to.

class pytac.element.EpicsElement(length, element_type, name=None, lattice=None)[source]#

EPICS-aware element.

Adds get_pv_name() method.

Methods:

Parameters:
  • length (float) – The length of the element.

  • element_type (str) – The type of the element.

  • name (str) – The unique identifier for the element in the ring.

  • lattice (Lattice) – The lattice to which the element belongs.

Methods:

get_pv_name(field, handle)[source]#

Get PV name for the specified field and handle.

Parameters:
  • field (str) – The requested field.

  • handle (str) – pytac.RB or pytac.SP.

Returns:

The readback or setpoint PV for the specified field.

Return type:

str

Raises: