Questions tagged [pint]

Pint is a Python units library to perform calculations with physical quantities. Use this tag in conjunction with the [python] tag for specific programming questions using Pint.

Pint is Python package to define, operate and manipulate physical quantities: the product of a numerical value and a unit of measurement. It allows arithmetic operations between them and conversions from and to different units.

It is distributed with a comprehensive list of physical units, prefixes and constants. Due to its modular design, you can extend (or even rewrite!) the complete list without changing the source code. It supports a lot of numpy mathematical operations without monkey patching or wrapping numpy.

It has a complete test coverage. It runs in Python 2.6+ and 3.2+ with no other dependency. It licensed under BSD.

Source, more information and latest release:
https://pint.readthedocs.io/

77 questions
1
vote
1 answer

Simplifying units in pint without changing the magnitude

Working with python-pint, let's suppose I have a quantity defined as which is equivalent to kilogram/m3. Now, when I try to get that using to_base_units i get: den.to_base_units()
TomCho
  • 3,204
  • 6
  • 32
  • 83
0
votes
0 answers

How to override predefined unit in pint?

I use the pint library in my lab assignments to efficiently deal with unit specifications and conversions. We recently had an experiment when we took some pictures and in the code, we need to convert from pixels to meters with a conversion factor. I…
Shai Avr
  • 942
  • 8
  • 19
0
votes
0 answers

Can Pint handle complex calculation when defining new Units?

This is the first time I'm creating my own units in the Pint registry. I'm trying to custom define sucrose units. Mostly density. Can Pint handle more complex calculations than just basic math? It's just addition/multiplication, but the…
0
votes
0 answers

Pint Quantity Console Outputs Stuck in Latex Mode

I have been using pint for a little while now. At some point I did something to get fancy outputs in my console, I think from a LaTex printer or something similar. Now I cannot figure out how to revert to more normal "pretty printing" behavior. The…
0
votes
0 answers

Pint support for saving to Parquet, hdf5 and Feather files

Pandas dataframes with Pint dtypes do not appear to be saving to Parquet or Hdf5 format. Is there no support for this, or am I doing this wrong. import pandas as pd import numpy as np import pint,pint_pandas eq =…
kbk78
  • 139
  • 4
0
votes
0 answers

How can I reinterpret a non-multiplicative Unit in a Quantity to its delta variant, regardless of whether it is in a multiplicative context?

The context for this question is that, using pint to parse input from users, I don't want those users to have to worry about delta vs non-delta units. I also know, for each quantity, whether it should be interpreted as a delta or non-delta…
cge
  • 9,552
  • 3
  • 32
  • 51
0
votes
1 answer

Typing and pint

I'm using pint to use and convert units. I wanted to create classes which restricts the quantities only to "[time]" or "[length]" dimensions, so as a first approach I did the following: from pint import Quantity, DimensionalityError class…
JLDiaz
  • 1,248
  • 9
  • 21
0
votes
1 answer

Pint: How to convert units in one dimension, leaving other dimensions unchanged?

I'd like to normalize measurements of different timespans to per-annum: import pint from pint import get_application_registry ureg = get_application_registry() x = ureg('kg/d') print(f"x = {x}") # x = 1.0 kilogram / d print(f"x = {x.to('kg/a')}") #…
Michael Tiemann
  • 251
  • 2
  • 9
0
votes
1 answer

Spectrochempy Unable to Find "pint.unit" -- Module Not Found Error

I am trying to install spectrochempy (https://www.spectrochempy.fr/stable/gettingstarted/install/install_win.html) via conda on Windows 10. I am able to follow the instructions without an error message; it is only when trying to verify the…
Pawel
  • 21
  • 4
0
votes
1 answer

pint-pandas import error ModuleNotFoundError: No module named 'pint.quantity' (pint is imported)

I am trying to use pint-pandas, but it errors on import with a ModuleNotFoundError: No module named 'pint.quantity'. MRE from the pint-pandas github 'basic example' (because it errors on import pint_pandas, i call the version numbers direct) FWIW:…
Robbes
  • 135
  • 8
0
votes
1 answer

Solving simultaneous nonlinear equations with units

I am basically building a general tool for solving for the operating point of a pump in a system - i.e., two equations and two unknowns - pump curve/system curve and head (H) and flowrate (Q). My posted example is not purely MWE, but is grouped in 3…
nate
  • 269
  • 2
  • 11
0
votes
0 answers

Add okta units to a pint registry and handle percent conversion

I have a pint registry that already defines many climate specific units, but I struggle to add a new one for cloud coverage. I would like to add "okta"[0] as a new unit. Oktas are an integer scale from 0 to 9. A conversion from percent to oktas is…
Abel
  • 688
  • 6
  • 19
0
votes
1 answer

How to serialize metpy (pint) units for use with dask distributed?

How can I properly serialize metpy units (based on pint) to work with dask distributed? As far as I understand, it looks like dask distributed automatically pickles data for ease of transfer, but fails to pickle the metpy units which is necessary…
bwc
  • 1,028
  • 7
  • 18
0
votes
1 answer

How are currency units used with Python Pint units?

I would like to do something like this: import pint ureg = pint.UnitRegistry() kg = ureg.kg USD = ureg.USD # not the way to do this weight = 2.3 * kg price = 1.49 * USD / kg cost = weight * price print(f"{cost:~.2f}") >>> 3.43 USD The Pint docs…
0
votes
1 answer

Need to install Python Pint Package using MSYS

I am very new to using MSYS and I need it to run a Fortran based code through python interface. I followed the whole installation procedure in this link https://github.com/SINTEF/thermopack/blob/main/addon/pycThermopack/README.md and when I tried to…