{ Practical astronomy | Computing | Time calculations }
Time calculations
Here we combine the computing environment, the software design principles and the insights about time into software to do some calculations for us. The result is the Times module (The capitalisation and the "s" at the end avoid a narrow miss with the similarly named standard Python module "time".) We use one hidden file to keep information about one instance of time.
.CE4_TIM
- Stores the Julian Day Number JD in days, minus 2450000 d.
JD has one disadvantage resulting from its starting point thousands of years ago: All times we are actually interested in tend to have JD values well above 2 million days. This consumes seven decimal digits on virtually no information, while we have only 12 significant decimal digits in the Python interpreter. When a "full JD" is given, the wrapper function treats it as a string, splits that on the decimal point and then subtracts 2450000 d from the combination of the two numbers. Internally "a JD" is such a reduced number. Only when a "full JD" needs to be written out are the two numbers – "a JD" and 2450000 – re-combined into a full-precision string.
The discussion of time and time measurements should leave us confused: There is the distinction between JD on one hand and date and time on the other. That is a mere question of units, and not one of time scales. Then there is the distinction of time scales, UT and UTC on one hand and TT and TAI on the other. Are we interested in all time scales (and each in both unit systems) or is there one predominant time scale with the others mere deviations from it? The latter is the case:
- Time is UT or UTC, and we do not care about the difference between them.
- For calculations time is preferably expressed as JD − 2450000 d
- For human use time is preferably expressed as Gregorian date and time of day in hours, minutes and seconds, all this in ISO 8601 format.
- The Julian calendar is a secondary form of expressing the date. The same time of day applies in both calendars.
- For ephemeris calculation, UT/JD has to be converted to TT as time argument. To support this, ΔT as function of JD can be calculated. But we show the user only ever ΔT, never TT itself.
- TAI is of no real interest. ΔAT as function of JD can be calculated, but is used only for academic interest. ΔAT is defined only since UTC with leap seconds existed and only about a year into the future. Beyond this interval a calculation of ΔAT is based on ΔAT = ΔT − 32.184 s.
We have these user utilities to set the principal data, JD − 2450000 d. It requires a Python script to invoke from the Bash shell and to convert input parameters, and a Python function to do the work:
TimSet.py fullJD
TimSet(fullJD)- Convert the given string with a full JD to the internal storage value JD − 2450000 d.
TimSetSys.py
TimSetSys()- Convert the current computer system clock value to the storage value JD − 2450000 d.
TimSetUT.py ISO8601
TimSetSys(ISO8601)- Convert the given ISO 8601 string into date and time of day and convert this further to the storage value JD − 2450000 d.
We have this user utility to show the principal data, but also information directly derived from it. Each requires a Python script to invoke from the Bash shell and a Python function to do the work and to make the output:
TimShow.py
TimShow()- Display to terminal the time as full JD, the date and time of day both in the Gregorian and Julian calendar, and the corrections ΔT and ΔAT in seconds.
Here is an example use from the Bash shell and from Python:
$ TimSetUT.py 1975-10-12T13:24:00 $ TimShow.py JD [d] 2442698.058333 Gregorian Date and UT 1975-10-12T13:24:00.0 Julian Date and UT 1975-09-29T13:24:00.0 TT - UT [s] 46.3562331736 TAI - UTC [s] 14.0 $ python >>> import Sputnik4.Times as Times >>> Times.TimSetUT("1975-10-12T13:24:00") >>> Times.TimShow() JD [d] 2442698.058333 Gregorian Date and UT 1975-10-12T13:24:00.0 Julian Date and UT 1975-09-29T13:24:00.0 TT - UT [s] 46.3562331736 TAI - UTC [s] 14.0 >>> print Times.TimGet() -7301.94166667
From the Python shell, we can also make more intimate use of
module functions. E.g. TimGet()
reads the stored time
from file. This is not the full JD, but JD−2450000.