Skip to content

Angle objects should be comparable to Quantity/Unit objects. #416

Closed

Description

@demitri

Currently Angle objects can only be compared to other Angle objects. They should be comparable to Quantity objects that make sense (e.g. equivalent to angles).

Activity

  1. eteq commented on Dec 18, 2012

    @eteq
    Member

    @demitri - strictly speaking, this means only dimensionless quantities. Is that what you were thinking?

  2. demitri commented on Dec 19, 2012

    @demitri
    ContributorAuthor

    It's been too long - I'm not sure what I was thinking. Maybe I was thinking this:

    a = Angle(10, unit=u.radian)
    a == 10 * u.radian
    >>> True
    
  3. eteq commented on Dec 19, 2012

    @eteq
    Member

    Ah, I see. I'm a little concerned about the potential for confusion (e.g. thinking q = Quantity(10, u.radian) is the same thing as a = Angle(10,unit=u.radian) and thus trying q.degrees or similar). But maybe I'm over-thinking it?

  4. demitri commented on Dec 19, 2012

    @demitri
    ContributorAuthor

    Yes. :) If people try that, they will get an error, feel foolish, mend their code and their ways, and lead a fuller, happier life.

  5. eteq commented on Dec 19, 2012

    @eteq
    Member

    Ok, that's fine - I'm not sure I'll be able to get to this too soon, so @demitri, do you want to do this PR?

  6. eteq commented on May 13, 2013

    @eteq
    Member

    This is being addressed in #1006 , so once that's merged, this can be closed. I'm re-tagging it v0.3 to match #1006

  7. astrofrog commented on May 13, 2013

    @astrofrog
    Member

    We should probably add some tests to ensure that straight comparisons work properly once #1006 is done.

  8. astrofrog commented on May 13, 2013

    @astrofrog
    Member

    By the way, here's a trick question: what should Angle(365, unit=u.degree) > Angle(10, unit=u.degree) return? :)

  9. demitri commented on May 13, 2013

    @demitri
    ContributorAuthor

    @astrofrog False. By default, 365 degrees becomes 5 degrees, which is less than 10 degrees. You have to explicitly specify larger bounds (e.g. bounds=[-720,720]) for the internal representation to store angles greater than 360 degrees. The angle above would behave as:

    >>> a = Angle(365, unit=u.degree)
    >>> print a.degrees
    5.0
    

    At least that was the API design.

  10. astrofrog commented on May 13, 2013

    @astrofrog
    Member

    @demitri - my question was more rethorical - what should it do? While I think it makes sense to compare separations, I don't think it necessarily makes sense to compare absolute angles. This becomes especially fishy if you start considering angles with different bounds for example. For instance, what about comparing -90 degrees (without bounds [-180:180]) with +270 degrees? (with bounds [0:360]). Technically speaking they are the same angle, but the internal values are different. So maybe comparisons should be disabled for absolute angles?

  11. demitri commented on May 13, 2013

    @demitri
    ContributorAuthor

    @astrofrog What I listed above is what I believe it should do. I don't think it becomes a problem with different bounds. Remember, to me the Angle object represents the Platonic ideal (as it were), not a decimal value and a unit string. It's an angle. Ignoring bounds, -90 deg is exactly equal to +270. It's the same angle, regardless of how it's specified. This would be ridiculous:

    >>> a1 = Angle(-90 * u.deg)
    >>> a2 = Angle(+270 * u.deg)
    >>> a1 == a2
    False
    

    If one want to keep track of the exact values that define the angle (e.g. "-90" and "+270"), let the use do that on their own. They're not dealing with angles anymore, they are dealing with strings and decimals.

    The point of bounds is to allow this:

    >>> a3 = Angle(400 * u.deg, bounds=[-720,720]
    >>> a3.degrees
    400.0
    

    instead of the default:

    >>> a4 = Angle(400 * u.deg)
    >>> a4.degrees
    40.0
    

    There are cases where one wants a different range, but either way, the angle is 40 degrees. The meaning of the angle does not depend on its representation (internal or external). This is very important.

    Bounds are also used for error checking in cases where one wants this behavior:

    >>> x = 270.0 # e.g. values read from file
    >>> a5 = Angle(x * u.deg, bounds=[-90,90]
    Exception: out of bounds
    
  12. demitri commented on May 13, 2013

    @demitri
    ContributorAuthor

    An argument can be made that 400 degrees might represent a rotation about an axis of one full revolution plus 40 degrees, and then that would be greater than 40 degrees. But this class is not advertised as representing rotations; it's an angular measure. The above (if needed) should be a subclass of Angle called AngularRotation.

  13. astrofrog commented on May 14, 2013

    @astrofrog
    Member

    @demitri - I realize I wasn't clear with what I meant - I was talking about disabling specifically the inequality comparisons, which I don't think make sense for a 'platonic' angle - for instance, what does it mean that 350 is larger than 5 degrees, since it's also -10 degrees, which is smaller than 5 degrees. Quantity objects allow inequality comparisons, but I'm just saying that this should be disabled for the Angle sub-class - does this make sense?

    Of course, the equality comparison makes sense the way you describe.

  14. demitri commented on May 14, 2013

    @demitri
    ContributorAuthor

    @astrofrog I don't think inequality comparisons should be disabled. 350 deg is greater than 5 degrees. -10 degrees is greater than 5 degrees. If you drew this on a piece of paper this is immediately evident. Think of pulling pieces out of a pie chart. The abstract "angle" is a pie piece, whose size is defined by a point of origin, but the angular distance covered is not dependent on a point of origin. Don't be concerned with the actual scalar values - compare the angles defined. I don't see a problem here. This is my concern with Angle being a subclass of Quantity; the latter appears to be defined by the scalar quantities and literal unit, while the former uses that only to determine the angle.

  15. eteq commented on May 19, 2013

    @eteq
    Member

    @demitri - I'm confused by what you said here. -10 degrees is not necessarily great than 5 degrees. An analogy might be the vector dot product of point A=(1,2) onto the x-axis and point B=(-2,1) onto the x-axis. I'd say A.x > B.x, because 1 > -2, even though the magnitude B.x is greater than A.x .

    Put another way, it's inherently ambiguous whether or not an angle's sign is meaningful or not. As you said above, that could be an AngularRotation, but it's not immediately obvious which one we mean in the Angle class, and there's no way to make it unambiguous because of the imprecision of the word "Angle."

    So while I may be wrong, I think @astrofrog is suggesting just disabling it entirely. If we did that, we already have an AngularSeparation, so we could just add an Angle subclass AngularRotation. They could then be nearly-trivial subclasses that treat inequalities different (and possibly also do different things with bounds?).

  16. astrofrog commented on May 19, 2013

    @astrofrog
    Member

    @eteq - just to confirm, I am indeed suggesting disabling inequality comparisons on Angle objects.

  17. mdboom commented on Sep 4, 2013

    @mdboom
    Contributor

    I believe this is resolved now. Reopen if not.

  18. added a commit that references this issue on Jun 12, 2019
  19. added a commit that references this issue on Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions