Clock display with Python and Tkinter

clock_display_2015-04-24

A simple clock display with local time, UTC, date (iso8601 format of course!), MJD, day-of-year, and week number. Useful as a permanent info-display in the lab - just make sure your machines are synced with NTP.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# use Tkinter to show a digital clock
# tested with Python24    vegaseat    10sep2006
# https://www.daniweb.com/software-development/python/code/216785/tkinter-digital-clock-python
# http://en.sharejs.com/python/19617
 
# AW2015-04-24
# added: UTC, localtime, date, MJD, DOY, week 
from Tkinter import *
import time
import jdutil # https://gist.github.com/jiffyclub/1294443
 
root = Tk()
root.attributes("-fullscreen", True) 
# this should make Esc exit fullscrreen, but doesn't seem to work..
#root.bind('<Escape>',root.attributes("-fullscreen", False))
root.configure(background='black')
 
#root.geometry("1280x1024") # set explicitly window size
time1 = ''
clock_lt = Label(root, font=('arial', 230, 'bold'), fg='red',bg='black')
clock_lt.pack()
 
date_iso = Label(root, font=('arial', 75, 'bold'), fg='red',bg='black')
date_iso.pack()
 
date_etc = Label(root, font=('arial', 40, 'bold'), fg='red',bg='black')
date_etc.pack()
 
clock_utc = Label(root, font=('arial', 230, 'bold'),fg='red', bg='black')
clock_utc.pack()
 
def tick():
    global time1
    time2 = time.strftime('%H:%M:%S') # local
    time_utc = time.strftime('%H:%M:%S', time.gmtime()) # utc
    # MJD
    date_iso_txt = time.strftime('%Y-%m-%d') + "    %.5f" % jdutil.mjd_now()
    # day, DOY, week
    date_etc_txt = "%s   DOY: %s  Week: %s" % (time.strftime('%A'), time.strftime('%j'), time.strftime('%W'))
 
    if time2 != time1: # if time string has changed, update it
        time1 = time2
        clock_lt.config(text=time2)
        clock_utc.config(text=time_utc)
        date_iso.config(text=date_iso_txt)
        date_etc.config(text=date_etc_txt)
    # calls itself every 200 milliseconds
    # to update the time display as needed
    # could use >200 ms, but display gets jerky
    clock_lt.after(20, tick)
 
tick()
root.mainloop()

This uses two small additions to jdutil:

1
2
3
4
5
6
7
def mjd_now():
    t = dt.datetime.utcnow()
    return dt_to_mjd(t)
 
def dt_to_mjd(dt):
    jd = datetime_to_jd(dt)
    return jd_to_mjd(jd)

Itärastit Roihuvuori

2015-04-18_ITR_roihuvuori_qr_splitsEasy course with lots of running along paths. From #3 I ran towards #15 for a bit before realizing the correct direction towards #4 - worst split. #9 is the best split - no orienteering required, just running. #11 is again slow and would have been faster along the road/path instead of over the hill via #13.

Espoorastit Kauklahti

First 'real' orienteering event for this season - yay!

Good speed at the start with a 7th place overall at control #3. Then the wheel start to rattle at #4-#5-#6 and completely fall off for the last third of the course. No major mistakes - just the engine overheating after overcooking the start... :)

2015-04-15_er_kauklahti_qr_splits

Söderkulla 83 km

Around +10 to +12 C with a bit of sun today. First ride with the road-bike. The bike-path east of Helsinki extends to about Söderkulla (35 km) where I turned around.

2015-04-11_soderkulla_83k

Espoo 50k

espoo_50k_loop_2015-04-06

The roads are mostly washed and free of gravel/sand...until about ring-II (13km). There's a new XXL store at around 16km. Some indecision around Espoo center 22-24km with the bike-path not very clearly marked. A quick stop for a drink & snickers just before 40 km, then into Helsinki central park which is now free of snow. Punctured the rear wheel at about 52 km so I had to walk about 2 km home.

Solvalla kiintorastit, 5km

Still snow on the ground for maybe 30% of the route. Quite wet and soft.

Mostly ok but just inside the #32 control circle we somehow lost faith and did a loop in the wrong direction.

2015-04-05_solvalla_5km_qr

55k ringroad ride

Around +2..+3 C with a cold shower towards the end.

55k_ringroad_2015-04-03

Keysight 53230A noise floor test

We got a new 53230A counter to the lab, so I decided to run some basic tests on it.

I collected time interval data using a 1-PPS source (H-maser through a SRS DG645), and wired this with a T-connector from CH1 to CH2 with a ~1 m (10 ns delay) cable. This should show the noise floor for time interval measurements as well as CH1/CH2 timing skew when measured the other way around (i.e. from CH2 to CH1). The 10 MHz external reference (at the back) was connected to a H-maser.

53230A_PPS_skew
The results show standard deviations of 12 ps (CH1->CH2) and 11 ps (CH2->CH1) respecively, with a channel skew of 112 ps. Compare to the single-shot spec of sqrt(2)*20 ps = 28 ps and Agilent/Keysight's marketing video on youtube.

I also collected 10 MHz frequency counter readings on CH1 (source: H-maser) with gate times of 0.1 s, 1.0 s, and 10.0 s. I collected the data with a simple program that just calls the "READ?" function repeatedly, which does result in some dead-time between measurements.

Here are the results in terms of Allan deviation. I used allantools.

Keysight_53230A_noise_floor

The time interval noise floor looks like white phase noise with an Allan deviation of 1.8e-11/tau. This is consistent with the 12 ps RMS value found above. It is left as an exercise for the reader to show that ADEV(1s) = sqrt(3)*RMS-time-interval-noise (correct??).

The frequency counting noise floor depends on the gate time, and I get 5e-12/sqrt(tau), 2e-12/sqrt(tau), and 6e-13/sqrt(tau) for gate times of 0.1 s, 1.0 s, and 10.0 s, respectively. This looks like white frequency noise. Enrico Rubiola has notes on frequency counters that may explain the numbers.

Korttelirastit Tapiola

Last Sunday of the winter-orienteering series. 3km sprint-course + 3km ordinary course. OK steady pace, 58:16.

Solar Eclipse behind clouds

eclipse_2015-03-20T121038A bad phone-camera picture  of today's partial solar eclipse which was hidden behind clouds. Taken through the eyepiece of an 80mm/f=600mm ED telescope.

See also eclipse pictures from 2008 when the weather was sunny.

© 2015 anderswallin.net

Theme by Anders NorenUp ↑