Skip to content

Simple unit convertion to SI on set() #350

Description

@gubaidulinvadim

I think from the discussion https://github.com/orgs/python-accelerator-middle-layer/discussions/49 it follows that the simplest approach is to use SI units in pyAML and to convert to SI on user input using pint.

P.S I would also add that TAURUS (library to built GUIs with TANGO [and EPICS too]) is already using pint.

Original proposal by @JeanLucPons bellow:

It would be very convenient that all get() return SI (expect for eV) value and all set() take SI values as input.
AT works already in SI.

Using SI in PyAML

i.e.

- type: pyaml.bpm.bpm
  name: BPMZ5D1R
  model:
    type: pyaml.bpm.bpm_simple_model
    x_pos_index: 0
    y_pos_index: 1
    x_pos:
      type: pyaml_cs_oa.epicsR
      read_pvname: ORBITCC:rdPos
      unit: nm
      si_unit: m
    y_pos:
      type: pyaml_cs_oa.epicsR
      read_pvname: ORBITCC:rdPos
      unit: nm
      si_unit: m
sr.design.get_bpm("BPMZ5D1R").positions.get() # already SI
sr.live.get_bpm("BPMZ5D1R").positions.get()  # should return values always in [m], conversion to SI should be handle internally using pint
    def get(self) -> float | list[float]:
        """Return the setpoint(s) [or readback(s) when read only variable] of a control system device variable in SI"""
        value = self.signal.read() # Raw value from control system
        Q = value * ureg(self.unit)
        return Q.to(self.si_unit).m  # Will it work like this for arrays using pint ?

How we deal with unit conv in Tango

We have this configuration:
image
Unit is the unit displayed
Display Unit the conversion factor to go from the raw device value to displayed value
Standard Unit is the conversion factor to go from the raw device value to SI
Problem:
We often make errors by sending the value displayed in application to the raw device when we write script.

Originally posted by @JeanLucPons in python-accelerator-middle-layer/governance#49 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions