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
12d 14' 0.0"” or
12d 13' 59.9"”.
The class interface shown below has a
.format() method 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
60). The factor list for a mixed unit system with
N units always has length
To create a
A factor list as discussed above. Example:
(24, 60, 60) for the
A list of coefficients from largest to smallest.
If the list is shorter than the length of the
factorList plus one, the returned value
will assume zero values for the omitted positions.
For convenience, you may also provide a single
numeric scalar representing the largest units.
Here are some examples in the hours-minutes-seconds
system, and what they represent.
||One hour, two minutes, three seconds.|
||One hour, two minutes.|
|Fourteen hours exactly.|
|Fourteen hours and thirty minutes.|
For example, here is how you would create an instance to represent 10:32:04AM in the hours-minutes-seconds mixed units system.
then = MixedValue((60, 60), (10, 32, 4))