Repository navigation
Sometimes angle units are dimensionless - new system, more general equivalency? - #1161
Conversation
|
I think this might be worth bringing up on the mailing list. I wonder if rather than worrying about different 'systems' or 'equivalencies' it should be possible to have units of "rad" that are dimensionless and can be freely dropped, but are otherwise included in a quantity until/unless they're dropped. Or maybe |
|
It doesn't appear this generated much interest on the list, so I'll just comment here. I don't really see why it ever makes sense to drop it implicitly - even though an angle is formally dimensionless mathematically, I'm not sure there's any context where it doesn't help to attach the "angle" label to it. Any sort of implicit dropping is bound to get people into trouble, because what might be the "obvious" place to do it for one person will probably seem unnatural to another with a different background. I don't entirely follow the example you gave @mhvk - in particular, I'm not sure what The one case I do see value here is that right now we want np.sin(someanglequantity) to give out a dimensionless quantity, but that will hopefully be addressed in #929 or some related follow-on. |
|
Oh, and regarding the comment on-list about having |
|
@eteq - Yes, it doesn't seem to have been picked up. I also mentioned the issue in #1139 - let me ping @astrofrog, @mdboom, and @iguananaut here, so perhaps they can comment. On the nature of the angle: SI defines radian as a unit derived from dimensionless, so in that sense there is no ambiguity. That said, I do see the advantage of having an About my example: sorry I was not clearer; indeed gives which is all correct. But As it is now, it is not easy to do this elegantly, except by writing explicitly |
|
I'm not really comfortable with having two different systems, so if we decided to make |
|
Ah, I understand the example now @mhvk (the So that leads to the suggestion of having some quick but explicit way of converting between radians and dimensionless units. I'm not a big fan of So I tend towards agreeing with @astrofrog second suggestion that we should just require that users force it to be But I agree with @astrofrog it would be useful to hear what others think of that approach. Oh and one other important detail that just occurred to me: we really do need |
|
@eteq, @astrofrog - I certainly see the arguments in favour of having angle as a real dimension, but it is an explicit decision not to be consistent with the current definition of SI [1]. Do we really want that? Though one can certainly argue we follow good precedent here, as the IAU still lists angles as "supplementary units" [2], which is how SI used to treat them. In any case, it seems we agree there should be an option. My sense is that it should be possible to be consistent with "strict" SI rather than going via
Of the three, I prefer the first option (with [1] http://physics.nist.gov/cuu/Units/units.html |
|
I was actually going to suggest solving this with a built-in equivalency (a la suggestion (2)) above. I think that's probably the cleanest solution and will make everything work. The problem is that the equivalencies don't currently do any factoring, so it won't find the match in the compound unit you gave in your example. I had meant to add that once the |
|
@mdboom - OK, sounds good. Out of curiosity, if one were to implement a strict SI system, how would one actually define a unit derived from the dimensionless one? I tried something probably insensible (certainly didn't work...): I'm slightly puzzled, since I can do |
|
@mhvk: In our system, all units are (logically) derived from dimensionless by default. There isn't really a special token for dimensionless, it's just indicated by the lack of units. Whether that needs to be re-addressed isn't clear -- I'll look into it when I implement a solution to this. |
|
@mdboom - still leaves me a bit confused: I can set |
|
Right. In our system we essentially equate dimensionless with having no unit. And it's the result of dividing any unit by itself (since the units cancel out and we are left with no units). So I believe what you're suggesting is having a dimensionless "unit" from which some other units derive. But that would break the very useful property above, would it not? |
|
To elaborate further, since dimensionless is the special case meaning "having no units", I'm not sure why it's helpful to have units derived from it, other than perhaps having a little syntactic sugar that's completely ignored by the system. Barring a small buglet that can be fixed thusly (see diff below), it is possible to define units in terms of dimensionless, but you don't really gain anything, since any dimensionless unit would than be convertible to any other. The problem with that is illustrated by then deriving |
|
Yes, it would just be syntactic sugar, but with an "SI approved" stamp! Note that the NIST site defines Kidding aside, your change makes sense for The question whether |
|
👍 to @mdboom's solution of using a built-in equivalency. Now that I think about it, that's exactly the whole point of equivalencies! (situations where you want to convert units in special/context-dependent ways.) |
|
I'm assigning myself to this. If I can find a reasonable solution to this in time for 0.3.0, great, otherwise I don't consider it highly urgent. |
|
Agreed it is not hugely urgent, though in the meantime I did encounter another fairly common situation where it would help if radian was equivalent to dimensionless: (and likely other examples with complex numbers). |
|
@mdboom - I made a trial implementation. It is somewhat ugly, since really this is not quite the same as a normal equivalency, in that I'd want all powers of radian to be converted, independent of whether it is part of a more complex unit. For equivalencies like Ideally, I'd like this to be an option to the user, i.e., they can set somewhere at the top of the script whether they want this to be the case. I now wrote this as an attribute to Since it is a bit of a weird equivalency, I also tried to write a PR where this is by option only; see https://github.com/mhvk/astropy/tree/units-radian-is-unity-decompose Anyway, with this, I can now do: which yields |
|
Yeah -- it's a bit hackish, but I see why it has to be the way it is. I think I'm okay with this. |
|
This will need some tests before merging. |
|
@mdboom - OK, I can write some tests. What I'd like your opinion on, however, is how to set this script/context wide. If that is not immediately obvious, perhaps I'll cut the current lines that do: and we can do a separate PR on that. |
|
Well, there's at least three choices here:
|
|
I feel somewhat strongly about being able to use "true SI" in Quantities/Units without having to add the equivalency everytime the quantity is initialised or converted. Do you think your context manager for imperial units be repurposed for this? I.e., something like or Though perhaps I should not think of repurposing. Would it be easy to add something like: (this may also be an alternative to storing equivalencies in quantities...) |
|
Your last suggestion is pretty close to what I meant by my option (1) above, but I'm still not crazy about introducing more global state. |
|
@astrofrog - it appears the travis failure to build sphinx is due to modeling? At least, assuming it is due to the |
|
@astrofrog, I raised an issue about what the warning I saw, though I'm no longer sure it is related, as I also saw it in #1593. The latter also has other problems, so I'll at least fix those. |
|
Yay! it is in good standing again. I think this is ready to be merged; @mdboom, @astrofrog? |
|
This seems fine to me, but I think that |
|
@astrofrog - I actually had that initially, as I agree it reads better. The main reason I changed is that I use An alternative would be to go back to |
|
I can see your point about interactive usage, but really, I don't think that should determine the wording, otherwise as time goes on we'll add convoluted terminology just so that it tab completes well ;) I personally think |
Also rename equivalency to angles_dimensionless
This since objects can no longer be initialised with equivalencies
|
@astrofrog - OK, it is back to |
|
This looks ready to merge. However (and apologies for this), we seem to be working on top of each other a bit today 😉. In light of #1662, do you think you could rebase this on #1662 and make the analogous changes so there's no |
|
Finally, it seems all is set here. |
|
I think I can take care of the rebase... hold on... |
|
Merged (manually) |
Angle units are formally dimensionless (or more precisely, in SI at least radians are a derived unit), and while for clarity it is definitely good not to always treat them as such, sometimes it would be handy. E.g., suppose I have defined
Omega = 2.*np.pi*u.rad/P, then I'm all set up to dophase=Omega*t, but I get a unit exception if I tryWould it be possible to, sometimes, tell that one just wants to use
rad=1? It seems equivalencies are rather cumbursome for this, but are there other solutions? Perhaps ansi_rad_is_dimensionlesssystem? Or ato_system(rad=1)?(Note, there is some relation to my thinking on having a
u.pi-- #1160 -- which is useful when one is thinking of orbital phases.)