API documentation

Pytac: Python Toolkit for Accelerator Controls.

pytac.cs module

Class representing an abstract control system.

class pytac.cs.ControlSystem[source]

Bases: object

Abstract base class representing a control system.

get(pv)[source]

Get the value of the given pv.

Parameters:pv (string) – The pv to get the value of.
Returns:The numeric value of the pv.
Return type:Number
put(pv, value)[source]

Put the value of a given pv.

Parameters:
  • pv (string) – The pv to put the value for.
  • value (Number) – The value to be set.

pytac.device module

The device class used to represent a particular function of an accelerator element.

A physical element in an accelerator may have multiple devices: an example at DLS is a sextupole magnet that contains also horizontal and vertical corrector magnets and a skew quadrupole.

class pytac.device.Device(name, cs, enabled=True, rb_suffix=None, sp_suffix=None)[source]

Bases: object

A device attached to an element.

Contains a control system, readback and setpoint pvs. A readback or setpoint pv is required when creating a device otherwise a PvException is raised. The device is enabled by default.

get_cs()[source]
get_pv_name(handle)[source]

Get a pv name on a specified handle.

Parameters:handle (string) – The readback or setpoint handle to be returned.
Returns:A readback or setpoint pv.
Return type:string
get_value(handle)[source]

Read the value of a readback or setpoint pv.

If neither readback or setpoint pvs exist then a PvException is raised.

Parameters:handle (string) – Handle used to get the value off a readback or setpoint pv.
Returns:The value of the pv.
Return type:Number
Raises:PvException – In case the requested pv doesn’t exist.
is_enabled()[source]

Whether the device is enabled.

Returns:whether the device is enabled
Return type:boolean
put_value(value)[source]

Set the device value.

Parameters:value (Number) – The value to set on the pv.
Raises:PvException – An exception occured when no setpoint pv exists.
class pytac.device.PvEnabler(pv, enabled_value, cs)[source]

Bases: object

pytac.element module

Module containing the element class.

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

Bases: object

Class representing one physical element in an accelerator lattice.

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

name

str – name identifying the element

type_

str – type of the element

length

number – length of the element in metres

cell

int – the element’s cell within the lattice

families

set – the families this element is a member of

add_device(field, device, uc)[source]

Add device and unit conversion objects to a given field.

Parameters:
  • field (string) – The key to store the unit conversion and device objects.
  • device (Device) – Represents a device stored on an element.
  • uc (PolyUnitConv/PchipUnitConv) – Represents a unit conversion object stored for a device.
add_to_family(family)[source]

Add the element to the specified family.

Parameters:family (string) – Represents the name of the family
get_cs(field)[source]
get_device(field)[source]

Get the device for the given field.

Parameters:field (string) – The lookup key to find the device on an element.
Returns:The device on the given field.
Return type:Device
Raises:KeyError if no such device exists
get_fields()[source]

Get the fields defined on an element.

Returns:A sequence of all the fields defined on an element.
Return type:list
get_pv_name(field, handle='*')[source]

Get a pv name on a device.

Can return the readback and setpoint pvs if no handle is specified.

Parameters:
  • field (string) – Uniquely identifies a device.
  • handle (string) – Can be ‘readback’ or ‘setpoint’ to return each pv. If neither is specified then both pvs are returned.
Returns:

A readback or setpoint pv associated with the identified device.

Return type:

string

Raises:
  • PvException – An exception occured accessing a field with
  • no associated device.
get_value(field, handle, unit='engineering', model='live')[source]

Get the value for a field.

Returns the value for 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 model flag returns either real or simulated values.

Parameters:
  • field (string) – Choose which device to use.
  • handle (string) – Can take as value either ‘setpoint’ or ‘readback’.
  • unit (string) – Specify either engineering or physics units to be returned.
  • model (string) – Set whether real or simulated values to be returned.
Returns:

A number that corresponds to the value of the identified field.

Return type:

Number

Raises:

PvException – When there is no associated device on the given field.

set_model(model)[source]
set_value(field, value, unit='engineering', model='live')[source]

Set the value on a uniquely identified device.

This value can be set on the machine or the simulation. A field is required to identify a device. Returned value can be engineering or physics.

Parameters:
  • field (string) – The key used to identify a device.
  • value (float) – The value set on the device.
  • unit (string) – Can be engineering or physics units.
  • model (string) – The type of model: simulation or live
Raises:
  • PvException – An exception occured accessing a field with
  • no associated device.

pytac.epics module

Module to implement an EpicsControlSystem object which is used to get real-time data from the machine.

class pytac.epics.EpicsControlSystem[source]

Bases: pytac.cs.ControlSystem

The EPICS control system.

It is used to communicate over channel access with the hardware in the ring.

get(pv)[source]

Get the value of a given pv.

Parameters:pv (string) – The process variable given as a string. It can be a readback or a setpoint pv.
Returns:Represents the current value of the given pv.
Return type:float
put(pv, value)[source]

Set the value for a given.

Parameters:
  • pv (string) – The pv to set the value of. It must be a setpoint pv.
  • value (Number) – The value to set the pv to.

pytac.exceptions module

Module to represent existent exceptions in Pytac.

exception pytac.exceptions.ElementNotFoundException[source]

Bases: exceptions.Exception

exception pytac.exceptions.PvException[source]

Bases: exceptions.Exception

exception pytac.exceptions.UniqueSolutionException[source]

Bases: exceptions.Exception

pytac.lattice module

Representation of a lattice object which contains all the elements of the machine.

class pytac.lattice.Lattice(name, control_system, energy)[source]

Bases: object

add_element(element)[source]

Add an element to the lattice.

Parameters:element (Element) – The element to be inserted into the lattice.
get_all_families()[source]

Get all available families of the lattice.

Returns:Contains all available families in the lattice.
Return type:set(string)
get_device_names(family, field)[source]

Get the names for devices attached to a specific field for elements in the specfied family.

Typically all elements of a family will have devices associated with the same fields - for example, BPMs each have device for fields ‘x’ and ‘y’.

Parameters:
  • family – family of elements
  • field – field specifying the devices
Returns:

devices for specified family and field

Return type:

list(devices)

get_devices(family, field)[source]

Get devices attached to a specific field for elements in the specfied family.

Typically all elements of a family will have devices associated with the same fields - for example, BPMs each have device for fields ‘x’ and ‘y’.

Parameters:
  • family – family of elements
  • field – field specifying the devices
Returns:

devices for specified family and field

Return type:

list(devices)

get_elements(family=None, cell=None)[source]

Get the elements of a family from the lattice.

If no family is specified it returns all elements.

Elements are returned in the order they exist in the ring.

Parameters:
  • family (string) – Restrict elements to those in this family
  • cell (int) – Restrict elements to those in the specified cell
Returns:

A list that contains all elements of the specified family.

Return type:

list(Element)

get_energy()[source]

Function to get the total energy of the lattice.

Returns:The total energy of the lattice.
Return type:Number
get_family_s(family)[source]

Get the positions for a set of elements from the same family.

Parameters:family (string) – The family the positions are being asked for.
Returns:A list of floating point numbers that represent the positions for each element.
Return type:list(float)
get_length()[source]

Returns the length of the lattice.

Returns:The length of the lattice.
Return type:float
get_pv_names(family, field, handle)[source]

Get all pv names for a specific family, field and handle.

Parameters:
  • family (string) – A specific family to requests elements of.
  • field (string) – The field to uniquely identify a device.
  • handle (string) – It is used to identify a readback or setpoint pv.
Returns:

A list of readback or setpoint pvs from the device.

Return type:

list(string)

get_pv_values(family, field, handle)[source]

Get all pv values for a set of pvs.

Parameters:
  • family (string) – A specific family to requests the values of.
  • field (string) – The field to uniquely identify a device.
  • handle (string) – It is used to identify a readback or setpoint pv.
Returns:

A list of readback or setpoint pv values from the device.

Return type:

list(float)

get_s(element)[source]

Find the position of a given element in the lattice.

Note that the given element must exist in the lattice.

Parameters:given_element – The element that the position is being asked for.
Returns:the position of the given element.
Return type:float
Raises
ElementNotFoundException: An exception is raised in case the element doesn’t exist inside the lattice.
set_model(model)[source]
set_pv_values(family, field, values)[source]

Set the pv value of a given family of pvs.

The pvs are determined by family and device. Note that only setpoint pvs can be modified.

Parameters:
  • family (string) – A specific family to set the value of.
  • field (string) – The field to uniquely identify a device.
  • values (list(float)) – A list of values to assign to the pvs.
Raises:
  • PvException – An exception raised in case the given list of values
  • doesn’t match the number of found pvs.

pytac.load_csv module

Module to load the elements of the machine from multiple csv files stored in the same directory.

pytac.load_csv.get_div_rigidity(energy)[source]
pytac.load_csv.get_mult_rigidity(energy)[source]
pytac.load_csv.load(mode, control_system=None, directory=None)[source]

Load the elements of a lattice from a directory.

Parameters:
  • mode (string) – The name of the mode to be loaded.
  • control_system (ControlSystem) – The control system to be used. If none is provided an EpicsControlSystem will be created.
  • directory (string) – Directory where to load the files from. If no directory is given the data directory at the root of the repository is used.
Returns:

The lattice containing all elements.

Return type:

Lattice

pytac.load_csv.load_unitconv(directory, mode, lattice)[source]

Load the unit conversion objects from a file.

Parameters:
  • directory (string) – The directory where the data is stored.
  • mode (string) – The name of the mode that is used.
  • lattice (Lattice) – The lattice object that will be used.

pytac.units module

An unit conversion object used to convert between physics and engineering units.

class pytac.units.PchipUnitConv(x, y, post_eng_to_phys=<function unit_function at 0x3ab96e0>, pre_phys_to_eng=<function unit_function at 0x3ab96e0>)[source]

Bases: pytac.units.UnitConv

class pytac.units.PolyUnitConv(coef, post_eng_to_phys=<function unit_function at 0x3ab96e0>, pre_phys_to_eng=<function unit_function at 0x3ab96e0>)[source]

Bases: pytac.units.UnitConv

class pytac.units.UnitConv(post_eng_to_phys=<function unit_function at 0x3ab96e0>, pre_phys_to_eng=<function unit_function at 0x3ab96e0>)[source]

Bases: object

eng_to_phys(value)[source]

Function that does the unit conversion.

Conversion from engineering to physics units. An additional function may be casted on the initial conversion.

Parameters:value (Number) – Value to be converted from engineering to physics units.
Returns:The result value.
Return type:result(Number)
phys_to_eng(value)[source]

Function that does the unit conversion.

Conversion from physics to engineering units. An additional function may be casted on the initial conversion.

Parameters:value (Number) – Value to be converted from physics to engineering units.
Returns:The result value.
Return type:result(Number)
pytac.units.unit_function(value)[source]

Default value for the pre and post functions used in unit conversion.

Parameters:value (Number) – The value to be converted.
Returns:The result of the conversion.
Return type:value(Number)