Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behavior when using @ureg.wraps #2030

Open
SchabiDesigns opened this issue Jul 4, 2024 · 1 comment
Open

strange behavior when using @ureg.wraps #2030

SchabiDesigns opened this issue Jul 4, 2024 · 1 comment

Comments

@SchabiDesigns
Copy link

Hi guys,

There is some strange behavior when using @ureg.wraps...
When I use my function without @ureg.wraps result has correct dimension and also intermediate results are correct:

Q_ = ureg.Quantity
def v_2_g(x, amplifier = Q_("10"), sensor = Q_("25 g_0"), sensor_volt = Q_("5 volt"), amplif_volt = Q_("10 volt")):
...

this results in:

sensor		: 10 standard_gravity
sensor_range	: 5 volt
ouput		: 5 volt

without amplifier:
10.0 standard_gravity

with amplifier (10) and same volt range (5 volt):
1.0 standard_gravity

with amplifier (10) and knowing that volt range has been stretched from 5 volt to 10 volt:
0.5 standard_gravity

When I use the @ureg.wraps decorator as follows:

Q_ = ureg.Quantity
@ureg.wraps("standard_gravity", ("volt", None, "standard_gravity", "volt", "volt"))
def v_2_g(output, amplifier = Q_("10"), sensor = Q_("25 g_0"), sensor_volt = Q_("5 volt"), amplif_volt = Q_("10 volt")):
...

this results in:

sensor		: 25
sensor_range	: 5
ouput		: 5

without amplifier:
25.0

with amplifier (10) and same volt range (5):
2.5 dimensionless

with amplifier (10) and knowing that volt range has been stretched from 5 to 10:
1.25 dimensionless

which then throws an DimensionalityError: Cannot convert from 'dimensionless' (dimensionless) to 'standard_gravity'

why suddenly is this dimensionless have been calculated? well it is not wrong since volt/volt results in dimensionless, but it seems @ureg.wraps can not handle that in the end... ???

Python 3.12.0
pip 24.0
Pint 0.24.1

Regards
Schabi

@SchabiDesigns
Copy link
Author

I found a solution. When using None within ureg.wraps the value passed should not be declared as a pint.Quantity without an unit. In my case the function works when I use amplifier = 10 instead of Q_("10")

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

No branches or pull requests

1 participant