The sidereal.py package uses a number of systems of mixed units:
Degrees, minutes, and seconds for latitudes and longitudes.
Hours, minutes, and seconds, for right ascensions and hour angles.
Hours, minutes, and seconds for times of day and sidereal times.
Operations on mixed-unit quantities include:
Converting from mixed units to a single unit. For example, converting an angle like 38° 52′ 30.7″ to decimal degrees.
Converting a single quantity to mixed units. For example, convert 14.876 hours to hours, minutes, and seconds.
Formatting a single quantity as mixed units. This is not as straightforward as it seems! If you just convert to mixed units and format each number, there is an ugly pathology for certain values. For example, suppose you have a tuple representing the angle 12° 13′ 59.999″, like this:
>>> angle = (12, 13, 59.999)
And then you format these quantities, using only one digit after the decimal in the seconds term, watch what happens:
>>> print '%dd %d\' %.1f"' % angle 12d 13' 60.0"
That is not user-friendly. We should display it either
as “12d 14' 0.0"” or
“12d 13' 59.9"”.
The class interface shown below has a special method, .format(), that prevents this problem.
In order to make calculations on mixed units, it is necessary to define the relative size of the units in the system. For example, in the days-hours-minutes-seconds system, there are 24 hours in a day, 60 minutes in an hour, and 60 hours in a second.
So we'll define a sequence called the factor
list as a Python sequence containing these
factors. For example, the factor list for the
days-hours-minutes-seconds system is (24, 60,
60). The factor list for a mixed unit system with
N units always has length
(N-1).
To create a MixedUnits instance, pass the
factor list to its constructor like this:
MixedUnits ( factorList )
For example, here is how you would create an instance to represent the days-hours-minutes-seconds mixed units system.
dhms = MixedUnits ( (24, 60, 60) )
Each instance has an attribute .factors
containing the factor list passed to the constructor.