API#
pytac.cs module#
Class representing an abstract control system.
- class pytac.cs.ControlSystem[source]#
Bases:
object
Abstract base class representing a control system.
A specialised implementation of this class would be used to communicate over channel access with the hardware in the ring.
Methods:
- get_single(pv, throw)[source]#
Get the value of a given PV.
- Parameters:
pv (string) – PV to get the value of. readback or a setpoint PV.
throw (bool) – On failure: if True, raise ControlSystemException; if False, return None and log a warning.
- Returns:
the current value of the given PV.
- Return type:
- Raises:
ControlSystemException – if it cannot connect to the specified PVs.
- get_multiple(pvs, throw)[source]#
Get the value for given PVs.
- Parameters:
pvs (sequence) – PVs to get values of.
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.
- Returns:
the current values of the PVs.
- Return type:
- Raises:
ControlSystemException – if it cannot connect to the specified PV.
- set_single(pv, value, throw)[source]#
Set the value of a given PV.
- Parameters:
- Raises:
ControlSystemException – if it cannot connect to the specified PV.
- set_multiple(pvs, values, throw)[source]#
Set the values for given PVs.
- Parameters:
pvs (sequence) – PVs to set the values of.
values (sequence) – values to set no the PVs.
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:
ValueError – if the PVs or values are not passed in as sequences or if they have different lengths
ControlSystemException – if it cannot connect to one or more PVs.
pytac.data_source module#
Module containing pytac data source classes.
- class pytac.data_source.DataSource[source]#
Bases:
object
Abstract base class for element or lattice data sources.
Typically an instance would represent hardware via a control system, or a simulation.
Attributes:
Methods:
- get_fields()[source]#
Get all the fields represented by this data source.
- Returns:
all fields.
- Return type:
iterable
- class pytac.data_source.DataSourceManager[source]#
Bases:
object
Class that manages all the data sources and UnitConv objects associated with a lattice or element.
It receives requests from a lattice or element object and directs them to the correct data source. The unit conversion objects for all fields are also held here.
- default_units#
Holds the current default unit type, pytac.PHYS or pytac.ENG, for an element or lattice.
- Type:
- default_data_source#
Holds the current default data source, pytac.LIVE or pytac.SIM, for an element or lattice.
- Type:
Methods:
- set_data_source(data_source, data_source_type)[source]#
Add a data source to the manager.
- Parameters:
data_source (DataSource) – the data source to be set.
data_source_type (str) – the type of the data source being set pytac.LIVE or pytac.SIM.
- get_data_source(data_source_type)[source]#
Get a data source.
- Parameters:
data_source_type (str) – the type of the data source being set pytac.LIVE or pytac.SIM.
- Raises:
DataSourceException – if there is no data source on the given field.
- get_fields()[source]#
Get all the fields defined on the manager.
Includes all fields defined by all data sources.
- Returns:
- A dictionary of all the fields defined on the manager,
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 manager.
- 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: str, handle: str = 'readback', units: str = 'default', data_source_type: str = 'default', throw: bool = True) float [source]#
Get the value for a field.
Returns the value of a field on the manager. 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. If handle, units or data_source are not given then the lattice default values are used.
- Parameters:
field – The requested field.
handle – pytac.SP or pytac.RB.
units – pytac.ENG or pytac.PHYS returned.
data_source – pytac.LIVE or pytac.SIM.
throw – On failure: if True, raise ControlSystemException; if False, return None and log a warning.
- Returns:
The value of the requested field
- Raises:
DataSourceException – if there is no data source on the given field.
FieldException – if the manager does not have the specified field.
- set_value(field: str, value: float, units: str = 'default', data_source_type: str = 'default', throw: bool = True) None [source]#
Set the value for a field.
This sets a value on the machine or the simulation. If handle,units or data_source are not given then the lattice default values are used.
- Parameters:
field – The requested field.
value – The value to set.
units – pytac.ENG or pytac.PHYS.
data_source_type – pytac.LIVE or pytac.SIM.
throw – On failure: if True, raise ControlSystemException: if False, log a warning.
- Raises:
HandleException – if the specified handle is not pytac.SP.
DataSourceException – if arguments are incorrect.
FieldException – if the manager does not have the specified field.
- class pytac.data_source.DeviceDataSource[source]#
Bases:
DataSource
Data source containing control system devices.
Attributes:
Methods:
- get_device(field)[source]#
Get device from the data_source.
- Parameters:
field (str) – field of the requested device.
- Returns:
The device of the specified field.
- Return type:
- Raises:
FieldException – if the specified field doesn’t exist on this data source.
- get_fields()[source]#
Get all the fields from the data_source.
- Returns:
list of strings of all the fields of the data_source.
- Return type:
- get_value(field, handle, throw=True)[source]#
Get the value of a readback or setpoint PV for a field from the data_source.
- Parameters:
- Returns:
The value of the PV.
- Return type:
- Raises:
FieldException – if the device does not have the specified field.
- set_value(field, value, throw=True)[source]#
Set the value of a readback or setpoint PV for a field from the data_source.
- Parameters:
- Raises:
FieldException – if the device does not have the specified field.
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[source]#
Bases:
object
A representation of a property of an element associated with a field.
Typically a control system will be used to set and get values on a device.
Methods:
- class pytac.device.SimpleDevice(value: float | List[float], enabled: bool = True, readonly: bool = True)[source]#
Bases:
Device
A basic implementation of the device class.
This device does not have a PV associated with it, nor does it interact with a simulator. In short this device acts as simple storage for data that rarely changes, as it is not affected by changes to other aspects of the accelerator.
- Parameters:
value – can be a number or a list of numbers.
enabled – whether the device is enabled. May be a PvEnabler object.
readonly – whether the value may be changed.
- is_enabled()[source]#
Whether the device is enabled.
- Returns:
whether the device is enabled.
- Return type:
- class pytac.device.EpicsDevice(name, cs, enabled=True, rb_pv=None, sp_pv=None)[source]#
Bases:
Device
An EPICS-aware device.
Contains a control system, readback and setpoint PVs. A readback or setpoint PV is required when creating an epics device otherwise a DataSourceException is raised. The device is enabled by default.
Attributes:
- Parameters:
name (str) – The prefix of EPICS PV for this device.
cs (ControlSystem) – The control system object used to get and set the value of a PV.
enabled (bool-like) – Whether the device is enabled. May be a PvEnabler object.
rb_pv (str) – The EPICS readback PV.
sp_pv (str) – The EPICS setpoint PV.
- Raises:
DataSourceException – if no PVs are provided.
Methods:
- is_enabled()[source]#
Whether the device is enabled.
- Returns:
whether the device is enabled.
- Return type:
- get_value(handle, throw=True)[source]#
Read the value of a readback or setpoint PV.
- Parameters:
- Returns:
The value of the PV.
- Return type:
- Raises:
HandleException – if the requested PV doesn’t exist.
- set_value(value, throw=True)[source]#
Set the device value.
- Parameters:
- Raises:
HandleException – if no setpoint PV exists.
- get_pv_name(handle)[source]#
Get the PV name for the specified handle.
- Parameters:
handle (str) – The readback or setpoint handle to be returned.
- Returns:
A readback or setpoint PV.
- Return type:
- Raises:
HandleException – if the PV doesn’t exist.
- class pytac.device.PvEnabler(pv, enabled_value, cs)[source]#
Bases:
object
A PvEnabler class to check whether a device is enabled.
The class will behave like True if the PV value equals enabled_value, and False otherwise.
- Parameters:
pv (str) – The PV name.
enabled_value (str) – The value for PV for which the device should be considered enabled.
cs (ControlSystem) – The control system object.
Methods:
pytac.element module#
Module containing the element class.
- class pytac.element.Element(length, element_type, name=None, lattice=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 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:
- Parameters:
Methods:
- 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:
- 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:
- 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 an element.
- 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.
- 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:
- Returns:
The value of the requested field
- Return type:
- Raises:
DataSourceException – if there is no data source on the given field.
FieldException – if the element 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 element does not have the specified field.
- class pytac.element.EpicsElement(length, element_type, name=None, lattice=None)[source]#
Bases:
Element
EPICS-aware element.
Adds get_pv_name() method.
Methods:
- Parameters:
Methods:
- get_pv_name(field, handle)[source]#
Get PV name for the specified field and handle.
- Parameters:
- Returns:
The readback or setpoint PV for the specified field.
- Return type:
- Raises:
DataSourceException – if there is no data source for this field.
FieldException – if the specified field doesn’t exist.
pytac.exceptions module#
Module containing all the exceptions used in pytac.
- exception pytac.exceptions.FieldException[source]#
Bases:
Exception
Exception associated with invalid field requests.
- exception pytac.exceptions.HandleException[source]#
Bases:
Exception
Exception associated with requests with invalid handles.
pytac.lattice module#
Representation of a lattice object which contains all the elements of the machine.
- class pytac.lattice.Lattice(name: str, symmetry: int | None = None)[source]#
Bases:
object
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]#
Bases:
Lattice
EPICS-aware lattice class.
Allows efficient get_element_values() and set_element_values() methods, and adds get_pv_names() method.
Attributes:
- Parameters:
name (str) – The name of the epics lattice.
epics_cs (ControlSystem) – The control system used to store the values on a PV.
symmetry (int) – The symmetry of the lattice (the number of cells).
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.
pytac.load_csv module#
Module to load the elements of the machine from csv files.
The csv files are stored in one directory with specified names:
elements.csv
devices.csv
families.csv
unitconv.csv
uc_poly_data.csv
uc_pchip_data.csv
- pytac.load_csv.csv_loader(csv_file: Path) Iterator[DictReader] [source]#
- pytac.load_csv.load_poly_unitconv(filepath: Path) Dict[int, PolyUnitConv] [source]#
Load polynomial unit conversions from a csv file.
- Parameters:
filepath – The file from which to load.
- Returns:
A dictionary of the unit conversions.
- Return type:
- pytac.load_csv.load_pchip_unitconv(filepath: Path) Dict[int, PchipUnitConv] [source]#
Load pchip unit conversions from a csv file.
- Parameters:
filename – The file from which to load.
- Returns:
A dictionary of the unit conversions.
- Return type:
- pytac.load_csv.resolve_unitconv(uc_params: Dict, unitconvs: Dict, polyconv_file: Path, pchipconv_file: Path) UnitConv [source]#
Create a unit conversion object based on the dictionary of parameters passed.
- Parameters:
uc_params (Dict) – A dictionary of parameters specifying the unit conversion object’s properties.
unitconvs (Dict) – A dictionary of all loaded unit conversion objects.
polyconv_file (Path) – The path to the .csv file from which all PolyUnitConv objects are loaded.
pchipconv_file (Path) – The path to the .csv file from which all PchipUnitConv objects are loaded.
- Returns:
The unit conversion object as specified by uc_params.
- Return type:
- Raises:
UnitsException – if the “uc_id” given in uc_params isn’t in the unitconvs Dict.
- pytac.load_csv.load_unitconv(mode_dir: Path, lattice: Lattice) None [source]#
Load the unit conversion objects from a file.
- Parameters:
mode_dir – Path to directory containing CSV files.
lattice – The lattice object that will be used.
- pytac.load_csv.load(mode, control_system=None, directory=None, symmetry=None) EpicsLattice [source]#
Load the elements of a lattice from a directory.
- Parameters:
mode (str) – 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 (str) – Directory where to load the files from. If no directory is given the data directory at the root of the repository is used.
symmetry (int) – The symmetry of the lattice (the number of cells).
- Returns:
The lattice containing all elements.
- Return type:
- Raises:
ControlSystemException – if the default control system, cothread, is not installed.
pytac.units module#
Classes for use in unit conversion.
- pytac.units.unit_function(value)[source]#
Default value for the pre and post functions used in unit conversion.
- class pytac.units.UnitConv(post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Bases:
object
Class to convert between physics and engineering units.
This class does not do conversion but does return values if the target units are the same as the provided units. Subclasses should implement _raw_eng_to_phys() and _raw_phys_to_eng() in order to provide complete unit conversion.
The two arguments to this function represent functions that are applied to the result of the initial conversion. One happens after the conversion, the other happens before the conversion back.
Attributes:
- Parameters:
post_eng_to_phys (function) – Function to be applied after the initial conversion.
pre_phys_to_eng (function) – Function to be applied before the initial conversion.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
Methods:
- set_post_eng_to_phys(post_eng_to_phys)[source]#
Set the function to be applied after the initial conversion.
- Parameters:
post_eng_to_phys (function) – Function to be applied after the initial conversion.
- set_pre_phys_to_eng(pre_phys_to_eng)[source]#
Set the function to be applied before the initial conversion.
- Parameters:
pre_phys_to_eng (function) – Function to be applied before the initial conversion.
- eng_to_phys(value)[source]#
Function that does the unit conversion.
Conversion from engineering to physics units. An additional function may be cast on the initial conversion.
- Parameters:
value (float) – Value to be converted from engineering to physics units.
- Returns:
The result value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- phys_to_eng(value)[source]#
Function that does the unit conversion.
Conversion from physics to engineering units. An additional function may be cast on the initial conversion.
- Parameters:
value (float) – Value to be converted from physics to engineering units.
- Returns:
The result value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- convert(value, origin, target)[source]#
Convert between two different unit types and check the validity of the result.
- Parameters:
- Returns:
The resulting value.
- Return type:
- Raises:
UnitsException – If the conversion is invalid; i.e. if there are no solutions, or multiple, within conversion limits.
- class pytac.units.PolyUnitConv(coef, post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Bases:
UnitConv
Linear interpolation for converting between physics and engineering units.
Attributes:
- p#
A one-dimensional polynomial of coefficients.
- Type:
poly1d
- Parameters:
coef (array-like) – The polynomial’s coefficients, in decreasing powers.
post_eng_to_phys (float) – The value after conversion between ENG and PHYS.
pre_eng_to_phys (float) – The value before conversion.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
- class pytac.units.PchipUnitConv(x, y, post_eng_to_phys=<function unit_function>, pre_phys_to_eng=<function unit_function>, engineering_units='', physics_units='', name=None)[source]#
Bases:
UnitConv
Piecewise Cubic Hermite Interpolating Polynomial unit conversion.
Attributes:
- x#
A list of points on the x axis. These must be in increasing order for the interpolation to work. Otherwise, a ValueError is raised.
- Type:
- y#
A list of points on the y axis. These must be in increasing or decreasing order. Otherwise, a ValueError is raised.
- Type:
- pp#
A pchip one-dimensional monotonic cubic interpolation of points on both x and y axes.
- Type:
PchipInterpolator
- Parameters:
x (list) – A list of points on the x axis. These must be in increasing order for the interpolation to work. Otherwise, a ValueError is raised.
y (list) – A list of points on the y axis. These must be in increasing or decreasing order. Otherwise, a ValueError is raised.
engineering_units (str) – The unit type of the post conversion engineering value.
physics_units (str) – The unit type of the post conversion physics value.
name (str) – An identifier for the unit conversion object.
- Raises:
ValueError – if coefficients are not appropriately monotonic.
pytac.utils module#
Utility functions.
- pytac.utils.get_div_rigidity(energy)[source]#
- Parameters:
energy (int) – the energy of the lattice.
- Returns:
div rigidity.
- Return type:
function
- pytac.utils.get_mult_rigidity(energy)[source]#
- Parameters:
energy (int) – the energy of the lattice.
- Returns:
mult rigidity.
- Return type:
function
This is the internal API reference for pytac
- pytac.__version__: str#
Version number as calculated by pypa/setuptools_scm