-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Distance to quantity #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distance to quantity #794
Conversation
astropy/coordinates/distances.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be checking that the quantity's unit is in fact a length? (i.e. is_equivalent(u.m)?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, definitely, good point! Will send up a fix for this shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, no it's in there already, just further down - see line 101.
I'll add a test for it, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh -- great!
|
Given that #793 was merged by not addressing what's here, I suppose we should revisit @astrofrog's comments: he brought up a concern that this adds functionality to I think this is not a problem. The point of having a Once this is resolved, I also plan to add support for distance modulii in a similar way to how |
|
Oh, and @mdboom @adrn - do you have any opinions on @astrofrog's concerns here? |
|
I'd say drop the special accessors... |
|
Another thought occurred to me in the on-list discussion of |
|
Just throwing out another crazy idea here...and this really is crazy, but here it goes. We could also standardize single-unit This would require some restructuring or namespace hacking... |
|
It is a crazy idea, but I actually like it. I'd want to think about how best to implement it. I wouldn't want to just slap a |
|
I've been feeling like Units really need a closer tie to the physical units that they represent (even for compound units). Then it would be much faster to generate a list of equivalencies because there would just be a registry of all 'length' units and such. That said, that may be easy enough for things like length, time, and mass. But I could see it getting hairy pretty quickly--it's a pre-baked idea. |
|
I also like @adrn's "crazy" idea. Then we could put the extra things like @mdboom - perhaps the thing is to generate the cache in Another question, though: would |
|
I'm just thinking this through, but I think I prefer these new "magical" properties to return the value of the quantity in the requested unit. In that sense, I think of Thinking through this further, I was concerned about the lack of equivalency support in this interface. But I think there are some obvious places where we would want it to be "automatic", and in other cases, the user will just have to use If there's agreement that this would be nice, I can go ahead and work up a PR for @adrn's idea. |
|
👍 to these properties returning values |
|
I like it! I thought about this a bit and I agree with @mdboom on returning values. |
|
👍 to @mdboom's idea from me. Lets leave this PR open until that is implemented then, and I can rebase this once that's done to remove the "special" accessors that will become redundant. Regarding equivalencies, it's been on my to-do list to add an option to |
|
@eteq: #837, which adds conversions as attributes on |
|
Ah, great, guess I'll remove it from my todo list, then! |
Quantity that allow the user to easily convert to other units. This involved add a more complex UnitRegistry class, that also keeps a dictionary of all registered units sorted by their physical type. From this new registry, a `compose` can also limit the set of units that it needs to search through for a match, making it faster, so this PR has the added bonus of being a performance improvement.
|
@mdboom and/or @astrofrog - I'm trying to pick out the parts of #1006 that need to be "translated" here - it looks to me like the methods that need to be overridden are |
|
@eteq: Yes. You may not need to do array_wrap if you don't need to add any extra attributes. The |
|
I'm going to just close this and open a new one, because it's completely different. |
(Note that this is based on #793, so only the last commit is unique to this PR)
This makes the change of converting
Distanceobjects incoordinatesto subclass fromQuantity. They already use the same internal naming scheme (_valueand_unit), so no substansive changes are needed. As @astrofrog mentions in #793, though, this does meanDistancepicks up the methods fromQuantity.An alternative approach (which wouldn't actually be that much more work) would be to drop the
Distanceclass completely, and just require aQuantitythat is a length. I'm mildly against this, because the current API is slightly more convenient -d.kpcis easier thand.to('kpc').value. Also, with aDistanceclass, we can have the initializer that allows providing az, and hopefully in the near future,distmod(and similar acessors). With a rawQuantitythat's not possible.