pytac.lattice
#
Representation of a lattice object which contains all the elements of the machine.
Members
EPICS-aware lattice class. |
|
Representation of a lattice. |
- class pytac.lattice.Lattice(name: str, symmetry: int | None = None)[source]#
Representation of a lattice.
Represents a lattice object that contains all elements of the ring. It has a name and a control system to be used for unit conversion.
Attributes:
- name#
The name of the lattice.
- symmetry#
The symmetry of the lattice (the number of cells).
- Parameters:
name – The name of the lattice.
symmetry – The symmetry of the lattice (the number of cells).
Methods:
- property cell_bounds: list[int] | None#
The indexes of elements in which a cell boundary occurs.
Examples
A lattice of 5 equal length elements with 2 fold symmetry would return [1, 4, 5] 1 - because it is the start of the first cell. 4 - because it is the first element in the second cell as the boundary between the first and second cells occurs halfway into the length of element 3. 5 - (len(lattice)) because it is the end of the second (last) cell.
- set_data_source(data_source: DataSource, data_source_type: str) None [source]#
Add a data source to the lattice.
- Parameters:
data_source – the data source to be set.
data_source_type – the type of the data source being set: pytac.LIVE or pytac.SIM.
- get_fields()[source]#
Get the fields defined on the lattice.
Includes all fields defined by all data sources.
- Returns:
- A dictionary of all the fields defined on the lattice,
separated by data source(key).
- Return type:
- 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:
- 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 the lattice.
- Returns:
The device on the given field.
- Return type:
- 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:
- Raises:
FieldException – if no unit conversion object is present.
- get_value(field, handle='readback', units='default', data_source='default', throw=True)[source]#
Get the value for a field on the lattice.
Returns the value of a field on the lattice. 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:
- Returns:
The value of the requested field
- Return type:
- Raises:
DataSourceException – if there is no data source on the given field.
FieldException – if the lattice does not have the specified field.
- 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:
- Raises:
DataSourceException – if arguments are incorrect.
FieldException – if the lattice does not have the specified field.
- get_length()[source]#
Returns the length of the lattice, in meters.
- Returns:
The length of the lattice (m).
- Return type:
- add_element(element)[source]#
Append an element to the lattice and update its lattice reference.
- Parameters:
element (Element) – element to append.
- 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:
- Returns:
list containing all elements of the specified family.
- Return type:
- Raises:
ValueError – if there are no elements in the specified cell or family.
- get_all_families()[source]#
Get all families of elements in the lattice.
- Returns:
all defined families.
- Return type:
- get_element_devices(family, field)[source]#
Get devices for 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 a device for fields ‘x’ and ‘y’.
- get_element_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 a device for fields ‘x’ and ‘y’.
- get_element_values(family, field, handle='readback', units='default', data_source='default', throw=True, dtype=None)[source]#
Get the value of the given field for all elements in the given family in the lattice.
- Parameters:
family (str) – family of elements to request the values of.
field (str) – field to request values for.
handle (str) – pytac.RB or pytac.SP.
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, None will be returned for any PV that fails and a warning will be logged.
dtype (numpy.dtype) – if None, return a list. If not None, return a numpy array of the specified type.
- Returns:
The requested values.
- Return type:
list or numpy.array
- set_element_values(family, field, values, units='default', data_source='default', throw=True)[source]#
Set the value of the given field for all elements in the given family in the lattice to the given values.
- Parameters:
family (str) – family of elements on which to set values.
field (str) – field to set values for.
values (sequence) – A list of values to assign.
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 return a list of True and False values corresponding to successes and failures and log a warning for each PV that fails.
- Raises:
IndexError – if the given list of values doesn’t match the number of elements in the family.
- set_default_units(units: str) None [source]#
Sets the default unit type for the lattice and all its elements.
- Parameters:
default_units – The default unit type to be set across the entire lattice, pytac.ENG or pytac.PHYS.
- Raises:
UnitsException – if specified default unit type is not a valid unit type.
- set_default_data_source(data_source_type: str) None [source]#
Sets the default data source for the lattice and all its elements.
- Parameters:
data_source_type – The default data source to be set across the entire lattice, pytac.LIVE or pytac.SIM.
- Raises:
DataSourceException – if specified default data source is not a valid data source.
- get_default_units()[source]#
Get the default unit type, pytac.ENG or pytac.PHYS.
- Returns:
the default unit type for the entire lattice.
- Return type:
- get_default_data_source()[source]#
Get the default data source, pytac.LIVE or pytac.SIM.
- Returns:
the default data source for the entire lattice.
- Return type:
- class pytac.lattice.EpicsLattice(name, epics_cs, symmetry=None)[source]#
EPICS-aware lattice class.
Allows efficient get_element_values() and set_element_values() methods, and adds get_pv_names() method.
Attributes:
- Parameters:
Methods:
- get_pv_name(field, handle)[source]#
Get the PV name for a specific field, and handle on this lattice.
- get_element_pv_names(family, field, handle)[source]#
Get the PV names for the given field, and handle, on all elements in the given family in the lattice.
Assume that the elements are EpicsElements that have the get_pv_name() method.
- get_element_values(family, field, handle='readback', units='default', data_source='default', throw=True, dtype=None)[source]#
Get the value of the given field for all elements in the given family in the lattice.
- Parameters:
family (str) – family of elements to request the values of.
field (str) – field to request values for.
handle (str) – pytac.RB or pytac.SP.
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, None will be returned for any PV that fails and a warning will be logged.
dtype (numpy.dtype) – if None, return a list. If not None, return a numpy array of the specified type.
- Returns:
The requested values.
- Return type:
list or numpy.array
- set_element_values(family, field, values, units='default', data_source='default', throw=True)[source]#
Set the value of the given field for all elements in the given family in the lattice to the given values.
- Parameters:
family (str) – family of elements on which to set values.
field (str) – field to set values for.
values (sequence) – A list of values to assign.
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:
IndexError – if the given list of values doesn’t match the number of elements in the family.