Skip to content

Absolute vs. Relative pressure #1066

Closed
@UniqASL

Description

@UniqASL

Dear all,

I could not find a differentiation between absolute and relative pressures in the list of units proposed by pint. Is this feature already implemented? If not, I think it would make sense to have it, as it is very common to differentiate between these two pressures. One could have units looking like bar_relative and bar_absolute for instance.

Thank you in advance and best regards,

Activity

alexpovel

alexpovel commented on Mar 31, 2020

@alexpovel

Wouldn't you then have to ask, relative to what? 1 bar, 1 atm come to mind.

With temperatures, it is more clear. degC is relative to 273.15 K.

UniqASL

UniqASL commented on Apr 1, 2020

@UniqASL
Author

Thanks for the reply. In English it seems that what I meant is actually called gauge pressure and yes indeed it is relative to atmospheric pressure. And it also seems that in English (in the industry notably) the unit barg or psig, etc. is used to define this gauge pressure and to differentiate from bara or psia (absolute pressure).

dcambie

dcambie commented on Nov 2, 2021

@dcambie

I was also interested in a way to define barg relative to ambient pressure, but ureg.define("barg = 1 * bar; offset: -1") did not work as expected. Ideally 4 barg = 5 bar. No idea why I get 3e-08, it seems also unrelated to pascal

ureg = UnitRegistry()
ureg.autoconvert_offset_to_baseunit = True
Q_ = ureg.Quantity
ureg.define("barg = 1 * bar; offset: -1")
my_pressure = 4 * ureg.barg
my_pressure.to("bar")
Out[5]: 3.0000000000000004e-08 <Unit('bar')>
dalito

dalito commented on Nov 6, 2021

@dalito
Contributor

@dcambie - There you found a nice bug :-).

The factor 1e-8 results two conversions: 1e-5 (from bar to Pa) and 1e-3 (from kg to g). The latter is because pint uses g but not kg internally as default unit for mass. The main problem is that the units of the first quantity are lost in the code path. Then a number (5.0) is converted to Pa. When using pint such a conversion would normally fail because the dimensionality is checked. However, for the internal calculation path pint explicitly deactivated the dimensionality check... (relevant code is all in registry.py).

I'll send a PR with a fix in a few minutes. Note that you should define the unit with a positive offset (my test code):

def test_issue1066(self):
        """Verify calculations with self-defined offset units"""
        ureg = UnitRegistry()
        ureg.define("barga = 1e5 * Pa; offset: 1e5")
        ureg.define("bargb = 1 * bar; offset: 1")
        q_4barg_a = ureg.Quantity(4, ureg.barga)
        q_4barg_b = ureg.Quantity(4, ureg.bargb)
        q_5bar = ureg.Quantity(5, ureg.bar)
        helpers.assert_quantity_equal(q_4barg_a, q_5bar)
        helpers.assert_quantity_equal(q_4barg_b, q_5bar)

dalito

dalito commented on Nov 6, 2021

@dalito
Contributor

In my opinion gauge pressure should be defined by the user. Adding it to the default unit definition file is problematic because of the unclear reference point as @alexpovel wrote above.

Mo-Gul

Mo-Gul commented on Jan 10, 2023

@Mo-Gul

In my opinion gauge pressure should be defined by the user. Adding it to the default unit definition file is problematic because of the unclear reference point as @alexpovel wrote above.

I totally agree. But in reality it is even worse. Because a constant offset is (of course) just an approximation/simplification. At least this is the case when the reference point is the atmospheric pressure, which is changing with time as we all know from the weather forecast 😄

So my question is, how would one implement that "dynamic offset", i.e. I have a table with the ambient (absolute) pressure and the gauge pressure from some sensor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @dcambie@dalito@Mo-Gul@alexpovel@UniqASL

      Issue actions

        Absolute vs. Relative pressure · Issue #1066 · hgrecco/pint