Two functions are provided for measuring the time intervals elapsed between pairs of Julian Day numbers. These are useful when an experiment is started at some time , and datapoints are to be labelled with the times elapsed since the beginning of the experiment. The time_diff() function returns the time interval, with physical dimensions of time, between two Julian Day numbers. This function is actually very simple, and is entirely equivalent to the algebraic expression (y-x)*unit(day). The following example, demonstrates its use to calculate the time elapsed between the traditional date for the foundation of Rome by Romulus and Remus in 753 BC and that of the deposition of the last Emperor of the Western Empire in AD 476:
pyxplot> x = time_julianday(-752,4,21,12,0,0)
pyxplot> y = time_julianday( 476,9, 4,12,0,0)
pyxplot> print time_diff(x,y)
3.8764483e+10 s
pyxplot> print time_diff(x,y)/unit(year)
1228.3723
The function time_diff_string() is similar, but returns a textual representation of the time interval, and is useful for producing textual axis labels representing the time elapsed since the beginning of an experiment. As with the time_string() function, it takes an optional third parameter which specifies the textual format in which the time interval should be represented. If no format is supplied, then the following verbose format is used:
"%Y years %d days %h hours %m minutes and %s seconds"
Table 4.4 lists the tokens which are substituted for various parts of the time interval. The following examples demonstrate the use of the function:
Token |
Substitution value |
%% |
A literal % sign. |
%d |
The number of days elapsed, modulo 365. |
%D |
The number of days elapsed. |
%h |
The number of hours elapsed, modulo 24. |
%H |
The number of hours elapsed. |
%m |
The number of minutes elapsed, modulo 60. |
%M |
The number of minutes elapsed. |
%s |
The number of seconds elapsed, modulo 60. |
%S |
The number of seconds elapsed. |
%Y |
The number of years elapsed. |
pyxplot> x = time_julianday(-752,4,21,12,0,0)
pyxplot> y = time_julianday( 476,9, 4,12,0,0)
pyxplot> print time_diff_string(x,y)
1229 years 78 days 0 hours 0 minutes and 0 seconds
pyxplot> print time_diff_string(x,y,"$%Ymathrm{y}%d
mathrm{d}$")
A plot of the rate of downloads from an Apache webserver.
In this example, we use PyXPlot’s facilities for handling dates and times to produce a plot of the rate of downloads from an Apache webserver based upon the download log which it stores in the file /var/log/apache2/access.log. This file contain a line of the following form for each page or file requested from the webserver: |
set output ’apache.dat’ |
Having stored our histogram in the file apache.dat, we now plot the resulting histogram, labelling the horizontal axis with the days of the week. The commands used to achieve this will be introduced in Chapter 1. Note that the major axis ticks along the horizontal axis are placed not at integer Julian Days, which fall at midday on each day, but at — |
set xlabel ’Day’ |
The plot below shows the graph which results on a moderately busy webserver which hosts, among many other sites, the PyXPlot website: |
![]() |