90
questions
0
votes
0
answers
5
views
How to use `pint.UnitRegistry.wraps` only if input has arguments with units
I wanted to overwrite wraps from pint.UnitRegistry in order to invoke it only if the user used arguments with units. My attempt is here:
from pint import UnitRegistry, Quantity
ureg = UnitRegistry()
...
0
votes
0
answers
44
views
Pint doesn't recognize my custom defined units
I'm using Pint to handle units for some files that I'm analyzing.
The files contain 10,000ish lines of data for 10 - 100 different variables each. The units of the variables are given in the files, ...
0
votes
1
answer
43
views
Using pint and scipy.integrate.quad
I'm trying to take a finite integral where all of my parameters and limits have units associated with them defined using pint. When I try to take the integral using scipy.integrate.quad I error out (...
0
votes
2
answers
45
views
Convert pint-panda dataframe to numpy
I have a large dataframe (>30 000 rows and > 500 columns), I am using pint to convert from one unit to another using the pint-panda option then I wish to write the dataframe to a text file. I ...
0
votes
1
answer
75
views
What's the difference between Pint's "Quantity" and "PlainQuantity"?
My IDE (type-checking provided by the Pyright language server) doesn't like me passing pint.Quantity instances to functions type-hinted with pint.Quantity:
from pint import Quantity
def get_units(...
0
votes
1
answer
61
views
Parse temperature string in pint
I was trying to parse a string with a temperature and pint fails due to the non-multiplicative nature of the temperature. However, it seems the internal conversion should handle this:
from pint import ...
0
votes
1
answer
32
views
How to convert numpy.timedelta64 to a pint quantity object with a time unit?
I need to convert a power time series (MW) to energy (MWh) by taking the sum:
import pint
import xarray as xr
import pandas as pd
ureg = pint.UnitRegistry()
power_mw = xr.DataArray(
np.random....
1
vote
1
answer
94
views
Python pint convert 1/°Fahrenheit to 1/°Celsius
I use the python package pint and want to calculate e.g. 1 m/°F to m/°C.
from pint import UnitRegistry
ureg = UnitRegistry() #autoconvert_offset_to_baseunit = True
quantity = ureg.Quantity
fromvalue =...
0
votes
0
answers
468
views
How to configure Laravel Pint to use two spaces instead of the tabs
How to configure Laravel Pint to use two spaces instead of the tabs?
I tried multiple stuff in my pint.json file here is the example containing some of them:
{
"preset": "laravel"...
1
vote
0
answers
41
views
How to register a system in pint?
I want to define a system programmitcally. For example, once I define
"real": Units(
mass="g/mol",
distance="angstrom",
time=&...
1
vote
1
answer
188
views
python pint celsius units
I can't define degC as a unit.
After entering
import pint
u=pint.UnitRegistry()
When stating 1*u.degC it outputs 1 degree_Celsius. Seems that it's OK.
When I'm stating 2*u.degC it outputs following ...
1
vote
1
answer
140
views
Setup a conversion rate in pint in python
I have this problem I'd like to solve with python pint.
0.29 points / minutes
118 points / (17.35 usd)
How much is 5 minutes in usd ?
I have then 2 new abstract units "points" and "...
0
votes
0
answers
61
views
Get all matching units from string
I am using pint 0.23 and I faced the following problem.
I have a unit in short format (dat). It can refer to deci-technical_atmosphere or deca-metric_ton. Here is what I do at the moment
>> ...
0
votes
0
answers
39
views
Get unit and not base unit
I am trying to get a more meaningful unit name when converting between unit systems.
In a separate file (custom_en.txt), I have defined a new unit system:
@system Nmm using international
...
0
votes
1
answer
73
views
python pint : Create a "pace" metric from velocity metrics
Using the pint library in python - It has support for unit conversions, which work great.
For example:
units.Quantity(2, "mph").to("kph")
I would like to understand how I could ...
0
votes
1
answer
60
views
Default to a derived unit on output in python pint
Is it possible to default the output if a unit with pint to a derived unit?
For example, if I compute a pressure by dividing a force and area, I would like it to display in "psi" by default.
...
0
votes
0
answers
144
views
How to set field `pint.Quantity._magnitude` of existing object?
Using the pint library, I profiled my code and found a bottleneck is creating new Quantity objects using the constructor like this:
import pint
ureg = pint.UnitRegistry()
...
quantity = pint.Quantity(-...
0
votes
1
answer
136
views
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 ...
1
vote
0
answers
79
views
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'...
2
votes
2
answers
466
views
numpy stack not working for astropy quantities in numpy 1.23
The following works in numpy 1.23.5 but not in 1.24.3:
from astropy import units as u
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
np.stack([a,b]*u.m)
With numpy 1....
1
vote
1
answer
2k
views
How to automatically run Laravel Pint on file save in VSCode?
The Laravel Pint docs specifies that you can run Pint by invoking the binary located in the vendor/bin directory like this:
./vendor/bin/pint
I would like to set this up in VSCode so that it ...
3
votes
1
answer
241
views
Simultaneously handling uncertainties and units in python
I building a python library to analyze data (e.g. spectral data) with units and uncertainties.
For example, we have data on wavelength (nm), counts, and power (W). I want to be able to easily convert ...
1
vote
1
answer
229
views
Difficulty with custom conversion factor using contexts with pint
I am looking to set up a fixed conversion factor between two specific units that cause a DimensionalityError in pint.
I have daily accumulated solar radiation data that is in J/m2 and want to convert ...
1
vote
1
answer
648
views
How with pint to remove empty line in class declaration?
Which property have I to set from
https://github.com/laravel/pint/blob/main/resources/presets/laravel.php
rules to remove empty line in class declaration :
class Classname
{
/** @var int */
...
3
votes
2
answers
1k
views
How with laravel/pint to make keys and values are aligned with spaces on the same level?
In Laravel 9 app using laravel/pint (1.4) with "psr12" preset I prefer to see not code :
\DB::table('quizzes')->insert([
'id' => 2,
'question' => 'What does ORM stand for?',...
2
votes
2
answers
236
views
How can I parse the unit : "g/100mL" using unit-parse in Python?
I'm trying to parse strings in Python, looking for scientific values and units. I want to retrieve them in order to convert them to some other units.
I'm using the library unit-parse (based on pint) ...
0
votes
1
answer
907
views
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 ...
0
votes
1
answer
522
views
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}&...
1
vote
1
answer
1k
views
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 ...
1
vote
1
answer
720
views
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 ...
0
votes
1
answer
68
views
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 ...
1
vote
1
answer
167
views
Python pint objects passed to multiprocessing have different registries than objects created in process
I have an application that requires multiprocessing where pint objects are passed as arguments to the process and pint objects are also created in the process. But these different pint objects have ...
2
votes
1
answer
217
views
How to use transformations in pint package correctly?
I am working on a project involving natural gas and want to be able to convert between volume, mass and energy using provided densities.
I have the following code python, using the pint package:
...
0
votes
1
answer
190
views
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 ...
1
vote
1
answer
700
views
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
...
0
votes
1
answer
53
views
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/...
1
vote
1
answer
837
views
Pint: How do I define my own units in the Pint Python library?
I am working with Pint to do unit conversions in a Python project. The project involves temperature gradients, which are not defined in Pint. My units are typically "deg.C/km" so I'd like ...
1
vote
1
answer
45
views
Dataframe zeros out quantities when a date time is used for an index
Whenever set my DataFrame index to a list of datetime's, the Dataframe zeros out all my quantities.
df = pd.DataFrame(
{
"code": pd.Series(mem_code, dtype="pint[byte]"),...
1
vote
1
answer
411
views
python pint: defined offset unit definition behaves unexpected on conversion
I'm trying to define gauge pressure (barg) as an offset unit using python/pint assuming the predefined unit (bar) refers to absolute pressure. When using the defined unit to set up a quantity in 'barg'...
0
votes
1
answer
263
views
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 ...
0
votes
1
answer
125
views
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 (...
2
votes
1
answer
6k
views
ModuleNotFoundError: No module named 'importlib_metadata' while installing pint in python
I have tried installing pint using pip. But whenever I am trying, I am getting ModuleNotFoundError: No module named 'importlib_metadata'.
Traceback:
ModuleNotFoundError Traceback ...
0
votes
1
answer
282
views
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 ...
3
votes
1
answer
647
views
Standard format for quantity in derived dimension in `pint`
TLDR: I'd like to have pint quantities, that are in a certain (derived) dimension, to be converted into a pre-set unit by default.
Details:
I deal with 5 dimensions, as specified below. Note that [...
0
votes
1
answer
321
views
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 ...
0
votes
2
answers
679
views
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 ...
3
votes
2
answers
728
views
Test for unit equivalence in pint
How do I test for unit equivalence in Pint? For example, nM is equivalent to nmol/L and L is equivalent to dm^3, but they are not equal according to Pint. I don't want compatibility, which Pint ...
1
vote
2
answers
997
views
Python Pint: set short representation of units as default
Pint units are represented by default with their full name:
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> q = ureg.Quantity('3.456 m^2')
>>> print(q)
3.456 ...
3
votes
1
answer
752
views
Parse just unit with pint
The pint docs are clear about how to parse a quantity like "1 meter". How do I parse just a unit, like "meter"? All of these return a quantity with a value of 1:
import pint
ureg = ...
1
vote
1
answer
890
views
Why is Pint creating a second registry?
I keep getting "Cannot operate with Quantity and Quantity of different registries." errors and I cannot figure out why. In the following code snippet, Pint creates one registry used to ...