get_timeseries.py 1.58 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
# 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.

"""Example:

    python timeseries.py -f ALMA -F totalPower -s 2016-01-20T10:13:32.000Z
"""

import vlbi
import numpy as np
import datetime
import matplotlib.pyplot as plt

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--facility")
parser.add_argument("-F", "--field")
parser.add_argument("-s", "--start-time")
parser.add_argument("-e", "--end-time")
parser.add_argument("-U", "--admin-username", default="admin", help="Username of server admin")
parser.add_argument("-P", "--admin-password", default="admin", help="Password of server admin")
parser.add_argument("--server", help="Server address", default="http://localhost:8000/rpc")

args = parser.parse_args()

client = vlbi.Client(args.server, "RU", args.admin_username, args.admin_password)

start_time = None
if args.start_time:
    start_time = datetime.datetime.strptime(args.start_time, "%Y-%m-%dT%H:%M:%S.%fZ")

end_time = None
if args.end_time:
    end_time = datetime.datetime.strptime(args.end_time, "%Y-%m-%dT%H:%M:%S.%fZ")

ts = client.getSingleFieldTimeseries(args.facility, args.field, start_time, end_time)

N = len(ts)

x = np.zeros((N, 2))
for i in range(len(ts)):
    d = datetime.datetime.strptime(ts[i]["time"], "%Y-%m-%dT%H:%M:%S.%fZ")

    x[i, 0] = int(d.strftime("%s"))
    x[i, 1] = ts[i]["value"]

plt.plot(x[:, 0], x[:, 1])
plt.xlabel("Time [s]")
plt.ylabel(args.field)
plt.show()