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
0
votes
1 answer

pint: electron_volt as base unit

Is there any way to have the composed unit eV as a base unit in pint using a straight forward combination of @system, @group and possibly some contextual conversions in a definition file? What I want to achieve is something like import pint ureg =…
red-isso
  • 305
  • 1
  • 7
0
votes
1 answer

pint: Is wrapping built-in functions with ureg.wraps() impossible?

I'm trying to wrap time.sleep: from time import sleep from pint import UnitRegistry ureg = UnitRegistry() ureg.wraps(None, ureg.seconds)(sleep) However, this code throws a ValueError: Traceback (most recent call last): File "demo.py", line 5, in…
Sören
  • 1,803
  • 2
  • 16
  • 23
0
votes
1 answer

KeyError with custom derived quantity

I have defined a new derived dimension with [molar_energy] = [energy] / [substance] However, if I do the following it complains: >>> UR.get_compatible_units('[molar_energy]') Traceback (most recent call last): File "", line 1, in
Rufus
  • 15
  • 2
  • 8
0
votes
1 answer

In `pint`, set per-unit `default_format`

Basically the title. In pint, is there a way to define the default string formatting per dimension or per unit, instead of 'across the board'? Stated more precisely: I want to format a quantity's numerical value (i.e., magnitude), based on its…
ElRudi
  • 2,122
  • 2
  • 18
  • 33
0
votes
2 answers

pint: convert geographic CRS degrees to nautical miles

I would like to use pint to convert degrees (distance in a geographic CRS) into nautical miles. https://geopandas.org/docs/reference/api/geopandas.GeoDataFrame.sjoin_nearest.html outputs distance in degree for epsg:4326. Given distance (in nm)…
Ray Bell
  • 1,508
  • 4
  • 18
  • 45
0
votes
1 answer

How to print python Pint quantities and its meaning

I am very new to python and python pint. I just want to know the supportable units of python pint. Also what is the meaning of the below representation: {length: 1, time: -1} Reference from pint unit. Also how do I print the available pint units…
june alex
  • 244
  • 4
  • 17
0
votes
0 answers

Does anyone know a better way to evaluate dimension of the formula in python?

Now, I have a formula with some symbols. These symbols have units. Does anyone know a python library to evaluate the dimension of the formula. I checked sympy and pint. Sympy seems to be based on the unit system of physics, but what I want to deal…
0
votes
1 answer

How can you define a 2-D Quantity Array in Python with different units in each dimension

I want to define an array containing fuel consumption data for a genset. The x-axis will have units of 'kW' and the y-axis 'gal/hr'. Is there a way to create a Numpy compatible Quantity Array with Pint or a similar library that has different…
Darko
  • 589
  • 1
  • 7
  • 18
0
votes
1 answer

Dealing with an error without defining what the correct answer is

I'd like to deal with an input error without defining what the success criteria is i.e. only loop back round the user input turns out to be incorrect. All of the examples I can find require a definition of success. Rather than list all the possible…
KennyMcK
  • 35
  • 4
0
votes
0 answers

Pint list conversion

I have a very long list I'm trying to convert as fast as possible. Currently I'm doing the following which is very fast compared to a 1 by 1 conversion: alist = [1,2,3,4, ... 100000] list_with_unit = alist * ureg('meter') list_converted =…
Francesco Meli
  • 2,484
  • 2
  • 21
  • 52
0
votes
1 answer

How to convert between frequency and period in Pint?

I would like to be able to convert between frequency values and period values. These are not directly convertible since they are not exactly the same unit, but I read that there are predefined relationships between units called Contexts. However, I…
mlg556
  • 419
  • 3
  • 13
0
votes
0 answers

pint: Magnitude of a numpy array

I am trying to print a numpy array without its units. I have done this succesfully if a quantity is a float (e. g. 3 *ureg.milliampere). On the other hand, in case of an array, I cannot have the array returned . Does anybody know how to to return…
kostas
  • 101
  • 12
0
votes
1 answer

Volume to Mass transformation not recognized in pint

I am trying to use pint in a situation where I need to do transformations between dimensions, eg. fluid ounces to grams. The values I need for my transformation are in a database and change for various substances (eg. different densities for…
little_birdie
  • 5,600
  • 3
  • 23
  • 28
0
votes
1 answer

pint's usage with numpy's concatenate

I have this toy example where I am using pint and numpy - import numpy as np from pint import UnitRegistry ureg = UnitRegistry() Q_ = ureg.Quantity args = [] for k in range(0,17): uwnd = Q_(np.ones((1,73,144)),'meter / second') …
gansub
  • 1,164
  • 3
  • 20
  • 47
0
votes
1 answer

Why do pint Quantities display differently in QtConsole than in an iPython console and how do I change it?

So, I use the pint units package and would like values displayed in the console to be standard fixed width font, not a 'rendered' display. I use Spyder IDE which uses QtConsole and displays either html or latex png. The following screen shots…
mrclary
  • 489
  • 3
  • 16