Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Unknown unit "%" (will be treated as unitless) - List of recognized units? #1175

Closed
mariocaptain opened this issue Feb 20, 2021 · 2 comments
Closed
Labels

Comments

@mariocaptain
Copy link

Hi all,
I have been having some hard time displaying attribute units on TaurusForm, with the warnings as below.

MainThread     WARNING  2021-02-20 09:28:46,792 raspberrypi:10000.main/cpu/1.temperature: Unknown unit "oC" (will be treated as unitless)
MainThread     WARNING  2021-02-20 09:28:46,943 raspberrypi:10000.main/cpu/1.cpu_percent: Unknown unit "%" (will be treated as unitless)
MainThread     WARNING  2021-02-20 09:28:47,054 raspberrypi:10000.main/cpu/1.free_ram_percent: Unknown unit "%" (will be treated as unitless)
MainThread     INFO     2021-02-20 09:28:51,875 TaurusRootLogger:

As seen, the issue is that my defined attribute units are not recognized. I am not sure if this is related to tango, pytango or taurus but I have been searching the documentations of all the three for a list of recognized units without success.
Does such a list exist?

Thanks!

@cpascual
Copy link
Member

Taurus uses the pint module to parse and handle units.
See the pint docs for details on syntax for supported units and also on how to define your own units.

From your traces, you are looking for "celsius" and "%".
Note that the support of "%" requires a relatively recent version of pint, and also note that by default it is represented as dimensionless. If you want a better support of percent, you can define it yourself, as in the following snippet:

from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.panel import TaurusForm


import sys
app = TaurusApplication(cmd_line_parser=None)

from taurus.core.units import UR

UR.define('percent = 0.01*count = %')   # <-- defining percent
w = TaurusForm()

w.setModel(["eval:Q(37, 'celsius')", "eval:Q(99, 'percent')"])

w.show()

sys.exit(app.exec_())

which yields:
image

@mariocaptain
Copy link
Author

Thanks so much @cpascual . In the pint module I found a complete list of all units. Also the snippet for displaying "%" works perfectly. Can't thank you enough!
Best,
Dave

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants