Giter Club home page Giter Club logo

Comments (6)

andrewgsavage avatar andrewgsavage commented on June 17, 2024 1

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.

andrewgsavage avatar andrewgsavage commented on June 17, 2024 1

np.sin worked when I tried that

from pint.

andrewgsavage avatar andrewgsavage commented on June 17, 2024

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.

nmadura avatar nmadura commented on June 17, 2024

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.

nmadura avatar nmadura commented on June 17, 2024

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.

nmadura avatar nmadura commented on June 17, 2024

Can confirm np.sin correctly handles the above case, math.sin does not

from pint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.