Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/use_cases/config/bessy2/bessy2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ devices:
response_matrix: ${path:orm.json}
- class: pyaml.rf.rf_plant.RFPlant
name: RF
masterclock: (MCLKHX251C:freq)[KHz]
masterclock: (MCLKHX251C:freq)[kHz]
- class: pyaml.magnet.hcorrector.HCorrector
name: HS4M2D1R
lattice_names: S4M2D1R@0
Expand Down
6 changes: 4 additions & 2 deletions pyaml/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .common.element import Element, __pyaml_repr__
from .common.exception import PyAMLConfigException, PyAMLException
from .common.holders.element_holder import ElementHolder
from .common.units import to_magnitude
from .configuration import ConfigurationManager, UnsupportedConfigurationRootError
from .configuration.factory import Factory
from .control.controlsystem import ControlSystem
Expand Down Expand Up @@ -223,9 +224,10 @@ def set_energy(self, E: float):

Parameters
----------
E : float
Energy value to set in eV
E : float or pint.Quantity
Energy value to set in eV (a quantity is converted to eV)
"""
E = to_magnitude(E, "eV")
self._set_properties("_set_energy", E)
self._energy = E

Expand Down
37 changes: 25 additions & 12 deletions pyaml/arrays/bpm_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyaml.diagnostics.bpm import BPM

from ..common.abstract import ReadFloatArray
from ..common.units import common_unit, per_value_units
from ..control.deviceaccesslist import DeviceAccessList
from .element_array import ElementArray

Expand All @@ -33,7 +34,9 @@ class RWBPMPosition(ReadFloatArray):
get()
Get BPM positions.
unit()
Get the units for BPM positions.
Return the pyAML unit for this quantity, i.e. returned by get().
control_system_unit()
Return the control-system unit for this quantity.
set_aggregator(agg)
Set the device access list aggregator for improved performance.
"""
Expand Down Expand Up @@ -63,16 +66,20 @@ def get(self) -> np.array:
return self.__aggregator.get().reshape(len(self.__bpms), 2)

# Gets the unit of the values
def unit(self) -> list[str]:
def unit(self) -> str | list[list[str]]:
"""
Get the units for BPM positions.
Return the pyAML unit for this quantity, i.e. returned by get().

Returns
-------
list[str]
List of unit strings for each BPM
str or list[list[str]]
Unit label, or one per value (shaped like get()) if they differ.
"""
return [b.positions.unit() for b in self.__bpms]
return common_unit([per_value_units(b.positions.unit(), 2) for b in self.__bpms])

def control_system_unit(self) -> str | list[list[str | None]] | None:
"""Return the control-system unit for this quantity."""
return common_unit([per_value_units(b.positions.control_system_unit(), 2) for b in self.__bpms])

# Set the aggregator (Control system only)
def set_aggregator(self, agg: DeviceAccessList):
Expand Down Expand Up @@ -109,7 +116,9 @@ class RWBPMSinglePosition(ReadFloatArray):
get()
Get single axis BPM positions.
unit()
Get the units for BPM positions.
Return the pyAML unit for this quantity, i.e. returned by get().
control_system_unit()
Return the control-system unit for this quantity.
set_aggregator(agg)
Set the device access list aggregator for improved performance.
"""
Expand Down Expand Up @@ -139,16 +148,20 @@ def get(self) -> np.array:
return self.__aggregator.get()

# Gets the unit of the values
def unit(self) -> list[str]:
def unit(self) -> str | list[str]:
"""
Get the units for BPM positions.
Return the pyAML unit for this quantity, i.e. returned by get().

Returns
-------
list[str]
List of unit strings for each BPM
str or list[str]
Unit label, or one per value if they differ.
"""
return [b.positions.unit() for b in self.__bpms]
return common_unit([per_value_units(b.positions.unit(), 2)[self.__idx] for b in self.__bpms])

def control_system_unit(self) -> str | list[str | None] | None:
"""Return the control-system unit for this quantity."""
return common_unit([per_value_units(b.positions.control_system_unit(), 2)[self.__idx] for b in self.__bpms])

# Set the aggregator (Control system only)
def set_aggregator(self, agg: DeviceAccessList):
Expand Down
34 changes: 22 additions & 12 deletions pyaml/arrays/cfm_magnet_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..common.abstract import ReadWriteFloatArray
from ..common.exception import PyAMLException
from ..common.units import common_unit, per_value_units
from ..magnet.cfm_magnet import CombinedFunctionMagnet
from .element_array import ElementArray

Expand All @@ -34,7 +35,7 @@ class RWMagnetStrengths(ReadWriteFloatArray):
set_and_wait(value)
Set every multipole strength and wait for the readbacks to converge.
unit()
Return the strength unit of every multipole.
Return the pyAML unit for this quantity, i.e. returned by get() and expected by set().
"""

def __init__(self, name: str, magnets: list[CombinedFunctionMagnet]):
Expand Down Expand Up @@ -89,12 +90,12 @@ def set_and_wait(self, value: np.array):
raise NotImplementedError("Not implemented yet.")

# Gets the unit of the values
def unit(self) -> list[str]:
"""Return the strength unit of every multipole."""
r = []
def unit(self) -> str | list[str]:
"""Return the pyAML unit for this quantity, i.e. returned by get() and expected by set()."""
units = []
for m in self.__magnets:
r.extend(m.strengths.unit())
return r
units.extend(per_value_units(m.strengths.unit(), len(m.model.get_strength_units())))
return common_unit(units)


class RWMagnetHardwares(ReadWriteFloatArray):
Expand All @@ -117,7 +118,9 @@ class RWMagnetHardwares(ReadWriteFloatArray):
set_and_wait(value)
Set every hardware value and wait for the readbacks to converge.
unit()
Return the hardware unit of every multipole.
Return the pyAML unit for this quantity, i.e. returned by get() and expected by set().
control_system_unit()
Return the control-system unit for this quantity.
"""

def __init__(self, name: str, magnets: list[CombinedFunctionMagnet]):
Expand Down Expand Up @@ -172,12 +175,19 @@ def set_and_wait(self, value: np.array):
raise NotImplementedError("Not implemented yet.")

# Gets the unit of the values
def unit(self) -> list[str]:
"""Return the hardware unit of every multipole."""
r = []
def unit(self) -> str | list[str]:
"""Return the pyAML unit for this quantity, i.e. returned by get() and expected by set()."""
units = []
for m in self.__magnets:
r.extend(m.hardwares.unit())
return r
units.extend(per_value_units(m.hardwares.unit(), len(m.model.get_hardware_units())))
return common_unit(units)

def control_system_unit(self) -> str | list[str | None] | None:
"""Return the control-system unit for this quantity."""
units = []
for m in self.__magnets:
units.extend(per_value_units(m.hardwares.control_system_unit(), len(m.model.get_hardware_units())))
return common_unit(units)


class CombinedFunctionMagnetArray(ElementArray):
Expand Down
23 changes: 15 additions & 8 deletions pyaml/arrays/magnet_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..common.abstract import ReadWriteFloatArray
from ..common.abstract_aggregator import ScalarAggregator
from ..common.exception import PyAMLException
from ..common.units import common_unit
from ..magnet.magnet import Magnet
from .element_array import ElementArray

Expand Down Expand Up @@ -61,7 +62,7 @@ class RWMagnetStrength(ReadWriteFloatArray):
set_and_wait(value)
Set every strength and wait for the readbacks to converge.
unit()
Return the strength unit of every magnet in the array.
Return the pyAML unit for this quantity, i.e. returned by get() and expected by set().
set_aggregator(agg)
Install an aggregator so the array is read and written in a single call.
"""
Expand Down Expand Up @@ -142,9 +143,9 @@ def set_and_wait(self, value: np.array):
raise NotImplementedError("Not implemented yet.")

# Gets the unit of the values
def unit(self) -> list[str]:
"""Return the strength unit of every magnet in the array."""
return [m.strength.unit() for m in self.__magnets]
def unit(self) -> str | list[str]:
"""Return the pyAML unit for this quantity, i.e. returned by get() and expected by set()."""
return common_unit([m.strength.unit() for m in self.__magnets])

# Set the aggregator (Control system only)
def set_aggregator(self, agg: ScalarAggregator):
Expand Down Expand Up @@ -180,7 +181,9 @@ class RWMagnetHardware(ReadWriteFloatArray):
set_and_wait(value)
Set every hardware value and wait for the readbacks to converge.
unit()
Return the hardware unit of every magnet in the array.
Return the pyAML unit for this quantity, i.e. returned by get() and expected by set().
control_system_unit()
Return the control-system unit for this quantity.
set_aggregator(agg)
Install an aggregator so the array is read and written in a single call.
"""
Expand Down Expand Up @@ -252,9 +255,13 @@ def set_and_wait(self, value: np.array):
raise NotImplementedError("Not implemented yet.")

# Gets the unit of the values
def unit(self) -> list[str]:
"""Return the hardware unit of every magnet in the array."""
return [m.hardware.unit() for m in self.__magnets]
def unit(self) -> str | list[str]:
"""Return the pyAML unit for this quantity, i.e. returned by get() and expected by set()."""
return common_unit([m.hardware.unit() for m in self.__magnets])

def control_system_unit(self) -> str | list[str | None] | None:
"""Return the control-system unit for this quantity."""
return common_unit([m.hardware.control_system_unit() for m in self.__magnets])

# Set the aggregator
def set_aggregator(self, agg: ScalarAggregator):
Expand Down
Loading
Loading