Repository navigation
Consider whether bounds are needed as part of the Angle class. - #1310
Conversation
|
As discussed in #1006, there are problems that arise when the An example problem is the Haversine distance, which performs a subtraction of For truly circular angles the bounds specify where to wrap. This can be useful, but can lead to problems for expressions like Without wrapping or exceptions, then the bounds are not really doing much as far as I can tell. |
|
I would argue that for subtraction, the result should no longer have any bounds for the reason you mention, so if we want to keep bounds, we certainly have to improve the rules on when they are kept and when they are removed. |
|
Subtraction is just another name for addition |
|
I think this defeats the purpose of bounds. They should not be silently dropped. |
@demitri - Do you have any suggestion for handling the issues that I mentioned? |
|
@taldcroft Right now, no. I'd have to sit down and analyze the problem rather than answering off the cuff. I'd say disable the operations under question for the moment. My main guiding thoughts:
I think this would be worth presenting as a discussion on the astopy list. |
|
Disabling basic arithmetic and ufunc operations would certainly spoil the joy of having merged #1006, which was a lot of work! Here is what we currently get, which I find unacceptable (and will open an issue soon): |
|
@taldcroft This is what I mean about |
|
@taldcroft, @demitri - Just read the discussion in #1006 and here. My feeling is that the bounds in To me, this suggests bounds checking should not be part of (1) In (2) Bounds checking becomes part of the As I think @astrofrog mentioned, in practice we may be beating a dead horse, as for use in coordinates one does not really need to use angles directly at all. But I do see some use outside of coordinates, mostly as a neat way to represent/parse angle quantities; for those, however, I think bound checking just confuses things. |
|
@mhvk - I agree that bounds (as a property that either enforces limits or does auto-wrapping) should be dropped from If I understand correctly, your option (1) would mean that for a That leaves option (2), which seems good to me. I personally don't see a real need for The Just quickly brainstorming I was thinking I was thinking about a Without a |
|
@taldcroft - Indeed, the coordinates class would be composed of a As for bounds, it would seem that one could use the existing mechanism in the longitude/latitude classes (or the equivalent inside coordinates). As for |
|
It seems to me that no one is really treating the @taldcroft The idea of a |
|
@demitri - I entirely agree that It happens that our main use case for
Just looking at the actual code for [1] Kenneth Rietz at PyCon: "My favorite pull requests are ones that delete code". |
|
As a proof of concept I just spend 15 minutes hacking As an immediate benefit, all our own distance functions like Of course there is a caveat that coordinates test coverage might not be complete with respect to wrapping issues, since this was known to be handled previously within [1] OK, after changing |
|
@taldcroft - just an idea - how about reinstating the bounds as an option in the initializer (maybe under a different name) to allow the angle to be automatically wrapped? (would prevent the user from having to do the arithmetic themselves). I think this discussion should be taken to the astropy-dev list. @taldcroft, since you originally suggested this change, do you want to do that? |
|
Bounds are useful for that reason alone - to not have to write your own code to wrap results. No need to change the name - that's the purpose. That and providing a way to restrict values for error checking. |
|
What about:
Then this allows arbitrary arithmetic between |
|
@astrofrog How could/would this use case be handled? I define declination: Obviously I don't want the result to be 30°. |
|
@demitri - well in my scenario in Of course, Angle is not a declination so this would not be available by default. The Declination class on the other hand could support raising an exception using this mechanism behind the scenes. |
|
@astrofrog That usage of No, |
|
@demitri - in my scenario the purpose of |
|
@astrofrog I was making an argument for not dropping |
|
Just out of interest, can you give a real life example where the bounds are not -90 to 90, -180 to 180, or 0 to 360? It would help me understand why we need arbitrary flexibility in this respect. |
|
I don't have a specific example, no. It just seems to me that if we support one, it should be a similar effort to support any. Well, wait. Let's say someone was working on coordinates for a telescope pointing. What if, due to geometry, mechanics, trees, whatever, the telescope could only point to targets with a declination range of [26.7, 82.1]? Not unreasonable, and it would be really nice to have code that made sure that the angle I give it falls in that range without me having to check all the time. I could very easily forget to check. |
|
Another use case is using the |
|
For the latter example, that's just the standard behavior in |
@astrofrog - this is pretty reasonable, but I think it can be even simpler and meet all typical use cases. What about just the following two methods and nothing cluttering up the initializer. These two methods explicitly decouple wrapping and bounds checking:
Some typical code would be: This makes for explicit code that is readable and allows intuitive math and spherical trig with |
|
I think I'm ok with either of @astrofrog or @taldcroft's suggestions here, but one thing is still left in my mind: what about the string representation? There are a lot of cases where you want the string representation to also be wrapped to a certain range (e.g. 0 to 24 hr for RA, -90 to 90 deg for dec). Right now that's implicitly taken care of by the bounds, but if that's removed, then subclasses that want this would have to re-implement string formatting code, right? |
|
Looks good to me! (apart from the docs needing updating) |
|
OK, I believe I have addressed all comments and done all the requisite doc updates. From my perspective this is good for merge. |
There was a problem hiding this comment.
I hadn't noticed this before... why is this giving an array of objects instead of U10 or similar? This may be behavior generic to Quantity, in which case it might be better dealt with in another PR, but if it somehow comes from Angle-specific stuff, it should probably be changed.
EDIT: I see below the note that this is intended behavior... is there a specific reason why it's good?
There was a problem hiding this comment.
I presume this will be fixed in #1374, but I just wanted to document accurately what we have now.
|
The items above are all pretty straightforward (except the array-output question, which is probably for another PR). So aside from that, I think this is ready to merge. Thanks for all the work, @taldcroft ! |
Remove bounds attribute from Angle class, add Longitude and Latitude classes
There is some level of disagreement as to whether the
Angleclass should includeboundsor whether this should be dealt with in the more specialized Coordinate classes. This issue is to keep track of any discussion and/or decision.