Comments (6)
I wonder if it wouldn't make sense to have a flag in the UnitRegistry like rad_as_angle or rad_as_unitless
I like that idea, 1-2 lines of code to change the UnitRegistry would be somewhat easier than copying the definition file and changing that one line and reloading it manually.
from pint import UnitRegistry
ureg = UnitRegistry()
ureg.define('radian = [angle] = rad')
Q_ = ureg.Quantity
a=Q_(1,"rad")
a.dimensionality
<UnitsContainer({})>
Unfortunately ureg.define
doesn't override existing definitions. I can see this being troublesome to change as you'd need to deal with all the definitions that rely on angle too.
An arguement when initialising the registry that creates a default registry with the angle line changed could work well, ie
ureg = UnitRegistry(angle_base_unit=True)
from pint.
np.sin worked when I tried that
from pint.
This was last discussed here, where I also suggested defining angle as a base unit. #1288
We could add something about angle acknowledging it isn't a base unit to https://pint.readthedocs.io/en/stable/user/angular_frequency.html
Could also suggest people try defining angle as you have if behaviour isn't as expected.
from pint.
We could add something about angle acknowledging it isn't a base unit to https://pint.readthedocs.io/en/stable/user/angular_frequency.html
Could also suggest people try defining angle as you have if behaviour isn't as expected.
RE: Documentation
That is interesting, I flipped past that page a dozen times in the last week, and never registered it as the source of my concern.
I might recommend changing the header to Angles and Angular Velocity
RE: angle as a physical definition
I read through the aforementioned ticket quickly, and I must confess that if I saw someone write 1 rad/s == 1 rotation/s I would be greatly confused as 1 rad != 1 rotation, 2pi rad == 1 rotation. But I don't really want to wade into that discussion.
I wonder if it wouldn't make sense to have a flag in the UnitRegistry
like rad_as_angle
or rad_as_unitless
Personally I imagine treating radians as an angle is more common, my 9th grader learned about it this year in discussions of Unit Circles. the need for 1 Hz = 1rad/s (I imagine) is a more specialized need. However, I understand that isn't my decision.
from pint.
I found out that defining [angle]
as a base unit had a drawback
when breaking a velocity out into it's component values I received an exception
# A registry file with the modification -- radian = [angle] = rad
>>> ureg = UnitRegistry('support/pint.default_en.txt')
>>> ang = 75 * ureg.degree
>>> ang.check('[angle]')
True
>>> speed = 30 * ureg.kph
>>> y_speed = speed * math.sin(ang.to('rad'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\264872\bin\VPD3\.venv\Lib\site-packages\pint\facets\plain\quantity.py", line 576, in __float__
raise DimensionalityError(self._units, "dimensionless")
pint.errors.DimensionalityError: Cannot convert from 'radian' to 'dimensionless'
from pint.
Can confirm np.sin
correctly handles the above case, math.sin
does not
from pint.
Related Issues (20)
- Suggested docs addition re: Performance Optimization HOT 1
- Equality concern between kph and km/h HOT 6
- Custom unit systems
- Add functionality to get rid of the si prefixes
- user defined unit prints HOT 2
- f-string not properly printed
- With NumPy Shape (2,2) problem with f-string latex formatting
- Quantity intervals HOT 7
- hvplot support HOT 2
- Conversion to relative units
- `ruff` pre-commit
- Regression in 0.23: assigning NaN arrays to array slices raises DimensionalityError
- np.array raises UnitStrippedWarning when creating array of Quantities HOT 1
- Two test failures in pint/testsuite/benchmarks/test_10_registry.py HOT 1
- Cannot convert from `kcal/mol` to `meV`
- Quantities of different registries can be equal but have different hash HOT 1
- pint is converting delta_degree_Celsius to degree_Fahrenheit
- wraps decorator won't accept quantities converted with to() using V for volts when not uising float as non_int_type HOT 4
- Equality comparison leads to contradictory results HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pint.