Angle¶

Class to handle angles.

class `pymeeus.Angle.``Angle`(*args, **kwargs)[source]

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__`()[source]

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

Returns: A new Angle object. `Angle`
```>>> a = Angle(-303.67)
>>> print(abs(a))
303.67
```
`__add__`(b)[source]

This method defines the addition between Angles.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(83.1)
>>> b = Angle(18.4)
>>> print(a + b)
101.5
```
`__call__`()[source]

Method used when object is called only with parenthesis.

Returns: The internal value of the Angle object. int, float
```>>> a = Angle(54.6)
>>> print(a())
54.6
```
`__div__`(b)[source]

This method defines the division between Angles.

Returns: A new Angle object. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type.
```>>> a = Angle(172.0)
>>> b = Angle(86.0)
>>> print(a/b)
2.0
```
`__eq__`(b)[source]

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

Note

For the comparison, the internal tolerance value is used.

Returns: A boolean. bool TypeError if input values are of wrong type.
```>>> a = Angle(172.01)
>>> b = Angle(172.009)
>>> a == b
False
```
`__float__`()[source]

This method returns Angle value as a float.

Returns: Internal angle value as a float. float
```>>> a = Angle(213.8)
>>> float(a)
213.8
```
`__ge__`(b)[source]

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

Returns: A boolean. bool TypeError if input values are of wrong type.
```>>> a = Angle(172.01)
>>> b = Angle(172.009)
>>> a >= b
True
```
`__gt__`(b)[source]

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

Returns: A boolean. bool TypeError if input values are of wrong type.
```>>> a = Angle(172.01)
>>> b = Angle(172.009)
>>> a > b
True
```
`__iadd__`(b)[source]

This method defines the accumulative addition to this Angle.

Returns: This Angle. `Angle`
```>>> a = Angle(172.1)
>>> b = Angle(54.6)
>>> a += b
>>> print(a)
226.7
```
`__idiv__`(b)[source]

This method defines the accumulative division to this Angle.

Returns: This Angle. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type.
```>>> a = Angle(330.0)
>>> b = Angle(30.0)
>>> a /= b
>>> print(a)
11.0
```
`__imod__`(b)[source]

This method defines the accumulative module b of this Angle.

Returns: This Angle. `Angle`
```>>> a = Angle(330.0)
>>> b = Angle(45.0)
>>> a %= b
>>> print(a)
15.0
```
`__imul__`(b)[source]

This method defines the accumulative multiplication to this Angle.

Returns: This Angle. `Angle`
```>>> a = Angle(30.0)
>>> b = Angle(55.0)
>>> a *= b
>>> print(a)
210.0
```
`__init__`(*args, **kwargs)[source]

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 Angle object. `Angle` 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__`()[source]

This method returns Angle value as an int.

Returns: Internal angle value as an int. int
```>>> a = Angle(213.8)
>>> int(a)
213
```
`__ipow__`(b)[source]

This method defines the accumulative power to this Angle.

Returns: This Angle. `Angle`
```>>> a = Angle(37.0)
>>> b = Angle(3.0)
>>> a **= b
>>> print(a)
253.0
```
`__isub__`(b)[source]

This method defines the accumulative subtraction to this Angle.

Returns: This Angle. `Angle`
```>>> a = Angle(97.0)
>>> b = Angle(39.0)
>>> a -= b
>>> print(a)
58.0
```
`__itruediv__`(b)[source]

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

Returns: This Angle. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type. __idiv__
`__le__`(b)[source]

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

Returns: A boolean. bool TypeError if input values are of wrong type.
```>>> a = Angle(72.0)
>>> b = Angle(72.0)
>>> a <= b
True
```
`__lt__`(b)[source]

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

Returns: A boolean. bool TypeError if input values are of wrong type.
```>>> a = Angle(72.0)
>>> b = Angle(72.0)
>>> a < b
False
```
`__mod__`(b)[source]

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

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(333.0)
>>> b = Angle(72.0)
>>> print(a % b)
45.0
```
`__mul__`(b)[source]

This method defines the multiplication between Angles.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(33.0)
>>> b = Angle(72.0)
>>> print(a * b)
216.0
```
`__ne__`(b)[source]

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

Note

For the comparison, the internal tolerance value is used.

Returns: A boolean. bool
```>>> a = Angle(11.200001)
>>> b = Angle(11.200000)
>>> a != b
True
```
`__neg__`()[source]

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

Returns: A new Angle object. `Angle`
```>>> a = Angle(-11.2)
>>> print(-a)
11.2
```
`__pow__`(b)[source]

This method defines the power operation for Angles.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(12.5)
>>> b = Angle(4.0)
>>> print(a ** b)
294.0625
```
`__radd__`(b)[source]

This method defines the addition between Angles by the right

Returns: A new Angle object. `Angle`
```>>> a = Angle(83.1)
>>> print(8.5 + a)
91.6
```
`__rdiv__`(b)[source]

This method defines division between Angles by the right.

Returns: A new Angle object. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type.
```>>> a = Angle(80.0)
>>> print(350 / a)
4.375
```
`__repr__`()[source]

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 string
```>>> a = Angle(12.5)
>>> repr(a)
'Angle(12.5)'
```
`__rmod__`(b)[source]

This method defines module operation between Angles by the right.

Returns: A new Angle object. `Angle`
```>>> a = Angle(80.0)
>>> print(350 % a)
30.0
```
`__rmul__`(b)[source]

This method defines multiplication between Angles by the right.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(11.0)
>>> print(250.0 * a)
230.0
```
`__round__`(n=0)[source]

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

Returns: A new Angle object. `Angle`
```>>> a = Angle(11.4361)
>>> print(round(a, 2))
11.44
```
`__rpow__`(b)[source]

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

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(5.0)
>>> print(24.0 ** a)
144.0
```
`__rsub__`(b)[source]

This method defines the subtraction between Angles by the right.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(25.0)
>>> print(24.0 - a)
-1.0
```
`__rtruediv__`(b)[source]

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

Returns: A new Angle object. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type. __rdiv__
`__str__`()[source]

Method used when trying to print the object.

Returns: Angle as string. string
```>>> a = Angle(12.5)
>>> print(a)
12.5
```
`__sub__`(b)[source]

This method defines the subtraction between Angles.

Returns: A new Angle object. `Angle` TypeError if input values are of wrong type.
```>>> a = Angle(25.4)
>>> b = Angle(10.2)
>>> print(a - b)
15.2
```
`__truediv__`(b)[source]

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

Returns: A new Angle object. `Angle` ZeroDivisionError if divisor is zero. TypeError if input values are of wrong type. __div__
`__weakref__`

list of weak references to the object (if defined)

static `deg2dms`(deg)[source]

Converts input from decimal to sexagesimal angle format.

Parameters: deg (int, float) – Degrees decimal format. Angle in sexagesimal format, with ranges adjusted. 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)[source]

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. Angle in decimal format, within +/-[0:360) range. float
```>>> print(Angle.dms2deg(-23, 26, 48.999983999997596))
-23.44694444
```
`dms_str`(fancy=True, n_dec=-1)[source]

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 Angle value as string in sexagesimal format. string 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`()[source]

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

Returns: Angle value as (degrees, minutes, seconds, sign). tuple
`get_ra`()[source]

Returns the Angle value as a Right Ascension in float format

Returns: The internal value of the Angle object as Right Ascension. int, float
```>>> a = Angle(138.75)
>>> print(a.get_ra())
9.25
```
`get_tolerance`()[source]

Gets the internal tolerance value used to compare Angles.

Note

The default tolerance value is base.TOL.

Returns: Internal tolerance. float
`ra_str`(fancy=True, n_dec=-1)[source]

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 Angle value as Right Ascension in sexagesimal format. string 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`()[source]

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. tuple
`rad`()[source]

Returns the Angle value in radians.

Returns: Angle value in radians. float
```>>> a = Angle(47.762)
0.83360416
```
static `reduce_deg`(deg)[source]

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. Float value of the angle in the +/-[0:360) range. float
```>>> a = 386.3
>>> b = Angle.reduce_deg(a)
>>> print(round(b, 1))
26.3
```
static `reduce_dms`(degrees, minutes, seconds=0.0)[source]

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. Angle in sexagesimal format, with ranges properly adjusted. tuple
```>>> print(Angle.reduce_dms(-743.0, 26.0, 49.6))
(23, 26, 49.6, -1.0)
```
`set`(*args, **kwargs)[source]

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 None. None TypeError if input values are of wrong type.
`set_ra`(*args)[source]

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. None. None TypeError if input values are of wrong type.
```>>> a = Angle()
>>> a.set_ra(9, 14, 55.8)
>>> print(a)
138.7325
```
`set_radians`(rads)[source]

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

Parameters: rads (int, float) – Input angle, in radians. None. None TypeError if input value is of wrong type.
```>>> a = Angle()
>>> print(a)
180.0
```
`set_tolerance`(tol)[source]

Changes the internal tolerance value used to compare Angles.

Parameters: tol (int, float) – New tolerance value. None None
`to_positive`()[source]

Converts the internal angle value from negative to positive.

Returns: This angle object. `Angle`
```>>> a = Angle(-87.32)
>>> print(a.to_positive())
272.68
```