Angle — PyMeeus 0.5.12 documentation

# Angle

Class to handle angles.

class pymeeus.Angle.Angle(*args, **kwargs)

  Class Angle deals with angles in either decimal format (d.dd) or in sexagesimal format (d m’ s’’).

  It provides methods to handle an Angle object like it were a simple float, but adding the functionality associated with an angle.

  The constructor takes decimals and sexagesimal input. The sexagesimal angles can be given as separate degree, minutes, seconds values, or as tuples or lists. It is also possible to provide another Angle object as input.

  Also, if radians=True is passed to the constructor, then the input value is considered as in radians, and converted to degrees.

  __abs__()

    This method is used to obtain the absolute value of this Angle.

    Returns

      A new Angle object.

    Return type

      `Angle`

        >>> a = Angle(-303.67)
        >>> print(abs(a))
        303.67

  __add__(b)

    This method defines the addition between Angles.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(83.1)
        >>> b = Angle(18.4)
        >>> print(a + b)
        101.5

  __call__()

    Method used when object is called only with parenthesis.

    Returns

      The internal value of the Angle object.

    Return type

      int, float

        >>> a = Angle(54.6)
        >>> print(a())
        54.6

  __div__(b)

    This method defines the division between Angles.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(172.0)
        >>> b = Angle(86.0)
        >>> print(a/b)
        2.0

  __eq__(b)

    This method defines the ‘is equal’ operator between Angles.

    Note

    For the comparison, the internal tolerance value is used.

    Returns

      A boolean.

    Return type

      bool

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(172.01)
        >>> b = Angle(172.009)
        >>> a == b
        False

  __float__()

    This method returns Angle value as a float.

    Returns

      Internal angle value as a float.

    Return type

      float

        >>> a = Angle(213.8)
        >>> float(a)
        213.8

  __ge__(b)

    This method defines ‘is equal or greater’ operator between Angles.

    Returns

      A boolean.

    Return type

      bool

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(172.01)
        >>> b = Angle(172.009)
        >>> a >= b
        True

  __gt__(b)

    This method defines the ‘is greater than’ operator between Angles.

    Returns

      A boolean.

    Return type

      bool

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(172.01)
        >>> b = Angle(172.009)
        >>> a > b
        True

  __hash__ = None
  __iadd__(b)

    This method defines the accumulative addition to this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

        >>> a = Angle(172.1)
        >>> b = Angle(54.6)
        >>> a += b
        >>> print(a)
        226.7

  __idiv__(b)

    This method defines the accumulative division to this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(330.0)
        >>> b = Angle(30.0)
        >>> a /= b
        >>> print(a)
        11.0

  __imod__(b)

    This method defines the accumulative module b of this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

        >>> a = Angle(330.0)
        >>> b = Angle(45.0)
        >>> a %= b
        >>> print(a)
        15.0

  __imul__(b)

    This method defines the accumulative multiplication to this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

        >>> a = Angle(30.0)
        >>> b = Angle(55.0)
        >>> a *= b
        >>> print(a)
        210.0

  __init__(*args, **kwargs)

    Angle constructor.

    It takes decimals and sexagesimal input. The sexagesimal angles can be given as separate degree, minutes, seconds values, or as tuples or lists. It is also possible to provide another Angle object as input.

    If radians=True is passed, then the input value is converted from radians to degrees.

    If ra=True is passed, then the input value is converted from Right Ascension to degrees

    Parameters

      - args (int, float, list, tuple, `Angle`) – Input angle, in decimal or sexagesimal format, or Angle

      - radians (bool) – If True, input angle is in radians. False by default.

      - ra (bool) – If True, input angle is in Right Ascension. False by default

    Returns

      Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(-13, 30, 0.0)
        >>> print(a)
        -13.5
        >>> b = Angle(a)
        >>> print(b)
        -13.5

  __int__()

    This method returns Angle value as an int.

    Returns

      Internal angle value as an int.

    Return type

      int

        >>> a = Angle(213.8)
        >>> int(a)
        213

  __ipow__(b)

    This method defines the accumulative power to this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

        >>> a = Angle(37.0)
        >>> b = Angle(3.0)
        >>> a **= b
        >>> print(a)
        253.0

  __isub__(b)

    This method defines the accumulative subtraction to this Angle.

    Returns

      This Angle.

    Return type

      `Angle`

        >>> a = Angle(97.0)
        >>> b = Angle(39.0)
        >>> a -= b
        >>> print(a)
        58.0

  __itruediv__(b)

    This method defines accumulative division to this Angle (Python3).

    Returns

      This Angle.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

    See

      __idiv__

  __le__(b)

    This method defines ‘is equal or less’ operator between Angles.

    Returns

      A boolean.

    Return type

      bool

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(72.0)
        >>> b = Angle(72.0)
        >>> a <= b
        True

  __lt__(b)

    This method defines the ‘is less than’ operator between Angles.

    Returns

      A boolean.

    Return type

      bool

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(72.0)
        >>> b = Angle(72.0)
        >>> a < b
        False

  __mod__(b)

    This method is used to obtain the module b of this Angle.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(333.0)
        >>> b = Angle(72.0)
        >>> print(a % b)
        45.0

  __mul__(b)

    This method defines the multiplication between Angles.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(33.0)
        >>> b = Angle(72.0)
        >>> print(a * b)
        216.0

  __ne__(b)

    This method defines the ‘is not equal’ operator between Angles.

    Note

    For the comparison, the internal tolerance value is used.

    Returns

      A boolean.

    Return type

      bool

        >>> a = Angle(11.200001)
        >>> b = Angle(11.200000)
        >>> a != b
        True

  __neg__()

    This method is used to obtain the negative version of this Angle.

    Returns

      A new Angle object.

    Return type

      `Angle`

        >>> a = Angle(-11.2)
        >>> print(-a)
        11.2

  __pow__(b)

    This method defines the power operation for Angles.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(12.5)
        >>> b = Angle(4.0)
        >>> print(a ** b)
        294.0625

  __radd__(b)

    This method defines the addition between Angles by the right

    Returns

      A new Angle object.

    Return type

      `Angle`

        >>> a = Angle(83.1)
        >>> print(8.5 + a)
        91.6

  __rdiv__(b)

    This method defines division between Angles by the right.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(80.0)
        >>> print(350 / a)
        4.375

  __repr__()

    Method providing the ‘official’ string representation of the object. It provides a valid expression that could be used to recreate the object.

    Returns

      As string with a valid expression to recreate the object

    Return type

      string

        >>> a = Angle(12.5)
        >>> repr(a)
        'Angle(12.5)'

  __rmod__(b)

    This method defines module operation between Angles by the right.

    Returns

      A new Angle object.

    Return type

      `Angle`

        >>> a = Angle(80.0)
        >>> print(350 % a)
        30.0

  __rmul__(b)

    This method defines multiplication between Angles by the right.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(11.0)
        >>> print(250.0 * a)
        230.0

  __round__(n=0)

    This method returns an Angle with content rounded to ‘n’ decimal.

    Returns

      A new Angle object.

    Return type

      `Angle`

        >>> a = Angle(11.4361)
        >>> print(round(a, 2))
        11.44

  __rpow__(b)

    This method defines the power operation for Angles by the right.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(5.0)
        >>> print(24.0 ** a)
        144.0

  __rsub__(b)

    This method defines the subtraction between Angles by the right.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(25.0)
        >>> print(24.0 - a)
        -1.0

  __rtruediv__(b)

    This method defines division between Angle by the right (Python3).

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

    See

      __rdiv__

  __str__()

    Method used when trying to print the object.

    Returns

      Angle as string.

    Return type

      string

        >>> a = Angle(12.5)
        >>> print(a)
        12.5

  __sub__(b)

    This method defines the subtraction between Angles.

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle(25.4)
        >>> b = Angle(10.2)
        >>> print(a - b)
        15.2

  __truediv__(b)

    This method defines the division between Angles (Python 3).

    Returns

      A new Angle object.

    Return type

      `Angle`

    Raises

      ZeroDivisionError if divisor is zero.

    Raises

      TypeError if input values are of wrong type.

    See

      __div__

  __weakref__

    list of weak references to the object (if defined)

  static deg2dms(deg)

    Converts input from decimal to sexagesimal angle format.

    Parameters

      deg (int, float) – Degrees decimal format.

    Returns

      Angle in sexagesimal format, with ranges adjusted.

    Return type

      tuple

    Note

    The output format is (Degrees, Minutes, Seconds, sign)

        >>> print(Angle.deg2dms(23.44694444))
        (23, 26, 48.999983999997596, 1.0)

  static dms2deg(degrees, minutes, seconds=0.0)

    Converts an angle from sexagesimal to decimal format.

    Parameters

      - degrees (int, float) – Degrees.

      - minutes (int, float) – Minutes.

      - seconds (int, float) – Seconds. 0.0 by default.

    Returns

      Angle in decimal format, within +/-[0:360) range.

    Return type

      float

        >>> print(Angle.dms2deg(-23, 26, 48.999983999997596))
        -23.44694444

  dms_str(fancy=True, n_dec=- 1)

    Returns the Angle value as a sexagesimal string.

    The parameter fancy allows to print in “Dd M’ S’’” format if True, and in “D:M:S” (easier to parse) if False. On the other hand, the n_dec parameter sets the number of decimals used to print the seconds. Set to a negative integer to disable (default).

    Parameters

      - fancy (int) – Format of output string. True by default.

      - n_dec – Number of decimals used to print the seconds

    Returns

      Angle value as string in sexagesimal format.

    Return type

      string

    Raises

      TypeError if input value is of wrong type.

        >>> a = Angle(42.75)
        >>> print(a.dms_str())
        42d 45' 0.0''
        >>> print(a.dms_str(fancy=False))
        42:45:0.0
        >>> a = Angle(49, 13, 42.4817)
        >>> print(a.dms_str(n_dec=2))
        49d 13' 42.48''

  dms_tuple()

    Returns the Angle as a tuple containing (degrees, minutes, seconds, sign).

    Returns

      Angle value as (degrees, minutes, seconds, sign).

    Return type

      tuple

  get_ra()

    Returns the Angle value as a Right Ascension in float format

    Returns

      The internal value of the Angle object as Right Ascension.

    Return type

      int, float

        >>> a = Angle(138.75)
        >>> print(a.get_ra())
        9.25

  get_tolerance()

    Gets the internal tolerance value used to compare Angles.

    Note

    The default tolerance value is base.TOL.

    Returns

      Internal tolerance.

    Return type

      float

  ra_str(fancy=True, n_dec=- 1)

    Returns the Angle value as a sexagesimal string in Right Ascension.

    The parameter fancy allows to print in “Hh M’ S’’” format if True, and in “H:M:S” (easier to parse) if False. On the other hand, the n_dec parameter sets the number of decimals used to print the seconds. Set to a negative integer to disable (default).

    Parameters

      - fancy (int) – Format of output string. True by default.

      - n_dec – Number of decimals used to print the seconds

    Returns

      Angle value as Right Ascension in sexagesimal format.

    Return type

      string

    Raises

      TypeError if input value is of wrong type.

        >>> a = Angle(138.75)
        >>> print(a.ra_str())
        9h 15' 0.0''
        >>> print(a.ra_str(fancy=False))
        9:15:0.0
        >>> a = Angle(2, 44, 11.98581, ra=True)
        >>> print(a.ra_str(n_dec=3))
        2h 44' 11.986''

  ra_tuple()

    Returns the Angle in Right Ascension format as a tuple containing (hours, minutes, seconds, sign).

    Returns

      Angle value as RA in (hours, minutes, seconds, sign) format.

    Return type

      tuple

  rad()

    Returns the Angle value in radians.

    Returns

      Angle value in radians.

    Return type

      float

        >>> a = Angle(47.762)
        >>> print(round(a.rad(), 8))
        0.83360416

  static reduce_deg(deg)

    Takes a degree value in decimal format and converts it to a float value in the +/-[0:360) range.

    Parameters

      deg (int, float, `Angle`) – Input degree angle in decimal format.

    Returns

      Float value of the angle in the +/-[0:360) range.

    Return type

      float

        >>> a = 386.3
        >>> b = Angle.reduce_deg(a)
        >>> print(round(b, 1))
        26.3

  static reduce_dms(degrees, minutes, seconds=0.0)

    Takes a degree value in sexagesimal format and converts it to a value in the +/-[0:360) range (degrees) and [0:60) range (minutes and seconds). It also takes care of fractional degrees and minutes.

    Parameters

      - degrees (int, float) – Degrees.

      - minutes (int, float) – Minutes.

      - seconds (int, float) – Seconds. 0.0 by default.

    Returns

      Angle in sexagesimal format, with ranges properly adjusted.

    Return type

      tuple

        >>> print(Angle.reduce_dms(-743.0, 26.0, 49.6))
        (23, 26, 49.6, -1.0)

  set(*args, **kwargs)

    Method used to define the value of the Angle object.

    It takes decimals and sexagesimal input. The sexagesimal angles can be given as separate degree, minutes, seconds values, or as tuples or lists. It is also possible to provide another Angle object as input.

    If radians=True is passed, then the input value is converted from radians to degrees

    If ra=True is passed, then the input value is converted from Right Ascension to degrees

    Parameters

      - args (int, float, list, tuple, `Angle`) – Input angle, in decimal or sexagesimal format, or Angle

      - radians (bool) – If True, input angle is in radians. False by default.

      - ra (bool) – If True, input angle is in Right Ascension. False by default

    Returns

      None.

    Return type

      None

    Raises

      TypeError if input values are of wrong type.

  set_ra(*args)

    Define the value of the Angle object from a Right Ascension.

    It takes decimals and sexagesimal input. The sexagesimal Right Ascensions can be given as separate hours, minutes, seconds values, or as tuples or lists.

    Parameters

      args (int, float, list, tuple) – Input Right Ascension, in decimal or sexagesimal format.

    Returns

      None.

    Return type

      None

    Raises

      TypeError if input values are of wrong type.

        >>> a = Angle()
        >>> a.set_ra(9, 14, 55.8)
        >>> print(a)
        138.7325

  set_radians(rads)

    Method to define the value of the Angle object from radians.

    Parameters

      rads (int, float) – Input angle, in radians.

    Returns

      None.

    Return type

      None

    Raises

      TypeError if input value is of wrong type.

        >>> a = Angle()
        >>> a.set_radians(pi)
        >>> print(a)
        180.0

  set_tolerance(tol)

    Changes the internal tolerance value used to compare Angles.

    Parameters

      tol (int, float) – New tolerance value.

    Returns

      None

    Return type

      None

  to_positive()

    Converts the internal angle value from negative to positive.

    Returns

      This angle object.

    Return type

      `Angle`

        >>> a = Angle(-87.32)
        >>> print(a.to_positive())
        272.68