Repository navigation
Introduce units.cycle (2 pi radians) [note: initially considered u.pi] - #1160
Conversation
|
I'm not sure how I feel about this. In principle I like the idea, but in practice it leads to some kind of odd results. Like what if you have unless maybe you defined some sort of equivalency. I think it almost makes more sense to define pi as a constant, but even then I'd leave it unitless; I don't think pi naturally has "units" of radians. |
|
I think if one uses u.pi, the above behaviour would be expected, i.e., one should not do I did also consider putting pi under constants, but I think that is even more likely to lead to confusion (like you, I concluded it would have to be dimensionless, which beats the point). Under units, my sense was that it hurts no-one, but provides some convenience. |
|
Added yields |
|
I'm a little concerned about the potential for confusion between I do like So I would be in favor of dropping the |
|
No reason dimensionless quantities can't be in constants. I think we have several dimensionless constants already (fine-structure comes to mind). |
|
Huh. Turns out we don't have the fine-structure constant, actually. There are several others I think we need to add but that's a separate issue. This issue of having pi in expressions does bring up an interesting point regarding constants in general though. Since Astropy defines constants as a subclass of It's possible that the combined units of all constants in a quantity could still be displayed which would definitely help with bookkeeping: Something like that. Having behavior like this would be ideal for This would all be really great to see but it would take a bit of work to overhaul what we already have and to get it right. It's also getting dangerously close to being a symbolic manipulation system and reinventing at least parts of SymPy's wheel. |
|
With Returning to this request, the right thing may be @eteq's suggestion of having |
|
@mhvk - actually, you can just update this PR by removing the I would say the aliases shouldn't include |
(rather than si.py, since cycle is a non-SI unit recognised for use in astronomy: http://www.iau.org/science/publications/proceedings_rules/units/)
|
@eteq - OK, I changed the pull request (unfortunately, I messed up and hence decided to rebase). I added |
|
When #1006 is merged, this will mean that Angle classes will also grow a |
|
@mdboom - agree that being able to do |
|
This looks great to me in terms of functionality, @mhvk - I totally agree Perhaps you can also add a quick test that exercises this? (Maybe just something that does |
|
@eteq - OK, test added. |
|
Looks great - merging! Thanks @mhvk |
Introduce units.cycle (2 pi radians)
This may be silly (@wkerzendorf certainly thought so...), but to me it made sense to introduce
u.pi, so that one can do things like:This example would be for eventual passing to functions, e.g.,
np.cos(phase). This will be particularly useful if trigonometric functions insist on quanties with angle units (which I think they should). The one disconcerting thing is the units ofconstants.h/(2*u.pi)would not match those ofconstants.hbar, but a similar inconsistency exists now, where people who write2*np.pi*t/phave to realise thenp.picarries a unit here, which they need to add.Overall, my sense was that there was no harm done in adding
u.pi, and I personally would like the convenience.