simulated_client.py 5.12 KB
Newer Older
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# An example client for the Radboud Radio Lab VLBI Monitor
# 
# Copyright (c) 2016 Pim Schellart
# 
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.

import random
import time
import datetime
import sys
import vlbi

if len(sys.argv) < 2:
    print "Usage: simulated_client.py observatory"
    sys.exit(1)

username = "admin"
password = "admin"
facility = sys.argv[1]

client = vlbi.Client("http://localhost:8000/rpc", facility, username, password)

observatory_coordinates = {"ALMA":     "-23.02900-067.75500",
                           "APEX":     "-23.00578-067.75917",
                           "LMT":      "+18.98583-097.31472",
                           "SMTO":     "+32.70161-109.89124",
                           "SMA":      "+19.82428-155.47797",
                           "IRAM_PdB": "+44.63389+005.90792",
                           "IRAM_PV":  "+37.06616-003.39272",
                           "SPT":      "-89.98000-024.80000",
                           "CARMA":    "+37.28040-118.14166"}

i = 0
while True:
    now = datetime.datetime.utcnow()
    plus = now + datetime.timedelta(seconds=10)
    snow = now.isoformat('T') + 'Z'
    splus = plus.isoformat('T') + 'Z'
        
    metadata = {}
    metadata["observatoryCoordinates"] = {"time": snow, "value": observatory_coordinates[sys.argv[1]]}
    metadata["systemTemperature"] = {"time": snow, "value": random.random()}
    metadata["oscillatorFrequencyOffset"] = {"time": snow, "value": random.random()}
    metadata["observingMode"] = {"time": snow, "value": "VLBI"}
#    metadata["currentPointing"] = {"time": snow, "value": random.random()}
    metadata["currentlySelectedSource"] = {"time": snow, "value": "Sgr A*"}
    metadata["oscillatorFrequencyOffset"] = {"time": snow, "value": random.random()}
    metadata["systemTemperature"] = {"time": snow, "value": random.random()}
    metadata["totalPower"] = {"time": snow, "value": random.random()}

    metadata["maser"] = {"time": snow, "value": random.choice((True, False))}
    metadata["maser.clockOffset"] = {"time": snow, "value": random.random()}
    metadata["maser.vacPumpCurrent"] = {"time": snow, "value": random.random()}
    metadata["maser.clockOffset"] = {"time": snow, "value": random.random()}
    metadata["maser.vacPumpCurrent"] = {"time": snow, "value": random.random()}
    metadata["maser.onAcPower"] = {"time": snow, "value": random.choice((True, False))}
    metadata["maser.lock"] = {"time": snow, "value": random.choice((True, False))}
    metadata["maser.chamberTemperature"] = {"time": snow, "value": random.random()}

    metadata["polarization"] = {"time": snow, "value": "L/R"}
    metadata["polarization.qwpInserted"] = {"time": snow, "value": random.choice((True, False))}

    metadata["phasing"] = {"time": snow, "value": random.choice((True, False))}
    metadata["phasing.status"] = {"time": snow, "value": random.choice((True, False))}
    metadata["phasing.efficiency"] = {"time": snow, "value": random.random()}
    metadata["phasing.referenceAntenna"] = {"time": snow, "value": int(100*random.random())}

    metadata["r2dbe"] = {"time": snow, "value": random.choice((True, False))}
    metadata["r2dbe.status"] = {"time": snow, "value": random.choice((True, False))}
    metadata["r2dbe.states"] = {"time": snow, "value": "unknown"}

    metadata["mark6"] = {"time": snow, "value": random.choice((True, False))}
    metadata["mark6.status"] = {"time": snow, "value": random.choice((True, False))}
    metadata["mark6.moduleNames"] = {"time": snow, "value": "unknown"}
    metadata["mark6.nofDisks"] = {"time": snow, "value": int(36*random.random())}
    metadata["mark6.moduleFreeSpace"] = {"time": snow, "value": random.random()}
    metadata["mark6.scheduleName"] = {"time": snow, "value": "default"}

    metadata["weather"] = {"time": snow, "value": random.choice((True, False))}
    metadata["weather.windSpeed"] = {"time": snow, "value": random.random()}
    metadata["weather.relativeHumidity"] = {"time": snow, "value": random.random()}
    metadata["weather.airPressure"] = {"time": snow, "value": random.random()}
    metadata["weather.vaneCalTemp"] = {"time": snow, "value": random.random()}
    metadata["weather.atmosphericOpacity"] = {"time": snow, "value": random.random()}
    metadata["weather.atmosphericPhaseRMS"] = {"time": snow, "value": random.random()}
    metadata["weather.outsideAmbientTemperature"] = {"time": snow, "value": random.random()}

    if facility in ["ALMA", "CARMA"]:
        metadata["phasing.efficiency"] = {"time": snow, "value": random.random()}

    if i % 10 == 0:
        metadata["recordingStatus"] = {"time": snow, "value": random.choice((True, False))}
        metadata["slewStatus"] = {"time": snow, "value": random.choice((True, False))}
        if facility in ["ALMA", "CARMA"]:
            metadata["phasing.status"] = {"time": snow, "value": random.choice((True, False))}

    if i % 60 == 0:
        metadata["centerFrequency"] = {"time": snow, "expires": splus, "value": random.random()}
    
    record = {"observatory" : sys.argv[1], "time" : snow, "metadata" : metadata}
    
    client.updateRecord(record)

    i += 1
    time.sleep(1)