Skip to content

phn/angles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angles

image

The Angles module defines several classes for representing angles, and positions on a sphere. It also has several functions for performing common operations on angles, such as unit conversion, normalization, creating string representations and others.

The position of M100 reported by SIMBAD is "12 22 54.899 +15 49 20.57". We can easily parse these coordinates as follows:

Installation

Use pip or easy_install:

$ pip install angles

or,

$ easy_install angles

Tests are in the file test_angles.py.

Examples

Some examples are given below. For more details see docstrings of functions and classes.

Unit conversion

Convert between radians, degrees, hours and arc-seconds.

Normalizing angles

Normalize value between two limits using normalize.

Normalizing angles on a sphere

Simplify point on sphere to simplest representation using normalize_sphere.

Sexagesimal representation

Convert decimal value into sexagesimal representation.

Formatting angles

Format an angle into various string representations using fmt_angle.

Parsing sexagesimal strings

Parse a sexagesimal number from a string using phmsdms.

Parse string containing angular position

Parse coordinates of a point on sphere using pposition.

Separation angle along a great circle

Find angular separation along a great circle using sep. This function uses vectors to find the angle of separation.

Bearing between two points

Find bearing of one point with respect to another using bear. Like sep this function uses vectors.

Angle class

Class for representing an angle, conversion between different units, generating string representations.

>>> from __future__ import print_function
>>> from angles import Angle

>>> a = Angle(sg="12h34m16.592849219")
>>> a.r, a.d, a.h, a.arcs  # doctest: +NORMALIZE_WHITESPACE
(3.291152306055805, 188.56913687174583, 12.571275791449722, 678848.892738285)

>>> a.hms.sign, a.hms.hh, a.hms.mm, a.hms.ss
(1, 12, 34, 16.593)
>>> a.hms.hms
(1, 12, 34, 16.593)
>>> a.h
12.571275791449722

>>> a.dms.sign, a.dms.dd, a.dms.mm, a.dms.ss
(1, 188, 34, 8.893)
>>> a.dms.dms
(1, 188, 34, 8.893)
>>> a.d
188.56913687174583

>>> print(a.ounit)
hours
>>> print(a)
+12 34 16.593
>>> a.pre, a.trunc
(3, False)
>>> a.pre = 4
>>> print(a)
+12 34 16.5928
>>> a.pre = 3
>>> a.trunc = True
>>> print(a)
+12 34 16.592

>>> a.ounit = "degrees"
>>> print(a)
+188 34 08.892
>>> a.ounit = "radians"
>>> print(a)  # doctest: +SKIP
3.29115230606

>>> a.ounit = "degrees"
>>> a.s1 = "DD "
>>> a.s2 = "MM "
>>> a.s3 = "SS"
>>> print(a)
+188DD 34MM 08.892SS

>>> a = Angle(r=10)
>>> a.d, a.h, a.r, a.arcs, a.ounit  # doctest: +NORMALIZE_WHITESPACE
(572.9577951308232, 38.197186342054884, 10, 2062648.0624709637, 'radians')

>>> a.d = 10
>>> a.d, a.h, a.r, a.arcs, a.ounit  # doctest: +NORMALIZE_WHITESPACE
(10.0, 0.6666666666666666, 0.17453292519943295, 36000.0, 'radians')

>>> a.dms.mm = 60
>>> a.d, a.h, a.r, a.arcs, a.ounit  # doctest: +NORMALIZE_WHITESPACE
(11.0, 0.7333333333333333, 0.19198621771937624, 39600.0, 'radians')

>>> a.dms.dms = (1, 12, 10, 5.234)
>>> a.d, a.h, a.r, a.arcs, a.ounit  # doctest: +NORMALIZE_WHITESPACE
(12.168120555555557, 0.8112080370370371, 0.21237376747404604,
43805.234000000004, 'radians')

>>> a.hms.hms = (1, 1, 1, 1)
>>> a.d, a.h, a.r, a.arcs, a.ounit  # doctest: +NORMALIZE_WHITESPACE
(15.254166666666668, 1.0169444444444444, 0.2662354329813017,
54915.00000000001, 'radians')

>>> print(a)  # doctest: +SKIP
0.266235432981
>>> a.ounit = 'hours'
>>> print(a)
+01 01 01.000
>>> a.ounit = 'degrees'
>>> print(a)
+15 15 15.000

Class for longitudinal angles

A subclass of Angle that is normalized to the range [0, 24), i.e., a Right Ascension like angle. The ounit attribute is always "hours".

Class for latitudinal angles

A subclass of Angle that is normalized to the range [-90, 90], i.e., a Declination like angle. The ounit attribute is always "degrees".

Class for points on a unit sphere

A class for representing a point on a sphere. The input angle values are normalized to get the simplest representation of the coordinates of the point.

Credits

Some of the functions are adapted from the TPM C library by Jeffrey W. Percival.

License

Released under BSD; see LICENSE.txt.

For comments and suggestions, email to user prasanthhn in the gmail.com domain.

About

Classes for representing angles, and positions on a unit sphere.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages